org.aesh.readline.editing.EditModeBuilder Java Examples
The following examples show how to use
org.aesh.readline.editing.EditModeBuilder.
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: ReadlineBuilder.java From aesh-readline with Apache License 2.0 | 6 votes |
public Readline build() { if(editMode == null) editMode = EditModeBuilder.builder().create(); if(!enableHistory) { history = null; } else if(history == null) { if(historyFile == null || !new File(historyFile).isFile()) history = new InMemoryHistory(historySize); else history = new FileHistory(new File(historyFile), historySize); } if(completionHandler == null) completionHandler = new SimpleCompletionHandler(); return new Readline(editMode, history, completionHandler); }
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: 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 #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: 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 #6
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 #7
Source File: ViEditingMode.java From aesh-readline with Apache License 2.0 | 5 votes |
@Override public void accept(InputProcessor inputProcessor) { if(inputProcessor.editMode().mode() != EditMode.Mode.VI) inputProcessor.setEditMode(EditModeBuilder.builder(EditMode.Mode.VI).create()); if(inputProcessor.buffer().buffer().cursor() == inputProcessor.buffer().buffer().length()) inputProcessor.buffer().moveCursor(-1); }
Example #8
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 #9
Source File: HistoryTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testHistoryMultiLine2() 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("1234567"); }
Example #10
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"); }
Example #11
Source File: DeviceTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testEmacsKeyUpdates() { Device device = DeviceBuilder.builder().name("ansi").build(); EditMode emacs = EditModeBuilder.builder() .addVariable(Variable.EDITING_MODE, "emacs") .device(device).create(); //by default only Key.HOME is set to beginning-of-line, but the ansi //device should remap it to Key.HOME_2 assertEquals("beginning-of-line", emacs.parse( Key.HOME_2).name()); }
Example #12
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 #13
Source File: Readline.java From aesh-readline with Apache License 2.0 | 4 votes |
public Readline() { this(EditModeBuilder.builder().create()); }
Example #14
Source File: ConsoleBufferTest.java From aesh-readline with Apache License 2.0 | 4 votes |
private ConsoleBuffer createConsoleBuffer(Connection connection, String prompt) { return new AeshConsoleBuffer(connection, new Prompt(prompt), EditModeBuilder.builder().create(), new InMemoryHistory(50), null, true, null); }
Example #15
Source File: ConsoleBufferTest.java From aesh-readline with Apache License 2.0 | 4 votes |
private ConsoleBuffer createConsoleBuffer(Connection connection) { return new AeshConsoleBuffer(connection, new Prompt("[aesh@rules]: "), EditModeBuilder.builder().create(), new InMemoryHistory(50), null, true, null); }
Example #16
Source File: TestConnection.java From aesh-readline with Apache License 2.0 | 4 votes |
public TestConnection(TestReadline readline, EditMode editMode, List<Completion> completions, Size size, Prompt prompt, Attributes attributes, EnumMap<ReadlineFlag, Integer> flags) { if(editMode == null) editMode = EditModeBuilder.builder().create(); bufferBuilder = new StringBuilder(); stdOutHandler = ints -> bufferBuilder.append(Parser.stripAwayAnsiCodes(Parser.fromCodePoints(ints))); if(size == null) this.size = new Size(80, 20); else this.size = size; if(prompt != null) this.prompt = prompt; if(attributes != null) this.attributes = attributes; if(this.attributes != null) eventDecoder = new EventDecoder(this.attributes); else { eventDecoder = new EventDecoder(); this.attributes = new Attributes(); } device = DeviceBuilder.builder().name("ansi").build(); decoder = new Decoder(512, Charset.defaultCharset(), eventDecoder); out = new LinkedList<>(); if(readline == null) { this.readline = new TestReadline(editMode); if(completions != null) readline(completions); else if(flags != null) readline(flags); else readline(); } else this.readline = readline; }
Example #17
Source File: TestConnection.java From aesh-readline with Apache License 2.0 | 4 votes |
public TestConnection(List<Completion> completions) { this(EditModeBuilder.builder().create(), completions); }
Example #18
Source File: TestConnection.java From aesh-readline with Apache License 2.0 | 4 votes |
public TestConnection(Prompt prompt) { //default emacs mode this(EditModeBuilder.builder().create(), null, prompt); }
Example #19
Source File: TestConnection.java From aesh-readline with Apache License 2.0 | 4 votes |
public TestConnection() { //default emacs mode this(EditModeBuilder.builder().create(), null); }
Example #20
Source File: EmacsEditingMode.java From aesh-readline with Apache License 2.0 | 4 votes |
@Override public void accept(InputProcessor inputProcessor) { if(inputProcessor.editMode().mode() != EditMode.Mode.EMACS) inputProcessor.setEditMode(EditModeBuilder.builder(EditMode.Mode.EMACS).create()); }
Example #21
Source File: ReadlineConsole.java From wildfly-core with GNU Lesser General Public License v2.1 | 2 votes |
/** * This has the side effect to create the internal readline instance. * * @param ch The Completion Handler. */ public void setCompletionHandler(CompletionHandler<? extends CompleteOperation> ch) { readline = new Readline(EditModeBuilder.builder().create(), null, ch); }