@Test public void signalHandlerRespondsToSIGINTByClearingPrompt() throws IOException { // Interactive attention (CTRL-C). JVM exits normally GfshSignalHandler signalHandler = new GfshSignalHandler(); ConsoleReader consoleReader = mock(ConsoleReader.class); when(consoleReader.getPrompt()).thenReturn(PROMPT); signalHandler.handleDefault(SIGINT, consoleReader); verify(consoleReader, times(1)).resetPromptLine(eq(PROMPT), eq(""), eq(END_OF_LINE)); } }
protected void handleDefault(final sun.misc.Signal sig, final ConsoleReader consoleReader) throws IOException { final Signal signal = Signal.valueOfName(sig.getName()); switch (signal) { case SIGINT: if (consoleReader != null) { String prompt = consoleReader.getPrompt(); consoleReader.resetPromptLine(prompt, "", -1); } break; default: final SignalHandler handler = getOriginalSignalHandler(signal); if (handler != null) { handler.handle(sig); } } }
/** * Output put the prompt + the current buffer */ public void drawLine() throws IOException { String prompt = getPrompt(); if (prompt != null) { rawPrint(prompt); } fmtPrint(buf.buffer, 0, buf.cursor, promptLen); // force drawBuffer to check for weird wrap (after clear screen) drawBuffer(); }
/** * Possible states in which the current readline operation may be in. */ private static enum State { /** * The user is just typing away */ NORMAL, /** * In the middle of a emacs seach */ SEARCH, FORWARD_SEARCH, /** * VI "yank-to" operation ("y" during move mode) */ VI_YANK_TO, /** * VI "delete-to" operation ("d" during move mode) */ VI_DELETE_TO, /** * VI "change-to" operation ("c" during move mode) */ VI_CHANGE_TO }
/** * Output put the prompt + the current buffer */ public void drawLine() throws IOException { String prompt = getPrompt(); if (prompt != null) { rawPrint(prompt); } fmtPrint(buf.buffer, 0, buf.cursor, promptLen); // force drawBuffer to check for weird wrap (after clear screen) drawBuffer(); }
private void handleCommandQueue() throws IOException, InterruptedException { boolean handledQueue = false; String queuedCommand; while ((queuedCommand = commandQueue.poll()) != null) { handledQueue = true; reader.resetPromptLine(reader.getPrompt(), queuedCommand, 0); reader.println(); reader.getHistory().add(queuedCommand); try { handlingInput = true; handleInput(queuedCommand); } finally { handlingInput = false; } } if (handledQueue) { String oldPrompt = reader.getPrompt(); reader.resetPromptLine("", "", 0); reader.setPrompt(oldPrompt); } }
String buffer = cursorBuffer.buffer.toString(); int cursor = cursorBuffer.cursor; String prompt = console.getPrompt();
String line = reader.readLine(reader.getPrompt(), null, null); if (line == null) { // EOF break;
/** * Possible states in which the current readline operation may be in. */ private static enum State { /** * The user is just typing away */ NORMAL, /** * In the middle of a emacs seach */ SEARCH, FORWARD_SEARCH, /** * VI "yank-to" operation ("y" during move mode) */ VI_YANK_TO, /** * VI "delete-to" operation ("d" during move mode) */ VI_DELETE_TO, /** * VI "change-to" operation ("c" during move mode) */ VI_CHANGE_TO }
@Override public String readLine(String prompt) throws IOException { boolean oldHistoryEnabled = reader.isHistoryEnabled(); History oldHistory = reader.getHistory(); Collection<Completer> oldCompleters = new ArrayList<>(reader.getCompleters()); String oldPrompt = reader.getPrompt(); try { reader.setHistoryEnabled(false); reader.setHistory(new MemoryHistory()); for (Completer c : oldCompleters) { reader.removeCompleter(c); } String result = reader.readLine(prompt); return result; } finally { for (Completer c : oldCompleters) { reader.addCompleter(c); } reader.setPrompt(oldPrompt); reader.setHistory(oldHistory); reader.setHistoryEnabled(oldHistoryEnabled); } } }
cr.getPrompt(); do { cr.println("Select a process to attach to:");