Reader(Thread thread, boolean echo) { this.thread = thread; this.editor = new Editor(console, echo); this.line = new ArrayBlockingQueue<String>(1); } }
public void addModeListener(Runnable runnable) { editor.addModeListener(runnable); }
} else if (current instanceof Editor) { Editor editor = (Editor)current; EditorAction action = editor.getMode().on(key); if (action != null) { String line = editor.append(action, key.sequence); if (line != null) { ShellProcess process = shell.createProcess(line); ProcessHandler.Reader reader = processHandler.editor.get(); if (reader != null) { EditorAction action = editor.getMode().on(key); if (action != null) { String s = reader.editor.append(action, key.sequence); if (s != null) { reader.line.add(s);
@Override void perform(Editor editor, EditorBuffer buffer) throws IOException { if (buffer.getCursor() < editor.getCursorBound()) { buffer.moveRight(); } } };
public void setMode(Mode mode) { editor.setMode(mode); }
@Override String execute(Editor editor, EditorBuffer buffer, int[] sequence, boolean flush) throws IOException { if (editor.isEmpty()) { editor.console.status = Console.CLOSING; return null; } else { if (editor.console.getMode() == Mode.EMACS) { return EditorAction.DELETE_PREV_CHAR.execute(editor, buffer, sequence, true); } else { return EditorAction.ENTER.execute(editor, buffer, sequence, true); } } } };
public Mode getMode() { return editor.getMode(); }
/** * Switch to edit. */ Editor edit() { String prompt = shell.getPrompt(); if (prompt != null && prompt.length() > 0) { try { driver.write(prompt); driver.flush(); } catch (IOException e) { // Swallow for now... } } editor.reset(); handler.set(editor); return editor; }
@Override String execute(Editor editor, EditorBuffer buffer, int[] sequence, boolean flush) throws IOException { editor.historyCursor = -1; editor.historyBuffer = null; String line = buffer.getLine(); editor.lineParser.append(line); if (editor.console.getMode() == Mode.VI_MOVE) { editor.console.setMode(Mode.VI_INSERT); } if (editor.lineParser.crlf()) { editor.console.driver.writeCRLF(); editor.console.driver.flush(); String request = editor.visitor.getRaw(); if (request.length() > 0) { editor.addToHistory(request); } return request; } else { buffer.append('\n'); editor.console.driver.write("> "); if (flush) { buffer.flush(); } return null; } } };
@Override void perform(Editor editor, EditorBuffer buffer) throws IOException { int cursor = editor.getCursorBound() - buffer.getCursor(); if (cursor > 0) { buffer.moveRightBy(cursor); } } };
public void setMode(Mode mode) { editor.setMode(mode); }
@Override String execute(Editor editor, EditorBuffer buffer, int[] sequence, boolean flush) throws IOException { if (editor.isEmpty()) { editor.console.status = Console.CLOSING; return null; } else { if (editor.console.getMode() == Mode.EMACS) { return EditorAction.DELETE_PREV_CHAR.execute(editor, buffer, sequence, true); } else { return EditorAction.ENTER.execute(editor, buffer, sequence, true); } } } };
public Mode getMode() { return editor.getMode(); }
/** * Switch to edit. */ Editor edit() { String prompt = shell.getPrompt(); if (prompt != null && prompt.length() > 0) { try { driver.write(prompt); driver.flush(); } catch (IOException e) { // Swallow for now... } } editor.reset(); handler.set(editor); return editor; }
@Override String execute(Editor editor, EditorBuffer buffer, int[] sequence, boolean flush) throws IOException { editor.historyCursor = -1; editor.historyBuffer = null; String line = buffer.getLine(); editor.lineParser.append(line); if (editor.console.getMode() == Mode.VI_MOVE) { editor.console.setMode(Mode.VI_INSERT); } if (editor.lineParser.crlf()) { editor.console.driver.writeCRLF(); editor.console.driver.flush(); String request = editor.visitor.getRaw(); if (request.length() > 0) { editor.addToHistory(request); } return request; } else { buffer.append('\n'); editor.console.driver.write("> "); if (flush) { buffer.flush(); } return null; } } };
public Console(Shell shell, ConsoleDriver driver) throws NullPointerException { if (shell == null) { throw new NullPointerException("No null shell accepted"); } this.driver = driver; this.shell = shell; this.buffer = new LinkedBlockingDeque<KeyStroke>(1024); this.handler = new AtomicReference<Plugin>(); this.editor = new Editor(this); this.status = RUNNING; }
@Override void perform(Editor editor, EditorBuffer buffer) throws IOException { int count = 0; while (buffer.moveRight()) { count++; } editor.killBuffer.setLength(0); while (count-- > 0) { editor.killBuffer.appendCodePoint(buffer.del()); } editor.killBuffer.reverse(); if (buffer.getCursor() > editor.getCursorBound()) { buffer.moveLeft(); } } };
} else if (current instanceof Editor) { Editor editor = (Editor)current; EditorAction action = editor.getMode().on(key); if (action != null) { String line = editor.append(action, key.sequence); if (line != null) { ShellProcess process = shell.createProcess(line); ProcessHandler.Reader reader = processHandler.editor.get(); if (reader != null) { EditorAction action = editor.getMode().on(key); if (action != null) { String s = reader.editor.append(action, key.sequence); if (s != null) { reader.line.add(s);