52938
|
1 |
/*
|
|
2 |
* Copyright (c) 2002-2018, the original author or authors.
|
|
3 |
*
|
|
4 |
* This software is distributable under the BSD license. See the terms of the
|
|
5 |
* BSD license in the documentation provided with this software.
|
|
6 |
*
|
|
7 |
* http://www.opensource.org/licenses/bsd-license.php
|
|
8 |
*/
|
|
9 |
package jdk.internal.org.jline.reader;
|
|
10 |
|
|
11 |
import java.util.Objects;
|
|
12 |
|
|
13 |
/**
|
|
14 |
* A completion candidate.
|
|
15 |
*
|
|
16 |
* @author <a href="mailto:gnodet@gmail.com">Guillaume Nodet</a>
|
|
17 |
*/
|
|
18 |
public class Candidate implements Comparable<Candidate> {
|
|
19 |
|
|
20 |
private final String value;
|
|
21 |
private final String displ;
|
|
22 |
private final String group;
|
|
23 |
private final String descr;
|
|
24 |
private final String suffix;
|
|
25 |
private final String key;
|
|
26 |
private final boolean complete;
|
|
27 |
|
|
28 |
/**
|
|
29 |
* Simple constructor with only a single String as an argument.
|
|
30 |
*
|
|
31 |
* @param value the candidate
|
|
32 |
*/
|
|
33 |
public Candidate(String value) {
|
|
34 |
this(value, value, null, null, null, null, true);
|
|
35 |
}
|
|
36 |
|
|
37 |
/**
|
|
38 |
* Constructs a new Candidate.
|
|
39 |
*
|
|
40 |
* @param value the value
|
|
41 |
* @param displ the display string
|
|
42 |
* @param group the group
|
|
43 |
* @param descr the description
|
|
44 |
* @param suffix the suffix
|
|
45 |
* @param key the key
|
|
46 |
* @param complete the complete flag
|
|
47 |
*/
|
|
48 |
public Candidate(String value, String displ, String group, String descr, String suffix, String key, boolean complete) {
|
|
49 |
Objects.requireNonNull(value);
|
|
50 |
this.value = value;
|
|
51 |
this.displ = displ;
|
|
52 |
this.group = group;
|
|
53 |
this.descr = descr;
|
|
54 |
this.suffix = suffix;
|
|
55 |
this.key = key;
|
|
56 |
this.complete = complete;
|
|
57 |
}
|
|
58 |
|
|
59 |
/**
|
|
60 |
* The value that will be used for the actual completion.
|
|
61 |
* This string should not contain ANSI sequences.
|
|
62 |
* @return the value
|
|
63 |
*/
|
|
64 |
public String value() {
|
|
65 |
return value;
|
|
66 |
}
|
|
67 |
|
|
68 |
/**
|
|
69 |
* The string that will be displayed to the user.
|
|
70 |
* This string may contain ANSI sequences.
|
|
71 |
* @return the display string
|
|
72 |
*/
|
|
73 |
public String displ() {
|
|
74 |
return displ;
|
|
75 |
}
|
|
76 |
|
|
77 |
/**
|
|
78 |
* The group name for this candidate.
|
|
79 |
* Candidates can be grouped together and this string is used
|
|
80 |
* as a key for the group and displayed to the user.
|
|
81 |
* @return the group
|
|
82 |
*
|
|
83 |
* @see LineReader.Option#GROUP
|
|
84 |
* @see LineReader.Option#AUTO_GROUP
|
|
85 |
*/
|
|
86 |
public String group() {
|
|
87 |
return group;
|
|
88 |
}
|
|
89 |
|
|
90 |
/**
|
|
91 |
* Description of this candidate, usually a small help message
|
|
92 |
* to understand the meaning of this candidate.
|
|
93 |
* This string may contain ANSI sequences.
|
|
94 |
* @return the description
|
|
95 |
*/
|
|
96 |
public String descr() {
|
|
97 |
return descr;
|
|
98 |
}
|
|
99 |
|
|
100 |
/**
|
|
101 |
* The suffix is added when this candidate is displayed.
|
|
102 |
* However, if the next character entered does not match,
|
|
103 |
* the suffix will be automatically removed.
|
|
104 |
* This string should not contain ANSI sequences.
|
|
105 |
* @return the suffix
|
|
106 |
*
|
|
107 |
* @see LineReader.Option#AUTO_REMOVE_SLASH
|
|
108 |
* @see LineReader#REMOVE_SUFFIX_CHARS
|
|
109 |
*/
|
|
110 |
public String suffix() {
|
|
111 |
return suffix;
|
|
112 |
}
|
|
113 |
|
|
114 |
/**
|
|
115 |
* Candidates which have the same key will be merged together.
|
|
116 |
* For example, if a command has multiple aliases, they can be merged
|
|
117 |
* if they are using the same key.
|
|
118 |
* @return the key
|
|
119 |
*/
|
|
120 |
public String key() {
|
|
121 |
return key;
|
|
122 |
}
|
|
123 |
|
|
124 |
/**
|
|
125 |
* Boolean indicating whether this candidate is complete or
|
|
126 |
* if the completer may further expand the candidate value
|
|
127 |
* after this candidate has been selected.
|
|
128 |
* This can be the case when completing folders for example.
|
|
129 |
* If the candidate is complete and is selected, a space
|
|
130 |
* separator will be added.
|
|
131 |
* @return the completion flag
|
|
132 |
*/
|
|
133 |
public boolean complete() {
|
|
134 |
return complete;
|
|
135 |
}
|
|
136 |
|
|
137 |
@Override
|
|
138 |
public int compareTo(Candidate o) {
|
|
139 |
return value.compareTo(o.value);
|
|
140 |
}
|
|
141 |
}
|