public void close() { if (running) { log.trace("Closing"); pipe.interrupt(); running = false; } }
public Console(final IO io, final Callable<ConsoleTask> taskFactory, final History history, final InputStream bindings) throws IOException { assert io != null; // history could be null // bindings could be null this.pipe = new InputPipe(io.streams, io.getTerminal(), new InputPipe.InterruptHandler() { public boolean interrupt() throws Exception { return interruptTask(); } public boolean stop() throws Exception { return false; } }); this.pipe.setName("Console InputPipe"); this.pipe.setDaemon(true); // Setup a new IO w/our pipe input stream & rebuilding the input reader this.io = new IO(new StreamSet(pipe.getInputStream(), io.streams.out, io.streams.err), null, io.out, io.err, true); this.reader = new ConsoleReader( this.io.streams.in, this.io.out, bindings, io.getTerminal()); this.reader.setPaginationEnabled(true); this.reader.setCompletionHandler(new CandidateListCompletionHandler()); this.reader.setHistory(history != null ? history : new MemoryHistory()); assert taskFactory != null; this.taskFactory = taskFactory; }
public void run() { log.trace("Running"); pipe.start(); running = true; while (running) { try { running = work(); } catch (Throwable t) { log.trace("Work failed", t); if (getErrorHandler() != null) { running = getErrorHandler().handleError(t); } else { t.printStackTrace(); } // Need to reset the terminal in some cases after a failure try { io.getTerminal().reset(); } catch (Exception e) { log.error("Failed to reset terminal", e); } } } log.trace("Stopped"); }