@Override public boolean test(TerminalString candidate) { return candidate.toString().endsWith("*"); } });
@Override public boolean test(TerminalString candidate) { return candidate.toString().endsWith("*"); } });
public static final String formatErrorMessage(String message) { return new TerminalString(message, ERROR_COLOR, BOLD_STYLE).toString(); }
public static TerminalString formatRequired(TerminalString name) { return new TerminalString(name.toString(), REQUIRED_COLOR, BOLD_STYLE); }
public static final String formatSuccessMessage(String message) { return new TerminalString(message, SUCCESS_COLOR).toString(); }
public static final String formatWarnMessage(String message) { return new TerminalString(message, WARN_COLOR, BOLD_STYLE).toString(); }
public static final String formatErrorMessage(String message) { return new TerminalString(message, ERROR_COLOR, BOLD_STYLE).toString(); }
public static String formatWorkflowPrompt(String prompt) { return new TerminalString(prompt, WORKFLOW_COLOR).toString(); }
public static final String formatSuccessMessage(String message) { return new TerminalString(message, SUCCESS_COLOR).toString(); }
public static final String formatWarnMessage(String message) { return new TerminalString(message, WARN_COLOR, BOLD_STYLE).toString(); }
public static TerminalString formatRequired(TerminalString name) { return new TerminalString(name.toString(), REQUIRED_COLOR, BOLD_STYLE); }
public static String formatWorkflowPrompt(String prompt) { return new TerminalString(prompt, WORKFLOW_COLOR).toString(); }
public static void formatPrompt(StringBuilder buffer) { if (buffer.toString().contains("@")) { int at = buffer.indexOf("@"); int space = buffer.lastIndexOf(" "); String preAt = buffer.substring(1, at); String postAt = buffer.substring(at + 1, space + 1); buffer.delete(1, space + 1); buffer.append( new TerminalString(preAt, PROMPT_COLOR).toString()); buffer.append("@"); buffer.append( new TerminalString(postAt, PROMPT_COLOR).toString()); } else if (buffer.toString().contains("disconnected")) { String prompt = buffer.substring(1); buffer.replace(1, buffer.lastIndexOf(" ") + 1, new TerminalString(prompt, ERROR_COLOR).toString()); } else { String prompt = buffer.substring(1); buffer.replace(1, buffer.lastIndexOf(" ") + 1, new TerminalString(prompt, PROMPT_COLOR).toString()); } }
public static void formatPrompt(StringBuilder buffer) { if (buffer.toString().contains("@")) { int at = buffer.indexOf("@"); int space = buffer.lastIndexOf(" "); String preAt = buffer.substring(1, at); String postAt = buffer.substring(at + 1, space + 1); buffer.delete(1, space + 1); buffer.append( new TerminalString(preAt, PROMPT_COLOR).toString()); buffer.append("@"); buffer.append( new TerminalString(postAt, PROMPT_COLOR).toString()); } else if (buffer.toString().contains("disconnected")) { String prompt = buffer.substring(1); buffer.replace(1, buffer.lastIndexOf(" ") + 1, new TerminalString(prompt, ERROR_COLOR).toString()); } else { String prompt = buffer.substring(1); buffer.replace(1, buffer.lastIndexOf(" ") + 1, new TerminalString(prompt, PROMPT_COLOR).toString()); } }
public Prompt(TerminalString terminalString) { if(terminalString != null) { ansiString = Parser.toCodePoints(terminalString.toString()); this.prompt = Parser.toCodePoints(terminalString.getCharacters()); } else this.prompt = new int[]{}; }
@Override public void complete(AeshCompleteOperation co) { LOG.debugf("Completing {0}", co.getBuffer()); cliCompleter.complete(ctx, co, this); if (ctx.isColorOutput()) { List<TerminalString> completionCandidates = co.getCompletionCandidates(); List<TerminalString> requiredCandidates = new ArrayList<>(); for (TerminalString candidate : completionCandidates) { if (candidate.toString().endsWith("*") && !"*".equals(candidate.toString())) { TerminalString newCandidate = Util.formatRequired(candidate); requiredCandidates.add(newCandidate); } } completionCandidates.removeIf(new Predicate<TerminalString>() { @Override public boolean test(TerminalString candidate) { return candidate.toString().endsWith("*"); } }); completionCandidates.addAll(requiredCandidates); } LOG.debugf("Completion candidates {0}", co.getCompletionCandidates()); }
@Override public void complete(AeshCompleteOperation co) { LOG.debugf("Completing {0}", co.getBuffer()); cliCompleter.complete(ctx, co, this); if (ctx.isColorOutput()) { List<TerminalString> completionCandidates = co.getCompletionCandidates(); List<TerminalString> requiredCandidates = new ArrayList<>(); for (TerminalString candidate : completionCandidates) { if (candidate.toString().endsWith("*") && !"*".equals(candidate.toString())) { TerminalString newCandidate = Util.formatRequired(candidate); requiredCandidates.add(newCandidate); } } completionCandidates.removeIf(new Predicate<TerminalString>() { @Override public boolean test(TerminalString candidate) { return candidate.toString().endsWith("*"); } }); completionCandidates.addAll(requiredCandidates); } LOG.debugf("Completion candidates {0}", co.getCompletionCandidates()); }
/** * Display the completion string in the terminal. * If !completion.startsWith(buffer.getLine()) the completion will be added to the line, * else it will replace whats at the buffer line. * * @param completion partial completion * @param appendSpace if its an actual complete */ private void displayCompletion(TerminalString completion, Buffer buffer, InputProcessor inputProcessor, boolean appendSpace, char separator) { if(completion.getCharacters().startsWith(buffer.asString())) { ActionMapper.mapToAction("backward-kill-word").accept(inputProcessor); inputProcessor.buffer().writeString(completion.toString()); } else { inputProcessor.buffer().writeString(completion.toString()); } if(appendSpace) { inputProcessor.buffer().writeChar(separator); } }
registry.completeCommandName(co, parsedLine); assertEquals(1, co.getCompletionCandidates().size()); assertEquals("foo", co.getCompletionCandidates().get(0).toString()); registry.completeCommandName(co, parsedLine); assertEquals(1, co.getCompletionCandidates().size()); assertEquals("foo", co.getCompletionCandidates().get(0).toString());
@Test public void testDynamic() throws Exception { TestConnection connection = new TestConnection(); CommandRegistry registry = new AeshCommandRegistryBuilder() .command(createGroupCommand().create()) .create(); Settings settings = SettingsBuilder.builder() .connection(connection) .commandRegistry(registry) .logging(true) .build(); ReadlineConsole console = new ReadlineConsole(settings); AeshCompleteOperation co = new AeshCompleteOperation(new DefaultAeshContext(), "gr", 2); ParsedLine parsedLine = new LineParser() .input(co.getBuffer()) .cursor(co.getCursor()) .parseBrackets(true) .parse(); registry.completeCommandName(co, parsedLine); assertEquals("group", co.getCompletionCandidates().get(0).toString()); console.start(); connection.read("group child1 --foo BAR"+Config.getLineSeparator()); Thread.sleep(10); console.stop(); }