/** * Create a new stream set as {@link System} is currently configured. */ public static StreamSet system() { return new StreamSet(System.in, System.out, System.err); }
/** * Register streams for the current thread. */ public static void register(final InputStream in, final PrintStream out, final PrintStream err) { ensureInstalled(); if (log.isTraceEnabled()) { log.trace("Registering: {} -> {}, {}, {}", new Object[] { Thread.currentThread(), in, out, err }); } StreamRegistration prev = registration(false); StreamSet set = new StreamSet(in, out, err); StreamRegistration next = new StreamRegistration(set, prev); registrations.set(next); }
private static StreamSet ansiStreams(final StreamSet streams) { assert streams != null; return new StreamSet(streams.in, wrap(streams.out), wrap(streams.err)); }
/** * Install the hijacker. */ public static synchronized void install() { if (installed) { throw new IllegalStateException("Already installed"); } // Capture the current set of streams previous = new StreamSet(System.in, System.out, System.err); // Install our streams System.setIn(new DelegateInputStream()); System.setOut(new DelegateOutputStream(StreamSet.OutputType.OUT)); System.setErr(new DelegateOutputStream(StreamSet.OutputType.ERR)); installed = true; log.debug("Installed"); }
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; }