private void updatePrompt() { console.setPrompt(createPrompt(getCurrentResource())); }
@Override public PrintStream out() { return console.getShell().out(); }
@PreDestroy @Override public void close() { this.executionListeners.clear(); this.commandNotFoundListeners.clear(); this.console.stop(); }
.create(); console.getShell().out().println("**********************************************************************"); console.getShell().out().println("* Artificer CLI"); console.getShell().out().println("* Licensed under Apache License V2.0, Copyright 2015"); console.getShell().out().println("* Locale: " + Locale.getDefault().toString().trim()); console.getShell().out().println("**********************************************************************"); console.setPrompt(new Prompt("artificer> ")); console.start();
this.output = new ShellUIOutputImpl(console); setCurrentResource(initialResource); this.console.start();
@Override public Result execute(UIExecutionContext context) throws Exception { Shell shell = (Shell) context.getUIContext().getProvider(); shell.getConsole().clear(); return Results.success(); }
@Override public void setCurrentResource(final Resource<?> resource) { Assert.notNull(resource, "Current resource should not be null"); this.currentResource = resource; Resource<?> temp = resource; while (!(temp instanceof DirectoryResource) && temp != null) { temp = temp.getParent(); } if (temp instanceof DirectoryResource) { // Workaround to prevent "Current working directory must be a directory" exceptions when running in a // transaction File dir = ((DirectoryResource) temp).getUnderlyingResourceObject(); if (dir.exists()) { console.getAeshContext().setCurrentWorkingDirectory(new org.jboss.aesh.io.FileResource(dir)); } } updatePrompt(); }
public ShellContextImpl createUIContext() { Imported<UIContextListener> listeners = addonRegistry.getServices(UIContextListener.class); UISelection<?> initialSelection = Selections.from(currentResource); ShellContextImpl shellContextImpl = new ShellContextImpl(this, initialSelection, listeners); for (CommandExecutionListener listener : executionListeners) { shellContextImpl.addCommandExecutionListener(listener); } ExportManager exportManager = null; if (console != null) exportManager = console.getExportManager(); if (exportManager != null) { Map<Object, Object> attributeMap = shellContextImpl.getAttributeMap(); for (String variableName : exportManager.getAllNames()) { String variableValue = exportManager.getValue(variableName); attributeMap.put(variableName, variableValue); } } return shellContextImpl; }
@Override public PrintStream err() { return console.getShell().err(); }
try (Shell scriptShell = shellFactory.createShell(currentResource, settings)) scriptShell.getConsole().setPrompt(new Prompt("")); try (BufferedReader lineReader = new BufferedReader(reader))
@Override public Result execute(UIExecutionContext context) throws Exception { UIContext uiContext = context.getUIContext(); Shell shell = (Shell) uiContext.getProvider(); shell.getConsole().stop(); forge.stop(); uiContext.getAttributeMap().put("org.jboss.forge.exit", Boolean.TRUE); return Results.success(); } }
@Override public UIProgressMonitor createProgressMonitor(UIContext context) { return new ShellUIProgressMonitor(console.getShell().out()); }
TerminalSize terminalSize = shell.getConsole().getShell().getSize();
PrintStream out = console.getShell().out(); String label = InputComponents.getLabelFor(select, false); String description = select.getDescription();
private String promptInternal(String message, boolean echo, boolean required) throws InterruptedException { PrintStream out = console.getShell().out(); // prompts should begin with a blue '?' String indicator = (required) ? "*" : "?"; String promptFlag = new TerminalString(indicator, new TerminalColor(Color.BLUE, Color.DEFAULT), new TerminalTextStyle( CharacterType.BOLD)).toString(); out.print(promptFlag + " " + message + " "); String output; if (isAcceptDefaultsEnabled()) { output = null; } else { output = readInput(out, echo); } out.println(); return output; }
@Override public Result execute(UIExecutionContext context) throws Exception { UIContext uiContext = context.getUIContext(); Shell shell = (Shell) uiContext.getProvider(); TerminalSize terminalSize = shell.getConsole().getShell().getSize(); List<String> display = new ArrayList<>(); Set<CommandInfo> commandInfos = new TreeSet<>(); for (UICommand command : commandFactory.getCommands()) { UICommandMetadata metadata = command.getMetadata(uiContext); String name = commandFactory.getCommandName(uiContext, command); boolean enabled = command.isEnabled(uiContext); commandInfos.add(new CommandInfo(metadata.getCategory().toString(), name, metadata.getDescription(), enabled)); } for (CommandInfo command : commandInfos) { display.add(command.category + " > " + new TerminalString(command.name, new TerminalColor(command.enabled ? Color.CYAN : Color.RED, Color.DEFAULT)).toString() + " - " + command.description); } UIOutput output = uiContext.getProvider().getOutput(); PrintStream out = output.out(); out.println(Parser.formatDisplayList(display.toArray(new String[display.size()]), terminalSize.getHeight(), terminalSize.getWidth())); return Results.success(); }