org.aesh.readline.terminal.Key Java Examples
The following examples show how to use
org.aesh.readline.terminal.Key.
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: ReadlineTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@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 #2
Source File: HistoryTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@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 #3
Source File: EOFTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void testEOF() { final int[] closeCalled = {0}; EnumMap<ReadlineFlag, Integer> flags = new EnumMap<>(ReadlineFlag.class); TestConnection term = new TestConnection(flags); term.setCloseHandler(v -> { closeCalled[0]++; }); term.read("foo".getBytes()); term.read(Key.CTRL_D); term.assertBuffer("foo"); term.read(Key.CTRL_A); term.read(Key.CTRL_D); term.assertBuffer("oo"); term.read(Key.CTRL_D); term.read(Key.CTRL_D); assertEquals(0, closeCalled[0]); term.read(Key.CTRL_D); assertEquals(1, closeCalled[0]); }
Example #4
Source File: HistoryTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@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 #5
Source File: EmacsModeTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void testSimpleMovementAndEdit() { TestConnection term = new TestConnection(); term.setSignalHandler(null); term.read("1234"); term.read(Key.CTRL_D); term.assertBuffer("1234"); term.read(Key.LEFT_2); term.read(Key.CTRL_D); term.read('5'); term.assertBuffer("1235"); term.read(Key.CTRL_A); term.read(Key.CTRL_D); term.assertBuffer("235"); term.read(Key.CTRL_F); term.read(Key.CTRL_F); term.read('6'); term.assertBuffer("2365"); }
Example #6
Source File: EmacsModeTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void testWordMovementAndEdit() throws Exception { TestConnection term = new TestConnection(); term.read("foo bar... Foo-Bar."); term.read(Key.META_b); term.read(Key.META_d); term.assertBuffer("foo bar... Foo-."); term.read(Key.CTRL_E); term.read(Key.LEFT_2); term.read("Bar"); term.assertBuffer("foo bar... Foo-Bar."); term.read(Key.CTRL_A); term.read(Key.META_f); term.read(Key.META_f); term.read(Key.META_d); term.assertBuffer("foo bar-Bar."); term.read(Key.META_b); term.read(Key.CTRL_U); term.assertBuffer("bar-Bar."); }
Example #7
Source File: HistoryTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@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 #8
Source File: EmacsModeTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void testWordMovementWithArrows() { TestConnection term = new TestConnection(); term.read("/subsyste=fo/ba:add(pro=abc)"); term.read(Key.CTRL_LEFT); term.read(Key.LEFT_2); term.read("p"); term.assertBuffer("/subsyste=fo/ba:add(prop=abc)"); term.read(Key.META_b); term.read(Key.META_b); term.read(Key.LEFT_2); term.read("r"); term.assertBuffer("/subsyste=fo/bar:add(prop=abc)"); term.read(Key.HOME); term.read(Key.CTRL_RIGHT); term.read("m"); term.assertBuffer("/subsystem=fo/bar:add(prop=abc)"); term.read(Key.META_f); term.read("o"); term.assertBuffer("/subsystem=foo/bar:add(prop=abc)"); }
Example #9
Source File: EmacsModeTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void testSwitchingEditModes() throws Exception { TestConnection term = new TestConnection(); term.read("foo bar... Foo-Bar."); term.read(Key.CTRL_A); term.read("A "); term.assertBuffer("A foo bar... Foo-Bar."); term.read(Key.CTRL_E); term.read("."); term.assertBuffer("A foo bar... Foo-Bar.."); term.read(Key.META_CTRL_J); term.read(Key.ESC); term.read(Key.ZERO); term.read(Key.i); term.read("A "); term.assertBuffer("A A foo bar... Foo-Bar.."); term.read(Key.ESC); term.read(Key.CTRL_E); term.read(Key.CTRL_E); term.read("."); term.assertBuffer("A A foo bar... Foo-Bar..."); }
Example #10
Source File: KeyMapperTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@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 #11
Source File: ViModeTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void testSearchWithArrownRight() { TestConnection term = new TestConnection(EditModeBuilder.builder(EditMode.Mode.VI).create()); term.read("asdf jkl\n"); term.readline(); term.read("footing\n"); term.readline(); term.read(Key.CTRL_R); term.read(Key.a); term.read(Key.RIGHT_2); term.assertBuffer("asdf jkl"); term.read(Key.a); term.assertBuffer("asdf jkla"); }
Example #12
Source File: ViModeTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void testPasteAndEdit() { TestConnection term = new TestConnection(EditModeBuilder.builder(EditMode.Mode.VI).create()); term.read("apt-get install vIM"); term.read(Key.ESC); term.read(Key.ZERO); term.read(Key.d); term.read(Key.W); term.read(Key.w); term.read(Key.P); term.read(Key.W); term.read(Key.y); term.read(Key.w); term.read(Key.DOLLAR); term.read(Key.p); term.read(Key.ENTER); term.assertLine("install apt-get vIMvIM"); }
Example #13
Source File: ViModeTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void testWordMovementAndEdit2() throws Exception { TestConnection term = new TestConnection(EditModeBuilder.builder(EditMode.Mode.VI).create()); term.read("foo bar... Foo-Bar."); term.read(Key.ESC); term.read(Key.B); term.read(Key.d); term.read(Key.b); term.assertBuffer("foo barFoo-Bar."); term.read(Key.ESC); term.read(Key.ZERO); term.read(Key.W); term.read(Key.d); term.read(Key.w); term.assertBuffer("foo -Bar."); term.read(Key.ENTER); term.assertLine("foo -Bar."); }
Example #14
Source File: CompletionReadlineTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@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 #15
Source File: Vi.java From aesh-readline with Apache License 2.0 | 6 votes |
private ActionStatus getActionStatus(KeyAction event) { if(event instanceof Key) { ActionStatus actionStatus = actions.get(event); if(actionStatus != null) return actionStatus; else { ActionStatusGroup group = actionGroups.get(event); if(group != null) return group.getByCurrentStatus(status); group = keyEventActionGroups.get(event); if(group != null) return group.getByCurrentStatus(status); } return null; } else { return parseKeyEventActions(event); } }
Example #16
Source File: CliShell.java From galleon with Apache License 2.0 | 6 votes |
@Override public Key read() throws InterruptedException { ActionDecoder decoder = new ActionDecoder(); final Key[] key = {null}; Attributes attributes = connection.enterRawMode(); try { connection.setStdinHandler(keys -> { decoder.add(keys); if (decoder.hasNext()) { key[0] = Key.findStartKey(decoder.next().buffer().array()); connection.stopReading(); } }); try { connection.openBlocking(); } finally { connection.setStdinHandler(null); } } finally { connection.setAttributes(attributes); } return key[0]; }
Example #17
Source File: ReadlineTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void testMasking() { Prompt prompt = new Prompt(": ", '#'); TestConnection term = new TestConnection(null, null, null, prompt); term.setSignalHandler(null); term.read("foo bar"); assertEquals(": #######", term.getOutputBuffer()); term.read(Key.BACKSPACE); term.read(Key.CTRL_A); term.read(Key.CTRL_D); term.read(Key.ENTER); term.assertLine("oo ba"); prompt = new Prompt("", '\0'); term.setPrompt(prompt); term.readline(); term.read("foo bar"); assertEquals("", term.getOutputBuffer()); term.read(Key.BACKSPACE); term.read(Key.BACKSPACE); term.read(Key.ENTER); term.assertLine("foo b"); }
Example #18
Source File: ReadlineTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void testSingleCompleteResult() { List<Completion> completions = new ArrayList<>(); completions.add(completeOperation -> { if(completeOperation.getBuffer().equals("f")) completeOperation.addCompletionCandidate("foo"); else if(completeOperation.getBuffer().equals("b")) completeOperation.addCompletionCandidate("bar"); }); TestConnection term = new TestConnection(completions); term.read("fo"); term.read(Key.CTRL_I); term.assertBuffer("fo"); term.read(Key.BACKSPACE); term.read(Key.CTRL_I); term.assertBuffer("foo "); term.read("1"); term.assertBuffer("foo 1"); term.read(Key.ENTER); term.assertLine("foo 1"); }
Example #19
Source File: HistoryTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@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: EditMode.java From aesh-readline with Apache License 2.0 | 6 votes |
default KeyAction createKeyEvent(int[] input) { Key key = Key.getKey(input); if(key != null) return key; else { return new KeyAction() { private int[] key = input; @Override public int getCodePointAt(int index) throws IndexOutOfBoundsException { return key[index]; } @Override public int length() { return key.length; } @Override public String name() { return Arrays.toString(key); } }; } }
Example #21
Source File: MaskingReadlineTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void maskingTest() { TestConnection term = new TestConnection(new Prompt("", '\u0000')); term.read("MMyPassword"); term.assertOutputBuffer(""); term.read(Key.BACKSPACE); term.read(Key.ENTER); term.assertLine("MMyPasswor"); term = new TestConnection(new Prompt(Parser.toCodePoints("[foo] "), '%')); term.read("MMyPassword"); term.assertOutputBuffer("[foo] %%%%%%%%%%%"); term.clearOutputBuffer(); term.read(Key.BACKSPACE); term.read(Key.ENTER); term.assertLine("MMyPasswor"); }
Example #22
Source File: CompletionReadlineTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@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 #23
Source File: CompletionReadlineTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@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 #24
Source File: CompletionReadlineTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@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 #25
Source File: ViModeTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void testWordMovementAndEdit() throws Exception { TestConnection term = new TestConnection(EditModeBuilder.builder(EditMode.Mode.VI).create()); term.read(" .."); term.read(Key.ESC); term.read(Key.b); term.read(Key.x); term.assertBuffer(" ."); term.read(Key.ZERO); term.read(Key.D); term.assertBuffer(""); term.read(Key.i); term.read("foo bar"); term.read(Key.ESC); term.read(Key.ZERO); term.read(Key.w); term.read(Key.x); term.read(Key.ENTER); term.assertLine("foo ar"); }
Example #26
Source File: ViModeTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testSearchWithArrownLeft() { TestConnection term = new TestConnection(EditModeBuilder.builder(EditMode.Mode.VI).create()); term.read("asdf jkl\n"); term.readline(); term.read("footing\n"); term.readline(); term.read(Key.CTRL_R); term.read(Key.a); term.read(Key.LEFT_2); term.assertBuffer("asdf jkl"); }
Example #27
Source File: ReadlineTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testMultipleCompleteResults() { List<Completion> completions = new ArrayList<>(); completions.add(completeOperation -> { if(completeOperation.getBuffer().equals("f")) { completeOperation.addCompletionCandidate("foo"); completeOperation.addCompletionCandidate("foo bar"); } else if(completeOperation.getBuffer().equals("foo")) { completeOperation.addCompletionCandidate("foo"); completeOperation.addCompletionCandidate("foo bar"); } else if(completeOperation.getBuffer().equals("b")) { completeOperation.addCompletionCandidate("bar bar"); completeOperation.addCompletionCandidate("bar baar"); } }); TestConnection term = new TestConnection(completions); term.read("f"); term.read(Key.CTRL_I); term.assertBuffer("foo"); term.clearOutputBuffer(); term.read(Key.CTRL_I); assertEquals(Config.getLineSeparator()+"foo foo bar "+ Config.getLineSeparator()+term.getPrompt()+"foo", term.getOutputBuffer()); term.read(Key.ENTER); term.readline(completions); term.read("b"); term.read(Key.CTRL_I); term.assertBuffer("bar\\ ba"); }
Example #28
Source File: EOFTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testIgnoreEOF() { final int[] closeCalled = {0}; EnumMap<ReadlineFlag, Integer> flags = new EnumMap<>(ReadlineFlag.class); flags.put(ReadlineFlag.IGNORE_EOF, 2); TestConnection term = new TestConnection(flags); term.setCloseHandler(v -> { closeCalled[0]++; }); term.read("foo".getBytes()); term.read(Key.CTRL_D); term.assertBuffer("foo"); term.read(Key.CTRL_A); term.read(Key.CTRL_D); term.assertBuffer("oo"); term.read(Key.CTRL_D); term.read(Key.CTRL_D); assertEquals(0, closeCalled[0]); term.read(Key.CTRL_D); assertEquals(0, closeCalled[0]); term.read(Key.CTRL_D); assertEquals(0, closeCalled[0]); term.read(Key.CTRL_D); assertEquals(1, closeCalled[0]); }
Example #29
Source File: ReadlineTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testCompleteResultsMultipleLines() { List<Completion> completions = new ArrayList<>(); completions.add(completeOperation -> { if(completeOperation.getBuffer().equals("ff")) { completeOperation.addCompletionCandidate("ffoo"); } else if(completeOperation.getBuffer().endsWith("f")) { completeOperation.addCompletionCandidate(completeOperation.getBuffer()+"oo"); } else if(completeOperation.getBuffer().endsWith("foo")) { completeOperation.addCompletionCandidate(completeOperation.getBuffer()+"foo"); completeOperation.addCompletionCandidate(completeOperation.getBuffer()+"foo bar"); } else if(completeOperation.getBuffer().endsWith("b")) { completeOperation.addCompletionCandidate(completeOperation.getBuffer()+"bar bar"); completeOperation.addCompletionCandidate(completeOperation.getBuffer()+"bar baar"); } }); Size termSize = new Size(10, 10); TestConnection term = new TestConnection(EditModeBuilder.builder().create(), completions, termSize); term.read("ff"); term.read(Key.CTRL_I); term.assertBuffer("ffoo "); term.read(Key.ENTER); term.readline(completions); term.read("11111111111f"); term.read(Key.CTRL_I); term.assertBuffer("11111111111foo "); }
Example #30
Source File: HistoryTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testHistoryMultiLine1() throws Exception { TestConnection term = new TestConnection(EditModeBuilder.builder(EditMode.Mode.EMACS).create()); term.read("1234 \\" + Config.getLineSeparator()); term.read("567" + Config.getLineSeparator()); term.readline(); term.read(Key.UP); term.read(Key.ENTER); term.assertLine("1234 567"); }