Refine search
/** * Restore the terminal. */ protected void restoreTerminal() { try { terminal.restore(); } catch (Exception e) { // ignore } if (terminal instanceof UnixTerminal) { // workaround for GRAILS-11494 try { new TerminalLineSettings().set("sane"); } catch (Exception e) { // ignore } } }
private String colorize(String string) { if (string == null || string.indexOf(ChatColor.COLOR_CHAR) < 0) { return string; // no colors in the message } else if (!jline || !reader.getTerminal().isAnsiSupported()) { return ChatColor.stripColor(string); // color not supported } else { // colorize or strip all colors for (ChatColor color : colors) { if (replacements.containsKey(color)) { string = string.replaceAll("(?i)" + color, replacements.get(color)); // NON-NLS } else { string = string.replaceAll("(?i)" + color, ""); // NON-NLS } } return string + Ansi.ansi().reset(); } }
app.eventBus().emitSync(new CliSessionStart(this)); OutputStream os = socket.getOutputStream(); console = new ConsoleReader(socket.getInputStream(), os); String banner = Banner.cachedBanner(); printBanner(banner, console); appName = "act"; console.setPrompt(S.fmt("%s[%s]>", appName, id)); console.addCompleter(commandNameCompleter); console.getTerminal().setEchoEnabled(false);
Terminal terminal = TerminalFactory.get(); try { terminal.init(); } catch (Exception e) { throw new RuntimeException("Failed to initialise terminal: ", e); console = new ConsoleReader(System.in, System.out, terminal); console.setHistory(history); cmdSession = cmdProc.createSession(console.getInput(), new PrintStream(new WriterOutputStream(console.getOutput())), System.err);
public void redrawHeader() { saveCursorPosition(); getConsole().out().print(ansi().cursor(1, 1)); Ansi style = ansi(); if (getTheme().getHeaderBackground() != null) { style.bg(getTheme().getHeaderBackground()); } if (getTheme().getHeaderForeground() != null) { style.fg(getTheme().getHeaderForeground()); } String textCoords = "L:" + getLine() + " C:" + getColumn(); int displayFileLength = getTerminal().getWidth() - getTitle().length() - textCoords.length() - 1; getConsole().out().print(style.a(getTitle()).a(":").a(Strings.tryToTrimToSize(getDisplayAs(), displayFileLength)).a(isDirty() ? DIRTY_SIGN : "").eraseLine(Ansi.Erase.FORWARD)); getConsole().out().print(ansi().cursor(1, getTerminal().getWidth() - textCoords.length())); getConsole().out().print(ansi().a(textCoords).reset()); getConsole().out().print(ansi().cursor(getTerminal().getHeight(), 1)); restoreCursorPosition(); }
@Override public void start(Environment environment) throws IOException { errorPrintStream = new PrintStream(errorStream, true); String user = environment.getEnv().get(Environment.ENV_USER); if (Strings.isNullOrEmpty(user)) { user = "unknown"; } try { // Use our RemoteTerminal which does not depends on the platform. terminal = new RemoteTerminal(true); terminal.init(); } catch (Exception e) { LOGGER.warn("Error during terminal detection, falling back to unsupported terminal"); LOGGER.debug(DETAILS_MESSAGE, e); terminal = new UnsupportedTerminal(); } consoleReader = new ConsoleReader(inputStream, outputStream, terminal); // Disable jline shutdownhook to avoid exception at application shutdown jline.internal.Configuration.getString("jline.shutdownhook", "false"); consoleReader.addCompleter(new StringsCompleter(commandRegistry.getCommandList())); consoleReader.setCompletionHandler(new CandidateListCompletionHandler()); consoleReader.setPrompt(user + "@" + application.getId() + "$ "); consoleReader.setHandleUserInterrupt(false); consoleReader.setHistoryEnabled(true); ses = new SubjectAwareExecutorService(Executors.newSingleThreadExecutor()); ses.submit(this); }
private String resetColor() { if (terminal.isAnsiSupported()) { return Ansi.ansi().reset().toString(); } else { return ""; } }
context.attach(JMXManager.class); orderService.setTradingEnabled(true); Terminal terminal = TerminalFactory.get(); try { terminal.init(); } catch (Exception e) { throw new Error("Could not initialize terminal", e); terminal.setEchoEnabled(false); console = new ConsoleReader(); String prompt = config.getString("console.cursor", "ct>") + " "; console.setPrompt(prompt); history = new MemoryHistory(); history.setMaxSize(config.getInt("console.hisory.size", 100)); console.setHistory(history); console.setHistoryEnabled(true); console.setKeyMap(KeyMap.EMACS);
private String switchToColor(Ansi.Color color) { if (terminal.isAnsiSupported()) { return Ansi.ansi().fgBright(color).toString(); } else { return ""; } }
this.reader = new ConsoleReader(); ShellOptionsJC options = new ShellOptionsJC(); JCommander jc = new JCommander(); .addShutdownHook(new Thread(() -> reader.getTerminal().setEchoEnabled(true))); password = reader.readLine("Password: ", '*');
public void start(int initialPort) throws Exception { ConsoleReader console = new ConsoleReader(); console.getTerminal().setEchoEnabled(false); console.setPrompt("\u001B[32menkan\u001B[0m> "); History history = new FileHistory(new File(System.getProperty("user.home"), ".enkan_history")); console.setHistory(history); CandidateListCompletionHandler handler = new CandidateListCompletionHandler(); console.setCompletionHandler(handler); consoleHandler = new ConsoleHandler(console); if (initialPort > 0) { consoleHandler.connect(initialPort); } clientThread.execute(consoleHandler); clientThread.shutdown(); }
public static String[] getRawAnsiSettings() throws IOException { ConsoleReader reader = new ConsoleReader(); return new String[] { "Width: " + reader.getTerminal().getWidth(), "Height: " + reader.getTerminal().getHeight(), "Ansi: " + reader.getTerminal().isAnsiSupported(), "Echo: " + reader.getTerminal().isEchoEnabled(), "Supported: " + reader.getTerminal().isSupported() }; }
/** * Hides the editor screen and restore the {@link Terminal}. */ public void hide() { console.out().print("\33[" + 1 + ";" + terminal.getHeight() + ";r"); //Erase screen doesn't behave well on windows. for (int l = 1; l <= terminal.getHeight(); l++) { console.out().print(ansi().cursor(l, 1)); console.out().print(ansi().eraseLine(Erase.FORWARD)); } console.out().print(ansi().cursor(1, 1)); flush(); try { terminal.restore(); } catch (Exception e) { //noop } }
protected void printMethodList(CommandSession session, PrintStream out, SortedMap<String, String> commands) { Terminal term = (Terminal) session.get(".jline.terminal"); int termWidth = term != null ? term.getWidth() : 80; out.println(Ansi.ansi().a(Ansi.Attribute.INTENSITY_BOLD).a("COMMANDS").a(Ansi.Attribute.RESET)); ShellTable table = new ShellTable().noHeaders().separator(" ").size(termWidth); table.column(new Col("Command").maxSize(64)); table.column(new Col("Description")); for (Map.Entry<String,String> entry : commands.entrySet()) { String key = NameScoping.getCommandNameWithoutGlobalPrefix(session, entry.getKey()); table.addRow().addContent(Ansi.ansi().a(Ansi.Attribute.INTENSITY_BOLD).a(key).a(Ansi.Attribute.RESET), entry.getValue()); } table.print(out, true); }
@Inject public JLine2Console(History history) throws Exception { super(); TerminalFactory.configure(Type.AUTO); terminal = TerminalFactory.get(); terminal.init(); consoleReader = new ConsoleReader(System.in, System.out, terminal); consoleReader.setHistory(history); consoleReader.setHistoryEnabled(true); }
ConsoleReader console = new ConsoleReader(); console.setPrompt("> "); // FIXME: it seems that JLine2 does not support a continuation prompt interactive(createReader(console)); } finally { try { TerminalFactory.get().restore(); } catch (Exception e) { e.printStackTrace();