@Override protected ConsoleReader createConsoleReader() { ConsoleReader consoleReader = super.createConsoleReader(); consoleReader.setHistory(gfshHistory); terminal = consoleReader.getTerminal(); return consoleReader; }
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(); } }
int nextTabStop(int pos) { int tabWidth = TAB_WIDTH; int width = getTerminal().getWidth(); int mod = (pos + tabWidth - 1) % tabWidth; int npos = pos + tabWidth - mod; return npos < width ? npos - pos : width - pos; }
private void printConfFooter(List<String> output) { int col3 = Math.max(1, Math.min(Integer.MAX_VALUE, reader.getTerminal().getWidth() - COL1 - COL2 - 6)); output.add(String.format("%" + COL1 + "s-+-%" + COL2 + "s-+-%-" + col3 + "s", Shell.repeat("-", COL1), Shell.repeat("-", COL2), Shell.repeat("-", col3))); }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws ShellCommandException, IOException { int numColumns = shellState.getReader().getTerminal().getWidth(); if (cl.hasOption(noWrapOpt.getOpt())) { numColumns = Integer.MAX_VALUE;
String prompt = "-- hit any key to continue or 'q' to quit --"; int lastPromptLength = prompt.length(); int termWidth = reader.getTerminal().getWidth(); int maxLines = reader.getTerminal().getHeight(); termWidth = reader.getTerminal().getWidth(); maxLines = reader.getTerminal().getHeight();
int width = getTerminal().getWidth(); int height = getTerminal().getHeight();
private final void printConstraintViolationException(ConstraintViolationException cve) { printException(cve, ""); int COL1 = 50, COL2 = 14; int col3 = Math.max(1, Math.min(Integer.MAX_VALUE, reader.getTerminal().getWidth() - COL1 - COL2 - 6)); logError(String.format("%" + COL1 + "s-+-%" + COL2 + "s-+-%" + col3 + "s%n", repeat("-", COL1), repeat("-", COL2), repeat("-", col3))); logError(String.format("%-" + COL1 + "s | %" + COL2 + "s | %-" + col3 + "s%n", "Constraint class", "Violation code", "Violation Description")); logError(String.format("%" + COL1 + "s-+-%" + COL2 + "s-+-%" + col3 + "s%n", repeat("-", COL1), repeat("-", COL2), repeat("-", col3))); for (TConstraintViolationSummary cvs : cve.violationSummaries) logError(String.format("%-" + COL1 + "s | %" + COL2 + "d | %-" + col3 + "s%n", cvs.constrainClass, cvs.violationCode, cvs.violationDescription)); logError(String.format("%" + COL1 + "s-+-%" + COL2 + "s-+-%" + col3 + "s%n", repeat("-", COL1), repeat("-", COL2), repeat("-", col3))); }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws IOException { // custom clear screen, so I don't have to redraw the prompt twice if (!shellState.getReader().getTerminal().isAnsiSupported()) { throw new IOException("Terminal does not support ANSI commands"); } // send the ANSI code to clear the screen shellState.getReader().print(((char) 27) + "[2J"); shellState.getReader().flush(); // then send the ANSI code to go to position 1,1 shellState.getReader().print(((char) 27) + "[1;1H"); shellState.getReader().flush(); return 0; }
@Override public void run() { try { console.getTerminal().restore(); } catch (final Exception ignored) { } }
@Override public int getHeight() { if (height > 0) return height; return reader.getTerminal().getHeight(); }
@Override public void run() { reader.getTerminal().setEchoEnabled(true); } });
@Override public void run() { try { console.getTerminal().restore(); } catch (final Exception ignored) { } }
.addShutdownHook(new Thread(() -> reader.getTerminal().setEchoEnabled(true)));
public void destroy() { try { console.getTerminal().restore(); } catch (Throwable e) { // Ignore } executor.shutdown(); }
@Override public int getWidth() { if (width > 0) return width; return reader.getTerminal().getWidth(); }
private void moveCursorFromTo(int i0, int i1) throws IOException { if (i0 == i1) return; int width = getTerminal().getWidth(); int l0 = i0 / width; int c0 = i0 % width;
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() }; }
public void run() throws Exception { reader.getTerminal().init(); printGreeting(); try { while(readExpression()) { } // run finalizers and shutdown session.close(); } finally { reader.getTerminal().restore(); } }
public void run() { try { if (reader.getHistory() instanceof FileHistory) { ((FileHistory) reader.getHistory()).flush(); } reader.getTerminal().restore(); } catch (Exception e) { // do nothing } } });