org.aesh.readline.action.ActionDecoder Java Examples
The following examples show how to use
org.aesh.readline.action.ActionDecoder.
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: 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 #2
Source File: Readline.java From aesh-readline with Apache License 2.0 | 5 votes |
public Readline(EditMode editMode, History history, CompletionHandler completionHandler) { this.editMode = editMode; this.history = history; if(completionHandler == null) this.completionHandler = new SimpleCompletionHandler(); else this.completionHandler = completionHandler; this.decoder = new ActionDecoder(this.editMode); }
Example #3
Source File: KeyTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testOtherOperations() { EditMode editMode = EditModeBuilder.builder(EditMode.Mode.EMACS).create(); Key up = Key.UP_2; Action action = editMode.parse(up); assertEquals(action.name(), ActionMapper.mapToAction("previous-history").name()); if (Config.isOSPOSIXCompatible()) { int[] doubleUpKey = new int[6]; for (int i = 0; i < 6; i++) { if (i > 2) doubleUpKey[i] = up.getKeyValues()[i - 3]; else doubleUpKey[i] = up.getKeyValues()[i]; } ActionDecoder actionDecoder = new ActionDecoder(editMode); actionDecoder.add(doubleUpKey); action = editMode.parse(actionDecoder.next()); assertEquals(action.name(), ActionMapper.mapToAction("previous-history").name()); } }
Example #4
Source File: InputrcParserTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testParseInputrc2() throws IOException { if(Config.isOSPOSIXCompatible()) { //TODO: must fix this for windows EditMode editMode = EditModeBuilder.builder().create(); ActionDecoder actionQueue = new ActionDecoder(); actionQueue.add(new int[]{27, 91, 68}); Assert.assertEquals("backward-char", editMode.parse( actionQueue.next()).name()); actionQueue.add(new int[]{27, 91, 66}); Assert.assertEquals("next-history", editMode.parse( actionQueue.next()).name()); actionQueue.add(1); Assert.assertEquals("beginning-of-line", editMode.parse( actionQueue.next()).name()); editMode = InputrcParser.parseInputrc( new FileInputStream( Config.isOSPOSIXCompatible() ? new File("src/test/resources/inputrc2") : new File("src\\test\\resources\\inputrc2"))); actionQueue.add(new int[]{27, 91, 68}); Assert.assertEquals("forward-char", editMode.parse( actionQueue.next()).name()); actionQueue.add(new int[]{27, 91, 66}); Assert.assertEquals("previous-history", editMode.parse(actionQueue.next()).name()); actionQueue.add(new int[]{27,10}); Assert.assertEquals("backward-char", editMode.parse(actionQueue.next()).name()); actionQueue.add(1); Assert.assertEquals("forward-word", editMode.parse(actionQueue.next()).name()); } }
Example #5
Source File: ReadlineConsole.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public int[] read() throws InterruptedException, IOException { initializeConnection(); ActionDecoder decoder = new ActionDecoder(); final int[][] key = {null}; // Keep a reference on the caller thread in case Ctrl-C is pressed // and thread needs to be interrupted. readingThread = Thread.currentThread(); // We need to set the interrupt SignalHandler to interrupt the reading. Consumer<Signal> prevHandler = connection.getSignalHandler(); connection.setSignalHandler((signal) -> { // Interrupting the current reading thread. switch (signal) { case INT: { LOG.tracef("Interrupting reading thread."); readingThread.interrupt(); } } }); CountDownLatch latch = new CountDownLatch(1); Attributes attributes = connection.enterRawMode(); connection.setStdinHandler(keys -> { decoder.add(keys); if (decoder.hasNext()) { key[0] = decoder.next().buffer().array(); /* Synchronously put the TerminalConnection thread in wait (side effect of setting a null handler). This does guarantee that when this thread unstack it will put itself in wait mode. That is safe, wait is the state expected once this handler is done. When the latch.await returns, or the current command terminates and a new readline call will position a new stdinhandler or read() is called again and a new stdinhandler will be set. In both cases the terminalConnection will wake up and read on the terminal. If we were not doing this call here but after latch.await we could have this thread to be already reading on the terminal when attempted to be put in wait mode (by the latch.await thread). Theoreticaly the console could read a key although no inputHandler has been already set. This has never been observed. But this can cause an issue on Cygwin (WFCORE-3647), if the connection is reading although Terminal attributes are get/set (by forking a sub process) by the next call to read(), the get/set call is stuck when reading sub process output and is unblocked when a key is typed in the terminal. So one key is swallowed and the key must be typed twice to operate. */ connection.setStdinHandler(null); latch.countDown(); } }); try { // Wait until interrupted latch.await(); } finally { connection.setSignalHandler(prevHandler); connection.setAttributes(attributes); readingThread = null; } return key[0]; }