private void init() { try { if (!operation.getControlOperator().isRedirectionOut()) { console.getShell().out().print(ANSI.getAlternateBufferScreen()); console.getShell().out().println("print alternate screen..."); console.getShell().out().flush(); } if (console.getShell().in().getStdIn().available() > 0) { java.util.Scanner s = new java.util.Scanner(console.getShell().in().getStdIn()).useDelimiter("\\A"); String fileContent = s.hasNext() ? s.next() : ""; console.getShell().out().println("FILECONTENT: "); console.getShell().out().print(fileContent); console.getShell().out().flush(); } else console.getShell().out().println("console.in() == null"); readFromFile(); // detach after init if hasRedirectOut() if (operation.getControlOperator().isRedirectionOut()) { attached = false; } } catch (IOException ioe) { } }
@Override public void processOperation(CommandOperation operation) throws IOException { if (operation.getInput()[0] == 'q') { console.getShell().out().print(ANSI.getMainBufferScreen()); attached = false; } else if (operation.getInput()[0] == 'a') { readFromFile(); } else { } }
private void readFromFile() throws IOException { if (console.getShell().in().getStdIn().available() > 0) { console.getShell().out().println("FROM STDOUT: "); } else console.getShell().out().println("here should we present some text... press 'q' to quit"); }