当前位置: 首页>>代码示例>>Java>>正文


Java CursorBuffer类代码示例

本文整理汇总了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;
    }
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:24,代码来源:CandidateCompletionHandler.java

示例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;
}
 
开发者ID:hhu-bsinfo,项目名称:dxram,代码行数:28,代码来源:TerminalCmdArgCompleter.java

示例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);
    }
}
 
开发者ID:beryx,项目名称:text-io,代码行数:19,代码来源:JLineTextTerminal.java

示例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);
    }
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:11,代码来源:ConsoleUtil.java

示例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;
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:11,代码来源:ConsoleUtil.java

示例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();
    }
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:8,代码来源:ConsoleUtil.java

示例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;
}
 
开发者ID:javanna,项目名称:elasticshell,代码行数:30,代码来源:JLineCompletionHandler.java

示例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();
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:7,代码来源:ConsoleUtil.java

示例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;
}
 
开发者ID:hhu-bsinfo,项目名称:dxram,代码行数:42,代码来源:TerminalCmdArgCompleter.java


注:本文中的jline.console.CursorBuffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。