@Override void perform(Editor editor, EditorBuffer buffer) throws IOException { editor.console.driver.cls(); StringBuilder sb = new StringBuilder(); int index = 0; List<String> lines = buffer.getLines(); for (String line : lines) { if (index == 0) { String prompt = editor.console.shell.getPrompt(); sb.append(prompt == null ? "" : prompt); } else { sb.append("\n> "); } sb.append(line); index++; } editor.console.driver.write(sb.toString()); editor.console.driver.flush(); } };
@Override public int getHeight() { return console.driver.getHeight(); }
@Override public int getWidth() { return console.driver.getWidth(); }
@Override String execute(Editor editor, EditorBuffer buffer, int[] sequence, boolean flush) throws IOException { editor.lineParser.reset(); buffer.reset(); editor.console.driver.writeCRLF(); String prompt = editor.console.shell.getPrompt(); if (prompt != null) { editor.console.driver.write(prompt); } if (flush) { editor.console.driver.flush(); } return null; } };
@Override public Screenable append(CharSequence csq, int start, int end) throws IOException { console.driver.write(csq, start, end); return this; }
void flush(boolean force) throws IOException { if (needFlush || force) { driver.flush(); needFlush = false; } }
/** * Move the cursor right by one char with the provided char. * * @param c the char to overwrite * @return true if it happended * @throws IOException */ boolean moveRight(char c) throws IOException { if (cursor < current.length()) { if (driver.moveRight(c)) { current.setCharAt(cursor++, c); return true; } } return false; }
@Override public Screenable cls() throws IOException { console.driver.cls(); return this; }
@Override public boolean takeAlternateBuffer() throws IOException { return console.driver.takeAlternateBuffer(); }
@Override public boolean releaseAlternateBuffer() throws IOException { return console.driver.releaseAlternateBuffer(); }
private void echoCRLF() throws IOException { driver.writeCRLF(); needFlush = true; }
int moveLeftBy(int count) throws IOException, IllegalArgumentException { if (count < 0) { throw new IllegalArgumentException("Cannot move with negative count " + count); } int delta = 0; while (delta < count) { if (delta < cursor && driver.moveLeft()) { delta++; } else { break; } } if (delta > 0) { needFlush = true; cursor -= delta; } return delta; }