/** * 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 stty(final String... args) throws IOException, InterruptedException { String[] s = new String[args.length + 1]; s[0] = sttyCommand; System.arraycopy(args, 0, s, 1, args.length); return exec(s); }
public String getPropertyAsString(String name) { checkNotNull(name); if (!fetchConfig(name)) { return null; } return getPropertyAsString(name, config); }
protected static int getProperty(String name, String stty) { String str = getPropertyAsString(name, stty); return str != null ? parseControlChar(str) : -1; }
public void restore() throws IOException, InterruptedException { set(initialConfig); }
public void disableInterruptCharacter() { try { intr = getSettings().getPropertyAsString("intr"); if ("<undef>".equals(intr)) { intr = null; } settings.undef("intr"); } catch (Exception e) { if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); } Log.error("Failed to disable interrupt character", e); } }
/** * Remove line-buffered input by invoking "stty -icanon min 1" * against the current terminal. */ @Override public void init() throws Exception { super.init(); setAnsiSupported(true); // Set the console to be character-buffered instead of line-buffered. // Make sure we're distinguishing carriage return from newline. // Allow ctrl-s keypress to be used (as forward search) // // Please note that FreeBSD does not seem to support -icrnl and thus // has to be handled separately. Otherwise the console will be "stuck" // and will neither accept input nor print anything to stdout. if (Configuration.getOsName().contains(TerminalFactory.FREEBSD)) { settings.set("-icanon min 1 -inlcr -ixon"); } else { settings.set("-icanon min 1 -icrnl -inlcr -ixon"); } settings.undef("dsusp"); setEchoEnabled(false); parseInfoCmp(); }
public static synchronized TerminalLineSettings getSettings(String device) throws IOException, InterruptedException { TerminalLineSettings settings = SETTINGS.get(device); if (settings == null) { settings = new TerminalLineSettings(device, false); SETTINGS.put(device, settings); } return settings; }
/** * <p> * Get the value of a stty property, including the management of a cache. * </p> * * @param name the stty property. * @return the stty property value. */ public int getProperty(String name) { checkNotNull(name); if (!fetchConfig(name)) { return -1; } return getProperty(name, config); }
/** * Returns the value of <tt>stty columns</tt> param. */ @Override public int getWidth() { int w = settings.getProperty("columns"); return w < 1 ? DEFAULT_WIDTH : w; }
private TerminalLineSettings(String ttyDevice, boolean unused) throws IOException, InterruptedException { checkNotNull(ttyDevice); this.sttyCommand = Configuration.getString(JLINE_STTY, DEFAULT_STTY); this.shCommand = Configuration.getString(JLINE_SH, DEFAULT_SH); this.ttyDevice = ttyDevice; this.useRedirect = SUPPORTS_REDIRECT && DEFAULT_TTY.equals(ttyDevice); this.initialConfig = get("-g").trim(); this.config = get("-a"); this.configLastFetched = System.currentTimeMillis(); Log.debug("Config: ", config); // sanity check if (config.length() == 0) { throw new IOException(MessageFormat.format("Unrecognized stty code: {0}", config)); } }
public UnixTerminal(String ttyDevice, String type) throws Exception { super(true); checkNotNull(ttyDevice); this.settings = TerminalLineSettings.getSettings(ttyDevice); if (type == null) { type = System.getenv("TERM"); } this.type = type; parseInfoCmp(); }
public ConsoleReader(final @Nullable String appName, final InputStream in, final OutputStream out, final @Nullable Terminal term, final @Nullable String encoding) throws IOException { this.appName = appName != null ? appName : "JLine"; this.encoding = encoding != null ? encoding : Configuration.getEncoding(); Terminal terminal = term != null ? term : TerminalFactory.get(); this.terminal = terminal instanceof Terminal2 ? (Terminal2) terminal : new DefaultTerminal2(terminal); String outEncoding = terminal.getOutputEncoding() != null? terminal.getOutputEncoding() : this.encoding; this.out = new OutputStreamWriter(terminal.wrapOutIfNeeded(out), outEncoding); setInput( in ); this.inputrcUrl = getInputRc(); consoleKeys = new ConsoleKeys(this.appName, inputrcUrl); if (terminal instanceof UnixTerminal && TerminalLineSettings.DEFAULT_TTY.equals(((UnixTerminal) terminal).getSettings().getTtyDevice()) && Configuration.getBoolean("jline.sigcont", false)) { setupSigCont(); } }
public static String waitAndCapture(Process p) throws IOException, InterruptedException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); InputStream in = null; InputStream err = null; OutputStream out = null; try { int c; in = p.getInputStream(); while ((c = in.read()) != -1) { bout.write(c); } err = p.getErrorStream(); while ((c = err.read()) != -1) { bout.write(c); } out = p.getOutputStream(); p.waitFor(); } finally { close(in, out, err); } return bout.toString(); }
public void enableInterruptCharacter() { try { if (intr != null) { settings.set("intr", intr); } } catch (Exception e) { if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); } Log.error("Failed to enable interrupt character", e); } }
public void disableLitteralNextCharacter() { try { lnext = getSettings().getPropertyAsString("lnext"); if ("<undef>".equals(lnext)) { lnext = null; } settings.undef("lnext"); } catch (Exception e) { if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); } Log.error("Failed to disable litteral next character", e); } }
/** * Remove line-buffered input by invoking "stty -icanon min 1" * against the current terminal. */ @Override public void init() throws Exception { super.init(); setAnsiSupported(true); // Set the console to be character-buffered instead of line-buffered. // Make sure we're distinguishing carriage return from newline. // Allow ctrl-s keypress to be used (as forward search) // // Please note that FreeBSD does not seem to support -icrnl and thus // has to be handled separately. Otherwise the console will be "stuck" // and will neither accept input nor print anything to stdout. if (Configuration.getOsName().contains(TerminalFactory.FREEBSD)) { settings.set("-icanon min 1 -inlcr -ixon"); } else { settings.set("-icanon min 1 -icrnl -inlcr -ixon"); } settings.undef("dsusp"); setEchoEnabled(false); parseInfoCmp(); }
public static synchronized TerminalLineSettings getSettings(String device) throws IOException, InterruptedException { TerminalLineSettings settings = SETTINGS.get(device); if (settings == null) { settings = new TerminalLineSettings(device, false); SETTINGS.put(device, settings); } return settings; }
protected static int getProperty(String name, String stty) { String str = getPropertyAsString(name, stty); return str != null ? parseControlChar(str) : -1; }
/** * <p> * Get the value of a stty property, including the management of a cache. * </p> * * @param name the stty property. * @return the stty property value. */ public int getProperty(String name) { checkNotNull(name); if (!fetchConfig(name)) { return -1; } return getProperty(name, config); }