org.aesh.readline.tty.terminal.TerminalConnection Java Examples
The following examples show how to use
org.aesh.readline.tty.terminal.TerminalConnection.
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: TestTerminal.java From aesh-readline with Apache License 2.0 | 6 votes |
public TestTerminal() { try { byteArrayOutputStream = new ByteArrayOutputStream(); terminal = new LineDisciplineTerminal("aesh-test", "term", byteArrayOutputStream); connection = new TerminalConnection(terminal); output = new ArrayList<>(); prompt = new Prompt(": "); readline = new Readline(); } catch (IOException e) { e.printStackTrace(); } }
Example #2
Source File: CliShell.java From galleon with Apache License 2.0 | 5 votes |
CliShell(TerminalConnection connection) throws IOException { this.connection = connection; this.terminal = connection.getTerminal(); if (terminal.getCodePointConsumer() == null) { stdOut = new Encoder(Charset.defaultCharset(), this::write); } else { stdOut = terminal.getCodePointConsumer(); } readline = new Readline(EditModeBuilder.builder().create()); }
Example #3
Source File: TerminalUtil.java From aesh-readline with Apache License 2.0 | 5 votes |
public static Size terminalSize() { TerminalConnection connection = terminal(); if(connection != null) return connection.size(); else return new Size(-1,-1); }
Example #4
Source File: TerminalUtil.java From aesh-readline with Apache License 2.0 | 5 votes |
public static String terminalType() { TerminalConnection connection = terminal(); if(connection != null) return connection.device().type(); else return ""; }
Example #5
Source File: TerminalUtil.java From aesh-readline with Apache License 2.0 | 5 votes |
private static TerminalConnection terminal() { try { return new TerminalConnection(); } catch (IOException e) { return null; } }
Example #6
Source File: SimpleTestExample.java From aesh-readline with Apache License 2.0 | 5 votes |
private static void read(TerminalConnection connection, Readline readline, String prompt) { readline.readline(connection, prompt, input -> { if(input != null && input.equals("exit")) { connection.write("we're exiting\n"); connection.close(); } else { connection.write("=====> "+input+"\n"); //lets read until we get exit read(connection, readline, prompt); } }); }
Example #7
Source File: ReadlineAliasTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void alias() throws Exception { 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(); File aliasFile = Config.isOSPOSIXCompatible() ? new File("src/test/resources/alias1") : new File("src\\test\\resources\\alias1"); AliasManager aliasManager = new AliasManager(aliasFile, false); AliasPreProcessor aliasPreProcessor = new AliasPreProcessor(aliasManager); List<Function<String, Optional<String>>> preProcessors = new ArrayList<>(); preProcessors.add(aliasPreProcessor); readline.readline(connection, new Prompt(""), s -> { //first check this assertEquals("ls -alF", s); //then call readline again, to check the next line readline.readline(connection, new Prompt(""), t -> assertEquals("grep --color=auto -l", t), null, preProcessors); } , null, preProcessors); outputStream.write(("ll"+Config.getLineSeparator()).getBytes()); outputStream.write(("grep -l"+Config.getLineSeparator()).getBytes()); outputStream.flush(); connection.openNonBlocking(); Thread.sleep(200); }
Example #8
Source File: CursorLocatorTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void lineTest() throws IOException { TerminalConnection connection = new TerminalConnection(); Buffer buffer = new Buffer(new Prompt(PROMPT)); String cmd1 = "cmd --opt1 --opt2 "; String cmd2 = "--opt3 --opt4"; String cmd = cmd1 + cmd2; buffer.insert((c) -> { }, cmd1 + "\\", WIDTH); buffer.setMultiLine(true); buffer.updateMultiLineBuffer(); buffer.insert((c) -> { }, cmd2, WIDTH); Line line = new Line(buffer, connection, WIDTH); String s = line.getLineToCursor(); Assert.assertEquals(cmd, s); Assert.assertFalse(line.getCursorLocator() == null); Assert.assertEquals(buffer.multiCursor(), s.length()); line.newCursorTransactionBuilder().move(10).build().run(); Assert.assertEquals(buffer.multiCursor(), s.length()); line.newCursorTransactionBuilder().moveBackward(10).build().run(); Assert.assertEquals(buffer.multiCursor(), s.length()); line.newCursorTransactionBuilder().moveForward(10).build().run(); Assert.assertEquals(buffer.multiCursor(), s.length()); line.newCursorTransactionBuilder().moveDown(10).build().run(); Assert.assertEquals(buffer.multiCursor(), s.length()); line.newCursorTransactionBuilder().moveUp(10).build().run(); Assert.assertEquals(buffer.multiCursor(), s.length()); line.newCursorTransactionBuilder().colorize(10, Color.DEFAULT, Color.DEFAULT, true).build().run(); Assert.assertEquals(buffer.multiCursor(), s.length()); }
Example #9
Source File: CliTerminalConnection.java From galleon with Apache License 2.0 | 4 votes |
public CliTerminalConnection() throws IOException { connection = new TerminalConnection(); out = new PrintStream(new CliOutputStream(), false, StandardCharsets.UTF_8.name()); shell = new CliShell(connection); }
Example #10
Source File: SimpleTestExample.java From aesh-readline with Apache License 2.0 | 4 votes |
public static void main(String... args) throws IOException { TerminalConnection connection = new TerminalConnection(); read(connection, ReadlineBuilder.builder().enableHistory(false).build(), ""); connection.openBlocking(); }