org.aesh.terminal.utils.Config Java Examples

The following examples show how to use org.aesh.terminal.utils.Config. 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 File: CompletionReadlineTest.java    From aesh-readline with 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 #2
Source File: Buffer.java    From aesh-readline with 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 #3
Source File: AeshConsoleBuffer.java    From aesh-readline with 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 #4
Source File: TestTerminalConnection.java    From aesh-readline with 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 #5
Source File: CliConfigTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 #6
Source File: Buffer.java    From aesh-readline with 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 #7
Source File: CompletionHandler.java    From aesh-readline with 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 #8
Source File: TestTerminalConnection.java    From aesh-readline with 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 #9
Source File: KeyTest.java    From aesh-readline with 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 #10
Source File: ReadlineConsole.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
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 #11
Source File: AliasManager.java    From aesh-readline with 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 #12
Source File: AliasManager.java    From aesh-readline with 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 #13
Source File: DeviceBuilder.java    From aesh-readline with 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 #14
Source File: HistoryTest.java    From aesh-readline with 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 #15
Source File: HistoryTest.java    From aesh-readline with 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 #16
Source File: HistoryTest.java    From aesh-readline with 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 #17
Source File: ReadlineTest.java    From aesh-readline with 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 #18
Source File: InputrcParser.java    From aesh-readline with 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 #19
Source File: HistoryTest.java    From aesh-readline with 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 #20
Source File: BufferTest.java    From aesh-readline with 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 #21
Source File: CompletionReadlineTest.java    From aesh-readline with 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 #22
Source File: FileHistory.java    From aesh-readline with 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 #23
Source File: KeyMapperTest.java    From aesh-readline with 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 #24
Source File: CompletionReadlineTest.java    From aesh-readline with 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 #25
Source File: PasteReadlineTest.java    From aesh-readline with 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 #26
Source File: CompletionReadlineTest.java    From aesh-readline with 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 #27
Source File: AliasManagerTest.java    From aesh-readline with 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 #28
Source File: KeyTest.java    From aesh-readline with 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 #29
Source File: ExecPtyTest.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Test
public void testOptimizedParseAttributesUbuntu() throws IOException {
    if(Config.isOSPOSIXCompatible()) {
        Attributes attributes = ExecPty.doGetLinuxAttr(ubuntuSttySample);
        checkAttributestUbuntu(attributes);
    }
}
 
Example #30
Source File: ExecPtyTest.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Test
public void testParseSizeHPUX() throws IOException {
    if(Config.isOSPOSIXCompatible()) {
        String input = new String(Files.readAllBytes(
                Config.isOSPOSIXCompatible() ?
                        new File("src/test/resources/ttytype_hpux.txt").toPath() :
                        new File("src\\test\\resources\\ttytype_hpux.txt").toPath()));

        Size size = ExecPty.doGetHPUXSize(input);

        assertEquals(47, size.getHeight());
        assertEquals(112, size.getWidth());
    }
}