本文整理汇总了Java中jline.console.CursorBuffer类的典型用法代码示例。如果您正苦于以下问题:Java CursorBuffer类的具体用法?Java CursorBuffer怎么用?Java CursorBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CursorBuffer类属于jline.console包,在下文中一共展示了CursorBuffer类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: complete
import jline.console.CursorBuffer; //导入依赖的package包/类
public boolean complete(ConsoleReader reader, List<CharSequence> candidates, int pos) throws IOException {
CursorBuffer buf = reader.getCursorBuffer();
if(candidates.size() == 1) {
CharSequence value1 = (CharSequence) candidates.get(0);
if(value1.equals(buf.toString())) {
return false;
}
else {
setBuffer(reader, value1, pos);
return true;
}
}
else {
if(candidates.size() > 1) {
String value = this.getUnambiguousCompletions(candidates);
setBuffer(reader, value, pos);
}
printCandidates(reader, candidates);
reader.drawLine();
return true;
}
}
示例2: getCmd
import jline.console.CursorBuffer; //导入依赖的package包/类
/**
* Helper to determine the current command entered and the argument position of the cursor
*
* @param p_buffer
* CursorBuffer of jline
* @param p_tokens
* List to add the tokens of the currently entered command to
* @return Current argument position depending on the CursorBuffer
*/
private static int getCmd(final CursorBuffer p_buffer, final List<String> p_tokens) {
int argPos;
String str = p_buffer.toString();
// separate by space but keep strings, e.g. "this is a test" as a single string and remove the quotes
Matcher matcher = Pattern.compile("([^\"]\\S*|\".+?\")\\s*").matcher(str);
while (matcher.find()) {
p_tokens.add(matcher.group(1).replace("\"", ""));
}
argPos = p_tokens.size() - 2;
if (str.charAt(str.length() - 1) == ' ' || str.charAt(str.length() - 1) == '\t') {
argPos++;
}
return argPos;
}
示例3: actionPerformed
import jline.console.CursorBuffer; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
CursorBuffer buf = textTerminal.reader.getCursorBuffer();
String partialInput = buf.buffer.toString();
buf.clear();
ReadHandlerData handlerData = handler.apply(textTerminal);
ReadInterruptionStrategy.Action action = handlerData.getAction();
if(action == CONTINUE) {
buf.write(partialInput);
} else {
if(action == RESTART) {
textTerminal.initialReadBuffer = partialInput;
}
ReadInterruptionData interruptData = ReadInterruptionData.from(handlerData, partialInput);
throw new ReadInterruptionException(interruptData, partialInput);
}
}
示例4: printLine
import jline.console.CursorBuffer; //导入依赖的package包/类
public static void printLine(ConsoleReader console, String author, String message) {
try {
CursorBuffer stashed = stashLine(console);
console.println(author + " > " + message);
unstashLine(console, stashed);
console.flush();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例5: stashLine
import jline.console.CursorBuffer; //导入依赖的package包/类
public static CursorBuffer stashLine(ConsoleReader console) {
CursorBuffer stashed = console.getCursorBuffer().copy();
try {
console.getOutput().write("\u001b[1G\u001b[K");
console.flush();
} catch (IOException e) {
e.printStackTrace();
}
return stashed;
}
示例6: unstashLine
import jline.console.CursorBuffer; //导入依赖的package包/类
public static void unstashLine(ConsoleReader console, CursorBuffer stashed) {
try {
console.resetPromptLine(console.getPrompt(), stashed.toString(), stashed.cursor);
} catch (IOException e) {
e.printStackTrace();
}
}
示例7: complete
import jline.console.CursorBuffer; //导入依赖的package包/类
public boolean complete(final ConsoleReader reader, final List<CharSequence> candidates, final int pos) throws IOException {
CursorBuffer buffer = reader.getCursorBuffer();
// if there is only one completion, then fill in the buffer, that's all
if (candidates.size() == 1) {
CharSequence candidate = candidates.get(0);
// fail if the only candidate is the same as the current buffer
if (candidate.equals(buffer.toString())) {
return false;
}
updateBuffer(reader, candidate, pos);
return true;
}
//if there are more suggestions, then fill in the buffer with the longer common prefix available
//and show auto-suggestions
if (candidates.size() > 1) {
String commonPrefix = getUnambiguousCompletions(candidates);
updateBuffer(reader, commonPrefix, pos);
}
printCandidates(reader, candidates);
//next line seems to cause small problems when cursor is not at the end of the buffer
//e.g. FilterBuilders.queryFilter(QueryBuilders.)
reader.drawLine();
return true;
}
示例8: printLine
import jline.console.CursorBuffer; //导入依赖的package包/类
public static void printLine(ConsoleReader console, String author, String message) throws IOException {
CursorBuffer stashed = stashLine(console);
console.println(author + " > " + message);
unstashLine(console, stashed);
console.flush();
}
示例9: complete
import jline.console.CursorBuffer; //导入依赖的package包/类
@Override
public int complete(final String p_buffer, final int p_cursor, final List<CharSequence> p_candidates) {
CursorBuffer buffer = m_reader.getCursorBuffer();
List<String> cmdTokens = new ArrayList<String>();
int argPos = getCmd(buffer, cmdTokens);
if (!cmdTokens.isEmpty()) {
TerminalCommandString cmdStr = new TerminalCommandString(buffer.toString());
if (!m_session.write(new TerminalReqCmdArgComp(argPos, cmdStr))) {
return -1;
}
Object obj = m_session.read();
if (obj instanceof TerminalCmdArgCompList) {
List<String> tmp = ((TerminalCmdArgCompList) obj).getCompletions();
if (tmp != null) {
SortedSet<String> list = new TreeSet<String>();
list.addAll(tmp);
if (p_buffer == null) {
p_candidates.addAll(list);
} else {
Iterator var4 = list.tailSet(p_buffer).iterator();
while (var4.hasNext()) {
String match = (String) var4.next();
if (!match.startsWith(p_buffer)) {
break;
}
p_candidates.add(match);
}
}
}
}
}
return p_candidates.isEmpty() ? -1 : 0;
}