Java Code Examples for org.aesh.terminal.utils.Config

The following examples show how to use org.aesh.terminal.utils.Config. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: aesh-readline   Source File: AliasManager.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public String printAllAliases() {
    StringBuilder sb = new StringBuilder();
    /*
    Collections.sort(aliases); // not very efficient, but it'll do for now...
    for(Alias a : aliases)
        sb.append(ALIAS_SPACE).append(a.toString()).append(Config.getLineSeparator());

    return sb.toString();
    */
    aliases.stream()
            .sorted()
            .forEach(a -> sb
                    .append(ALIAS_SPACE)
                    .append(a.toString())
                    .append(Config.getLineSeparator()));

    return sb.toString();
}
 
Example 2
Source Project: aesh-readline   Source File: AliasManager.java    License: Apache License 2.0 6 votes vote down vote up
public String removeAlias(String buffer) {
    if(buffer.trim().equals(UNALIAS))
        return unaliasUsage();
    if (unaliasHelpPattern.matcher(buffer).matches())
        return unaliasUsage();

    buffer = buffer.substring(UNALIAS.length()).trim();

    for(String s : buffer.split(" ")) {
        if(s != null) {
            Optional<Alias> a = getAlias(s.trim());
            if(a.isPresent()) {
                aliases.remove(a.get());
            }
            else
                return "unalias: "+s+": not found" +Config.getLineSeparator();
        }
    }
    return null;
}
 
Example 3
Source Project: aesh-readline   Source File: CompletionHandler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Display all possible completions
 *
 * @param completions all completion items
 */
private void displayCompletions(List<TerminalString> completions, Buffer buffer,
                                InputProcessor inputProcessor) {
    completions.sort(new CaseInsensitiveComparator());

    //if the buffer is longer than one line, we need to move the cursor down the number of lines
    //before we continue
    if(inputProcessor.buffer().buffer().length() > inputProcessor.buffer().size().getWidth()) {
        int numRows = inputProcessor.buffer().buffer().length() / inputProcessor.buffer().size().getWidth();
        int cursorRow = inputProcessor.buffer().buffer().cursor() / inputProcessor.buffer().size().getWidth();
        for(; cursorRow < numRows; cursorRow++)
            inputProcessor.buffer().writeOut(new int[] {27, '[', 'B' });
    }
    //finally move to a new line
    inputProcessor.buffer().writeOut(Config.CR);
    //then we print out the completions
    inputProcessor.buffer().writeOut(Parser.formatDisplayListTerminalString(completions,
            inputProcessor.buffer().size().getHeight(), inputProcessor.buffer().size().getWidth()));
    //then on the next line we write the line again
    inputProcessor.buffer().drawLineForceDisplay();
}
 
Example 4
Source Project: aesh-readline   Source File: AeshConsoleBuffer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void clear(boolean includeBuffer) {
    //(windows fix)
    if(!Config.isOSPOSIXCompatible())
        connection.stdoutHandler().accept(Config.CR);
    //first clear console
    connection.stdoutHandler().accept(ANSI.CLEAR_SCREEN);
    int cursorPosition = -1;
    if(buffer.cursor() < buffer.length()) {
        cursorPosition = buffer.cursor();
        buffer.move(connection.stdoutHandler(), buffer.length() - cursorPosition, size().getWidth());
    }
    //move cursor to correct position
    connection.stdoutHandler().accept(new int[] {27, '[', '1', ';', '1', 'H'});
    //then write prompt
    if(!includeBuffer)
        buffer().reset();

    //redraw
    drawLineForceDisplay();

    if(cursorPosition > -1)
        buffer.move(connection.stdoutHandler(), cursorPosition-buffer.length(), size().getWidth());
}
 
Example 5
Source Project: aesh-readline   Source File: Buffer.java    License: Apache License 2.0 6 votes vote down vote up
public void updateMultiLineBuffer() {
    int originalSize = multiLineBuffer.length;
    // Store the size of each line.
    int cmdSize;
    if (lineEndsWithBackslash()) {
        cmdSize = size - 1;
        multiLineBuffer = Arrays.copyOf(multiLineBuffer, originalSize + size-1);
        System.arraycopy(line, 0, multiLineBuffer, originalSize, size-1);
    }
    //here we have an open quote, so we need to feed a new-line into the buffer
    else {
        cmdSize = size + Config.getLineSeparator().length();
        multiLineBuffer = Arrays.copyOf(multiLineBuffer, originalSize + cmdSize);
        System.arraycopy(line, 0, multiLineBuffer, originalSize, size);
        // add new line
        int[] lineSeparator = Parser.toCodePoints(Config.getLineSeparator());
        System.arraycopy(lineSeparator, 0, multiLineBuffer, originalSize+size, lineSeparator.length);
    }
    locator.addLine(cmdSize, prompt.getLength());
    clear();
    prompt = new Prompt("> ");
    cursor = 0;
    size = 0;
}
 
Example 6
Source Project: aesh-readline   Source File: Buffer.java    License: Apache License 2.0 6 votes vote down vote up
private int[] syncCursor(int currentPos, int newPos, int width, boolean edge) {
    IntArrayBuilder builder = new IntArrayBuilder();
    if(newPos < 0)
        newPos = 0;
    if(currentPos / width == newPos / width) {
        if(currentPos > newPos) {
            // Case in which we are suppressing char and command reaches the edge of
            // terminal width. We must on mac offset of + 1.
            int move = Config.isMacOS() && edge ? currentPos-newPos + 1 : currentPos-newPos;
            builder.append(moveNumberOfColumns(move, 'D'));
        } else
            builder.append(moveNumberOfColumns(newPos-currentPos, 'C'));
    }
    //if cursor and end of buffer is on different lines, we need to move the cursor
    else {
        int moveToLine = currentPos / width - newPos / width;
        int moveToColumn = currentPos % width - newPos % width;
        char rowDirection = 'A';
        if(moveToLine < 0) {
            rowDirection = 'B';
            moveToLine = Math.abs(moveToLine);
        }
        builder.append(  moveNumberOfColumnsAndRows(  moveToLine, rowDirection, moveToColumn));
    }
    return builder.toArray();
}
 
Example 7
Source Project: aesh-readline   Source File: DeviceBuilder.java    License: Apache License 2.0 6 votes vote down vote up
public TerminalDevice build() {
    if(name == null)
        name = Config.isOSPOSIXCompatible() ? "ansi" : "windows";
    String data = getCapabilityFromType();
    TerminalDevice device = new TerminalDevice(name);

    if(data != null) {
        Set<Capability> bools = new HashSet<>();
        Map<Capability, Integer> ints = new HashMap<>();
        Map<Capability, String> strings = new HashMap<>();

        InfoCmp.parseInfoCmp(data, bools,ints, strings);
        device.addAllCapabilityBooleans(bools);
        device.addAllCapabilityInts(ints);
        device.addAllCapabilityStrings(strings);
    }

    return device;
}
 
Example 8
Source Project: aesh-readline   Source File: InputrcParser.java    License: Apache License 2.0 6 votes vote down vote up
protected static void parseLine(String line, EditModeBuilder editMode) {
    Matcher variableMatcher = variablePattern.matcher(line);
    if (variableMatcher.matches()) {
        Variable variable = Variable.findVariable(variableMatcher.group(1));
        if(variable != null)
            parseVariables(variable, variableMatcher.group(2), editMode);
    }
    //TODO: currently the inputrc parser is posix only
    else if (Config.isOSPOSIXCompatible()) {
        Matcher keyQuoteMatcher = keyQuoteNamePattern.matcher(line);
        if(keyQuoteMatcher.matches()) {
            editMode.addAction(mapQuoteKeys(keyQuoteMatcher.group(1)), keyQuoteMatcher.group(3));
        }
        else {
            Matcher keyMatcher = keyNamePattern.matcher(line);
            if(keyMatcher.matches()) {
                editMode.addAction(mapKeys(keyMatcher.group(1)), keyMatcher.group(3));
            }
        }
    }
}
 
Example 9
Source Project: aesh-readline   Source File: FileHistory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Write the content of the history buffer to file
 *
 * @throws IOException io
 */
private void writeFile() throws IOException {
    historyFile.delete();
    try (FileWriter fw = new FileWriter(historyFile)) {
        for(int i=0; i < size();i++)
            fw.write(Parser.fromCodePoints(get(i)) + (Config.getLineSeparator()));
    }
    if (historyFilePermission != null) {
        historyFile.setReadable(false, false);
        historyFile.setReadable(historyFilePermission.isReadable(), historyFilePermission.isReadableOwnerOnly());
        historyFile.setWritable(false, false);
        historyFile.setWritable(historyFilePermission.isWritable(), historyFilePermission.isWritableOwnerOnly());
        historyFile.setExecutable(false, false);
        historyFile.setExecutable(historyFilePermission.isExecutable(),
                historyFilePermission.isExecutableOwnerOnly());
    }
}
 
Example 10
Source Project: aesh-readline   Source File: PasteReadlineTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void paste() throws Exception {
    TestConnection connection = new TestConnection();
    connection.read("connect" + Config.getLineSeparator() +
                    "admin" + Config.getLineSeparator() +
                    "admin!");
    connection.assertLine("connect");
    connection.readline(s -> {
        assertEquals("admin", s);
        connection.setPrompt(new Prompt("[password:] ",'\u0000'));
    });
    connection.readline();
    connection.assertBuffer("admin!");
    assertEquals("[password:] ", connection.getOutputBuffer());
    connection.read("234"+ Config.getLineSeparator());
    connection.assertLine("admin!234");
}
 
Example 11
Source Project: aesh-readline   Source File: AliasManagerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testUnalias() {

    manager.parseAlias("alias foo2='bar -s -h'");
    manager.parseAlias("alias foo=bar");
    manager.parseAlias("alias foo3=bar --help");

    manager.removeAlias("unalias foo3");
    assertEquals("unalias: foo3: not found"+Config.getLineSeparator(), manager.removeAlias("unalias foo3"));

    String out = manager.removeAlias("unalias --help");
    assertEquals("unalias: usage: unalias name [name ...]" + Config.getLineSeparator(), out);

    out = manager.removeAlias("unalias        --help");
    assertEquals("unalias: usage: unalias name [name ...]" + Config.getLineSeparator(), out);
}
 
Example 12
Source Project: aesh-readline   Source File: ReadlineTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiLineDelete() {
    TestConnection term = new TestConnection();
    term.read("foo \\");
    term.clearOutputBuffer();
    term.read(Key.ENTER);
    term.assertBuffer("foo ");
    term.assertLine(null);
    assertEquals(Config.getLineSeparator()+"> ", term.getOutputBuffer());
    term.read("bar");
    term.read(Key.BACKSPACE);
    term.read(Key.BACKSPACE);
    term.read(Key.BACKSPACE);
    term.read(Key.BACKSPACE);
    term.read(Key.ENTER);
    term.assertLine("foo ");
}
 
Example 13
Source Project: aesh-readline   Source File: TestTerminalConnection.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSignal() throws IOException, InterruptedException {
    PipedOutputStream outputStream = new PipedOutputStream();
    PipedInputStream pipedInputStream = new PipedInputStream(outputStream);
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    TerminalConnection connection = new TerminalConnection(Charset.defaultCharset(), pipedInputStream, out);
    Attributes attributes = new Attributes();
    attributes.setLocalFlag(Attributes.LocalFlag.ECHOCTL, true);
    connection.setAttributes(attributes);

    Readline readline = new Readline();
    readline.readline(connection, new Prompt(""), s -> {  });

    connection.openNonBlocking();
    outputStream.write(("FOO").getBytes());
    outputStream.flush();
    Thread.sleep(100);
    connection.getTerminal().raise(Signal.INT);
    connection.close();

    Assert.assertEquals("FOO^C"+ Config.getLineSeparator(), new String(out.toByteArray()));
}
 
Example 14
Source Project: aesh-readline   Source File: TestTerminalConnection.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSignalEchoCtlFalse() throws IOException, InterruptedException {
    PipedOutputStream outputStream = new PipedOutputStream();
    PipedInputStream pipedInputStream = new PipedInputStream(outputStream);
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    TerminalConnection connection = new TerminalConnection(Charset.defaultCharset(), pipedInputStream, out);

    Readline readline = new Readline();
    readline.readline(connection, new Prompt(""), s -> {  });

    connection.openNonBlocking();
    outputStream.write(("FOO").getBytes());
    outputStream.flush();
    Thread.sleep(100);
    connection.getTerminal().raise(Signal.INT);
    connection.close();

    Assert.assertEquals(new String(out.toByteArray()), "FOO"+ Config.getLineSeparator());
}
 
Example 15
Source Project: aesh-readline   Source File: KeyTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFindStartKey() {
    int[] input = new int[]{2, 27, 65};
    Key inc = Key.findStartKey(input);
    assertEquals(Key.CTRL_B, inc);
    System.arraycopy(input, inc.getKeyValues().length, input, 0, input.length - inc.getKeyValues().length);
    inc = Key.findStartKey(input);
    assertEquals(Key.ESC, inc);
    System.arraycopy(input, inc.getKeyValues().length, input, 0, input.length - inc.getKeyValues().length);
    inc = Key.findStartKey(input);
    assertEquals(Key.A, inc);

    if (Config.isOSPOSIXCompatible()) {
        input = new int[]{32, 27, 91, 65, 10};
        inc = Key.findStartKey(input);
        assertEquals(Key.SPACE, inc);
        System.arraycopy(input, inc.getKeyValues().length, input, 0, input.length - inc.getKeyValues().length);
        inc = Key.findStartKey(input);
        assertEquals(Key.UP, inc);
        System.arraycopy(input, inc.getKeyValues().length, input, 0, input.length - inc.getKeyValues().length);
        inc = Key.findStartKey(input);
        assertEquals(Key.ENTER, inc);
        System.arraycopy(input, inc.getKeyValues().length, input, 0, input.length - inc.getKeyValues().length);
    }
}
 
Example 16
Source Project: aesh-readline   Source File: KeyTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFindStartKeyPosition() {
    int[] input = new int[]{2, 27, 65};
    Key inc = Key.findStartKey(input, 0);
    assertEquals(Key.CTRL_B, inc);
    inc = Key.findStartKey(input, 1);
    assertEquals(Key.ESC, inc);
    System.arraycopy(input, inc.getKeyValues().length, input, 0, input.length - inc.getKeyValues().length);
    inc = Key.findStartKey(input, 2);
    assertEquals(Key.A, inc);

    if (Config.isOSPOSIXCompatible()) {
        input = new int[]{32, 27, 91, 65, 10};
        inc = Key.findStartKey(input, 0);
        assertEquals(Key.SPACE, inc);
        inc = Key.findStartKey(input, 1);
        assertEquals(Key.UP, inc);
        inc = Key.findStartKey(input, 4);
        assertEquals(Key.ENTER, inc);

        input = new int[]{10};
        inc = Key.findStartKey(input, 0);
        assertEquals(Key.ENTER, inc);

    }
}
 
Example 17
Source Project: aesh-readline   Source File: CompletionReadlineTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMultipleCompletionsSorted() {
    List<Completion> completions = new ArrayList<>();
    completions.add(co -> {
        if(co.getBuffer().trim().equals("")) {
            co.addCompletionCandidate("foo");
            co.addCompletionCandidate("arg");
            co.addCompletionCandidate("Arg");
            co.addCompletionCandidate("boo");
        }
    });

    TestConnection term = new TestConnection(completions);
    term.read(Key.CTRL_I);
    term.assertOutputBuffer(": "+Config.getLineSeparator()+"arg  Arg  boo  foo  "+Config.getLineSeparator()+":");
 }
 
Example 18
Source Project: aesh-readline   Source File: CompletionReadlineTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCompletionEmptyLine() {
    List<Completion> completions = new ArrayList<>();
    completions.add(co -> {
        if(co.getBuffer().trim().equals("")) {
            co.addCompletionCandidate("bar");
            co.addCompletionCandidate("foo");
        }
    });

    TestConnection term = new TestConnection(completions);

    term.read("  ".getBytes());
    term.read(Key.LEFT_2);
    term.read(Key.LEFT_2);
    term.read(Key.CTRL_I);
    term.assertOutputBuffer(":   "+Config.getLineSeparator()+"bar  foo  "+Config.getLineSeparator()+":");
    term.clearOutputBuffer();
    term.read("a");
    term.read(Config.getLineSeparator());
    term.assertLine("a  ");
}
 
Example 19
Source Project: aesh-readline   Source File: CompletionReadlineTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCompletionMidLine() {
    List<Completion> completions = new ArrayList<>();
    completions.add(co -> {
        if(co.getBuffer().startsWith("1 ")) {
            co.addCompletionCandidate("1 foo");
        }
    });

    TestConnection term = new TestConnection(completions);

    term.read("1 bah".getBytes());
    term.read(Key.LEFT_2);
    term.read(Key.LEFT_2);
    term.read(Key.LEFT_2);
    term.read(Key.CTRL_I);
    term.assertBuffer("1 foo bah");
    term.clearOutputBuffer();
    term.read("A");
    term.read(Config.getLineSeparator());
    term.assertLine("1 foo Abah");
}
 
Example 20
Source Project: aesh-readline   Source File: CompletionReadlineTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCompletionsMidLine() {
    List<Completion> completions = new ArrayList<>();
    completions.add(co -> {
        if(co.getBuffer().startsWith("1 ")) {
            co.addCompletionCandidate("bar");
            co.addCompletionCandidate("foo");
        }
    });

    TestConnection term = new TestConnection(completions);

    term.read("1 bah".getBytes());
    term.read(Key.LEFT_2);
    term.read(Key.LEFT_2);
    term.read(Key.LEFT_2);
    term.read(Key.CTRL_I);
    term.assertOutputBuffer(": 1 bah"+Config.getLineSeparator()+"bar  foo  "+Config.getLineSeparator()+": 1 bah");
    term.clearOutputBuffer();
    term.read("A");
    term.read(Config.getLineSeparator());
    term.assertLine("1 Abah");
}
 
Example 21
Source Project: aesh-readline   Source File: KeyMapperTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testQuoteMapKeys() {
    if(Config.isOSPOSIXCompatible()) {
        EditModeBuilder builder = EditModeBuilder.builder();
        InputrcParser.parseLine("\"\\M-a\":   meta", builder);
        assertEquals(builder.create().parse(Key.META_a).name(), new NoAction().name());

        InputrcParser.parseLine("\"\\M-[D\": backward-char", builder);
        assertEquals(builder.create().parse(Key.LEFT).name(), new BackwardChar().name());
        InputrcParser.parseLine("\"\\M-[C\": forward-char", builder);
        assertEquals(builder.create().parse(Key.RIGHT).name(), new ForwardChar().name());
        InputrcParser.parseLine("\"\\M-[A\": previous-history", builder);
        assertEquals(builder.create().parse(Key.UP).name(), new PrevHistory().name());
        InputrcParser.parseLine("\"\\M-[B\": next-history", builder);
        assertEquals(builder.create().parse(Key.DOWN).name(), new NextHistory().name());

        InputrcParser.parseLine("\"\\M-\\C-D\": backward-char", builder);
        assertEquals(builder.create().parse(Key.META_CTRL_D).name(), new BackwardChar().name());
        InputrcParser.parseLine("\"\\C-\\M-d\": backward-char", builder);
        assertEquals(builder.create().parse(Key.META_CTRL_D).name(), new BackwardChar().name());
        InputrcParser.parseLine("\"\\C-a\": end-of-line", builder);
        assertEquals(builder.create().parse(Key.CTRL_A).name(), new EndOfLine().name());

    }
}
 
Example 22
Source Project: aesh-readline   Source File: BufferTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void multiLineQuote() {
    Buffer buffer = new Buffer(new Prompt(": "));
    List<int[]> outConsumer = new ArrayList<>();
    buffer.insert(outConsumer::add, "foo \"bar", 100);
    buffer.setMultiLine(true);
    buffer.updateMultiLineBuffer();
    outConsumer.clear();
    buffer.insert(outConsumer::add, " bar ", 100);
    assertEquals(">  bar ",
            Parser.fromCodePoints(Arrays.copyOfRange(outConsumer.get(0),
                    outConsumer.get(0).length-7, outConsumer.get(0).length )));

    assertEquals("foo \"bar"+Config.getLineSeparator()+" bar ", buffer.asString());

    //buffer.insert(outConsumer::add, "\\", 100);
    buffer.updateMultiLineBuffer();
    outConsumer.clear();
    buffer.insert(outConsumer::add, "gar\"", 100);
    assertEquals("> gar\"",
            Parser.fromCodePoints(Arrays.copyOfRange(outConsumer.get(0),
                    outConsumer.get(0).length-6, outConsumer.get(0).length )));

    assertEquals("foo \"bar"+Config.getLineSeparator()+" bar "+Config.getLineSeparator()+"gar\"", buffer.asString());
}
 
Example 23
Source Project: aesh-readline   Source File: HistoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testHistory() throws Exception {

    TestConnection term = new TestConnection(EditModeBuilder.builder(EditMode.Mode.EMACS).create());
    term.read("1234"+ Config.getLineSeparator());
    term.readline();
    term.read("567"+Config.getLineSeparator());
    term.readline();
    term.read(Key.UP);
    term.read(Key.UP);
    term.read(Key.ENTER);
    term.assertLine("1234");
    term.readline();
    term.read(Key.UP);
    term.read(Key.UP);
    term.read(Key.ENTER);
    term.assertLine("567");
}
 
Example 24
Source Project: aesh-readline   Source File: HistoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testReverseSearch() throws Exception {

    TestConnection term = new TestConnection(EditModeBuilder.builder(EditMode.Mode.EMACS).create());
    term.read("1234"+ Config.getLineSeparator());
    term.readline();
    term.read("567"+Config.getLineSeparator());
    term.readline();
    term.read("589"+Config.getLineSeparator());
    term.readline();
    term.clearOutputBuffer();
    term.read(Key.CTRL_R);
    term.assertBuffer("(reverse-i-search) `': ");
    term.clearOutputBuffer();
    term.read("5");
    term.assertBuffer("(reverse-i-search) `5': 589");
    term.clearLineBuffer();
    term.read(Key.ENTER);
    term.assertLine("589");
}
 
Example 25
Source Project: aesh-readline   Source File: HistoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testForwardSearch() throws Exception {

    TestConnection term = new TestConnection(EditModeBuilder.builder(EditMode.Mode.EMACS).create());
    term.read("1234"+ Config.getLineSeparator());
    term.readline();
    term.read("567"+Config.getLineSeparator());
    term.readline();
    term.read("589"+Config.getLineSeparator());
    term.readline();
    term.clearOutputBuffer();
    term.read(Key.CTRL_S);
    term.assertBuffer("(forward-i-search) `': ");
    term.clearOutputBuffer();
    term.read("5");
    term.assertBuffer("(forward-i-search) `5': 567");
    term.clearLineBuffer();
    term.read(Key.ENTER);
    term.assertLine("567");
}
 
Example 26
Source Project: aesh-readline   Source File: HistoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testReverseSearchEscape() throws Exception {

    TestConnection term = new TestConnection(EditModeBuilder.builder(EditMode.Mode.EMACS).create());
    term.read("1234"+ Config.getLineSeparator());
    term.readline();
    term.read("567"+Config.getLineSeparator());
    term.readline();
    term.read("589"+Config.getLineSeparator());
    term.readline();
    term.clearOutputBuffer();
    term.read(Key.CTRL_R);
    term.assertBuffer("(reverse-i-search) `': ");
    term.clearOutputBuffer();
    term.read("5");
    term.assertBuffer("(reverse-i-search) `5': 589");
    term.clearLineBuffer();
    term.clearOutputBuffer();
    term.read(Key.ESC);
    term.assertBuffer("589");
    term.assertLine(null);
    term.read(Key.ENTER);
    term.assertLine("589");
}
 
Example 27
@Test
public void testOptionResolveParameterValues() throws Exception {
    CliProcessWrapper cli = new CliProcessWrapper()
            .addJavaOption("-Duser.home=" + temporaryUserHome.getRoot().toPath().toString())
            .addJavaOption("-DfooValue=bar")
            .addCliArgument("--controller="
                    + TestSuiteEnvironment.getServerAddress() + ":"
                    + TestSuiteEnvironment.getServerPort())
            .addCliArgument("--connect")
            .addCliArgument("--resolve-parameter-values");
    try {
        cli.executeInteractive();
        cli.clearOutput();
        cli.pushLineAndWaitForResults("echo-dmr /system-property=foo:add(value=${fooValue})");
        String out = cli.getOutput();
        String dmr = out.substring(out.indexOf(Config.getLineSeparator()), out.lastIndexOf("}") + 1);
        ModelNode mn = ModelNode.fromString(dmr);
        assertEquals("bar", mn.get(Util.VALUE).asString());
    } finally {
        cli.destroyProcess();
    }
}
 
Example 28
ReadlineConsole(Settings settings) throws IOException {
    this.settings = settings;
    readlineHistory = new FileHistory(settings.getHistoryFile(),
            settings.getHistorySize(), settings.getPermission(), false);
    if (settings.isDisableHistory()) {
        readlineHistory.disable();
    } else {
        readlineHistory.enable();
    }
    if (isTraceEnabled) {
        LOG.tracef("History is enabled? %s", !settings.isDisableHistory());
    }
    aliasManager = new AliasManager(new File(Config.getHomeDir()
            + Config.getPathSeparator() + ".aesh_aliases"), true);
    AliasPreProcessor aliasPreProcessor = new AliasPreProcessor(aliasManager);
    preProcessors.add(aliasPreProcessor);
    completions.add(new AliasCompletion(aliasManager));
    readline = new Readline();
}
 
Example 29
Source Project: quarkus   Source File: QuarkusBaseCommand.java    License: Apache License 2.0 5 votes vote down vote up
private void startInteractive() {
    //we start the CLI in a new thread since the caller has a TerminalConnection open
    Runnable runnable = () -> {
        AeshConsoleRunner.builder()
                .command(CreateProjectCommand.class)
                .command(AddExtensionsCommand.class)
                .command(ListExtensionsCommand.class)
                .command(DevModeCommand.class)
                .command(CompileProjectCommand.class)
                .prompt("[[email protected]" + Config.getUserDir() + "]$ ")
                .addExitCommand()
                .start();
    };
    new Thread(runnable).start();
}
 
Example 30
Source Project: aesh-readline   Source File: AliasManager.java    License: Apache License 2.0 5 votes vote down vote up
public void persist() {
    if(persistAlias && aliasFile != null) {

        try {
        //just do it easily and remove the current file
            boolean keepGoing = true;
            if(aliasFile.isFile())
                keepGoing = aliasFile.delete();

            if(keepGoing) {
                File parentFile = aliasFile.getParentFile();
                if (parentFile != null) {
                    parentFile.mkdirs();
                }
                keepGoing = aliasFile.createNewFile();
            }

            if(keepGoing) {
                FileWriter fw = new FileWriter(aliasFile);
                Collections.sort(aliases); // not very efficient, but it'll do for now...
                for(Alias a : aliases) {
                    fw.write(ALIAS_SPACE + a.toString() + Config.getLineSeparator());
                }
                fw.flush();
                fw.close();
            }
        }
        catch(IOException e) {
            LOGGER.log(Level.WARNING, "Could not persist to alias file:", e);
        }
    }
}