/** * @param buffer * @return A ConsoleOperation that that StellarShell uses to drive input. */ private ConsoleOperation createOp(String buffer) { return new ConsoleOperation(ControlOperator.APPEND_OUT, buffer); }
/** * Creates the REPL's console. * @param commandLine The command line options. */ private Console createConsole(CommandLine commandLine) { // console settings boolean useAnsi = !commandLine.hasOption("na"); SettingsBuilder settings = new SettingsBuilder().enableAlias(true) .enableMan(true) .ansi(useAnsi) .parseOperators(false) .inputStream(PausableInput.INSTANCE); if(commandLine.hasOption("irc")) { settings = settings.inputrc(new File(commandLine.getOptionValue("irc"))); } return new Console(settings.create()); }
/** * Quits the console. */ private void handleQuit() { try { console.stop(); StellarFunctions.close(); } catch (Throwable e) { e.printStackTrace(); } }
protected String promptForInput(String prompt, Character mask, CommandInvocation invocation) throws IOException, InterruptedException { ConsoleBuffer consoleBuffer = new AeshConsoleBufferBuilder() .shell(invocation.getShell()) .prompt(new Prompt(prompt, mask)) .create(); InputProcessor inputProcessor = new AeshInputProcessorBuilder() .consoleBuffer(consoleBuffer) .create(); consoleBuffer.displayPrompt(); String result; do { result = inputProcessor.parseOperation(invocation.getInput()); } while(result == null ); return result; }
executor = createExecutor(commandLine, console, props, autoCompleter); loadVariables(commandLine, executor); console.setPrompt(new Prompt(EXPRESSION_PROMPT)); console.addCompletion(this); console.setConsoleCallback(this);
@Override public void handleInterrupt(Console console, Action action) { if (action == Action.INTERRUPT) { console.getShell().out().println("^C"); console.clearBufferAndDisplayPrompt(); } else { console.stop(); console.currentProcessFinished(null); } } });
newAction.addActionListener((ActionEvent e) -> { Prompt nf = new Prompt("Add a new function","f(x)="); nf.createPrompt(); System.out.println(nf.getOutput()); });
private void writeLine(String out) { console.getShell().out().println(out); }
@Override public int execute(ConsoleOperation output) throws InterruptedException { // grab the user the input String expression = StringUtils.trimToEmpty(output.getBuffer()); if(StringUtils.isNotBlank(expression) ) { // execute the expression StellarResult result = executor.execute(expression); if(result.isSuccess()) { // on success result.getValue().ifPresent(v -> writeLine(v.toString())); } else if (result.isError()) { // on error result.getException().ifPresent(e -> writeLine(ERROR_PROMPT + e.getMessage())); result.getException().ifPresent(e -> e.printStackTrace()); } else if(result.isTerminate()) { // on quit handleQuit(); } else { // should never happen throw new IllegalStateException("An execution result is neither a success nor a failure. Please file a bug report."); } } return 0; }
@Override public PrintStream err() { return console.getShell().err(); }
private void updatePrompt() { console.setPrompt(createPrompt(getCurrentResource())); }
public boolean isStdinAvailable() { return console.isRunning(); } }
/** * Handles the main loop for the REPL. */ public void run() { // welcome message writeLine(WELCOME); // print the globals if we got 'em executor.getContext() .getCapability(GLOBAL_CONFIG, false) .ifPresent(conf -> writeLine(conf.toString())); console.start(); }
PausableInput.INSTANCE.unpause(); if (console.isPresent()) { ((Console) console.get()).pushToInputStream("\b\n");
/** * The REPL should handle if the user chooses to quit. */ @Test public void testQuit() throws Exception { stellarShell.execute(createOp("quit")); // the console should not be running assertFalse(stellarShell.getConsole().isRunning()); }
@PreDestroy @Override public void close() { this.executionListeners.clear(); this.commandNotFoundListeners.clear(); this.console.stop(); }
public ArtificerContext() { cwd = new FileResource("").newInstance(Config.getUserDir()); }
@Override public PrintStream out() { return console.getShell().out(); }
public boolean isStdinAvailable() { return console.isRunning(); } }
@Override public UIProgressMonitor createProgressMonitor(UIContext context) { return new ShellUIProgressMonitor(console.getShell().out()); }