public int getTerminalHeight() { return terminal != null ? terminal.getHeight() : DEFAULT_HEIGHT; }
.build(); ConsoleReader reader = new ConsoleReader(); String line; while ((line = reader.readLine(PROMPT_MESSAGE)) != null) { client.write(streamName, ByteBuffer.wrap(line.getBytes(UTF_8))) .addEventListener(new FutureEventListener<DLSN>() {
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(); } }
public int getTerminalWidth() { if (terminal != null) { return terminal.getWidth(); } Map<String, String> env = System.getenv(); String columnsFromEnv = env.get("COLUMNS"); if (columnsFromEnv != null) { return Integer.parseInt(columnsFromEnv); } return DEFAULT_WIDTH; }
/** * 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 } } }
/** * Creates the instance of Terminal used directly in MicronautConsole. Note that there is also another terminal * instance created implicitly inside of ConsoleReader. That instance is controlled by the jline.terminal system * property. * * @return the new {@link Terminal} */ protected Terminal createTerminal() { terminal = TerminalFactory.create(); if (isWindows()) { terminal.setEchoEnabled(true); } return terminal; }
/** * @return Whether ansi is enabled */ public boolean isAnsiEnabled() { return Ansi.isEnabled() && (terminal != null && terminal.isAnsiSupported()) && ansiEnabled; }
/** * Restore the original terminal configuration, which can be used when * shutting down the console reader. The ConsoleReader cannot be * used after calling this method. */ @Override public void restore() throws Exception { // restore the old console mode setConsoleMode(originalMode); super.restore(); }
@Override protected int run() { // this allows the caller to manipulate the JVM state, so require the admin privilege. Jenkins.getActiveInstance().checkPermission(Jenkins.RUN_SCRIPTS); // this being remote means no jline capability is available System.setProperty("jline.terminal", UnsupportedTerminal.class.getName()); TerminalFactory.reset(); StringBuilder commandLine = new StringBuilder(); for (String arg : args) { if (commandLine.length() > 0) { commandLine.append(" "); } commandLine.append(arg); } Groovysh shell = createShell(stdin, stdout, stderr); return shell.run(commandLine.toString()); }
RRMultiWriter<Integer, String> writer = new RRMultiWriter(streamNameList, client); ConsoleReader reader = new ConsoleReader(); String line; while ((line = reader.readLine(PROMPT_MESSAGE)) != null) { writer.write(line) .addEventListener(new FutureEventListener<DLSN>() {
private static void printUsage() { HelpFormatter hf = new HelpFormatter(); try { int width = hf.getWidth(); int jlineWidth = TerminalFactory.get().getWidth(); width = Math.min(160, Math.max(jlineWidth, width)); hf.setWidth(width); } catch (Throwable t) { // Ignore } hf.printHelp("llapstatus", OPTIONS); }
client); ConsoleReader reader = new ConsoleReader(); String line; while ((line = reader.readLine(PROMPT_MESSAGE)) != null) { String[] parts = StringUtils.split(line, ':'); if (parts.length != 2) {
private static void printUsage() { HelpFormatter hf = new HelpFormatter(); try { int width = hf.getWidth(); int jlineWidth = TerminalFactory.get().getWidth(); width = Math.min(160, Math.max(jlineWidth, width)); hf.setWidth(width); } catch (Throwable t) { // Ignore } hf.printHelp("metatool", OPTIONS); }
.build(); ConsoleReader reader = new ConsoleReader(); String line; while ((line = reader.readLine(PROMPT_MESSAGE)) != null) { multiStreamWriter.write(ByteBuffer.wrap(line.getBytes(UTF_8))) .addEventListener(new FutureEventListener<DLSN>() {
private void printUsage() { HelpFormatter hf = new HelpFormatter(); try { int width = hf.getWidth(); int jlineWidth = TerminalFactory.get().getWidth(); width = Math.min(160, Math.max(jlineWidth, width)); // Ignore potentially incorrect values hf.setWidth(width); } catch (Throwable t) { // Ignore } hf.printHelp("llap", options); } }
writer = FutureUtils.result(dlm.openAsyncLogWriter()); ConsoleReader reader = new ConsoleReader(); String line; while ((line = reader.readLine(PROMPT_MESSAGE)) != null) { writer.write(new LogRecord(System.currentTimeMillis(), line.getBytes(UTF_8))) .addEventListener(new FutureEventListener<DLSN>() {
/** * Prints the info about a command to the given print writer. * * @param command command to print info * @param pw where to print the info */ public static void printCommandInfo(Command command, PrintWriter pw) { String description = String.format("%s: %s", command.getCommandName(), command.getDescription()); int width = 80; try { width = TerminalFactory.get().getWidth(); } catch (Exception e) { // In case the terminal factory failed to decide terminal type, use default width } HELP_FORMATTER.printWrapped(pw, width, description); HELP_FORMATTER.printUsage(pw, width, command.getUsage()); if (command.getOptions().getOptions().size() > 0) { HELP_FORMATTER.printOptions(pw, width, command.getOptions(), HELP_FORMATTER.getLeftPadding(), HELP_FORMATTER.getDescPadding()); } }