private static MemoryHistory getHistory() { String historyFilePath = System.getenv("PRESTO_HISTORY_FILE"); File historyFile; if (isNullOrEmpty(historyFilePath)) { historyFile = new File(getUserHome(), ".presto_history"); } else { historyFile = new File(historyFilePath); } return getHistory(historyFile); }
public static String getString(final String name) { return getString(name, null); }
/** * Get the default encoding. Will first look at the LC_ALL, LC_CTYPE, and LANG environment variables, then the input.encoding * system property, then the default charset according to the JVM. * * @return The default encoding to use when none is specified. */ public static String getEncoding() { // Check for standard locale environment variables, in order of precedence, first. // See http://www.gnu.org/s/libc/manual/html_node/Locale-Categories.html for (String envOption : new String[]{"LC_ALL", "LC_CTYPE", "LANG"}) { String envEncoding = extractEncodingFromCtype(System.getenv(envOption)); if (envEncoding != null) { try { if (Charset.isSupported(envEncoding)) { return envEncoding; } } catch (IllegalCharsetNameException e) { continue; } } } return getString("input.encoding", Charset.defaultCharset().name()); }
/** * Retrieve the URL for the inputrc configuration file in effect. Intended * use is for instantiating ConsoleKeys, to read inputrc variables. */ public static URL getInputRc() throws IOException { String path = Configuration.getString(JLINE_INPUTRC); if (path == null) { File f = new File(Configuration.getUserHome(), INPUT_RC); if (!f.exists()) { f = new File(DEFAULT_INPUT_RC); } return f.toURI().toURL(); } else { return Urls.create(path); } }
private static Properties initProperties() { URL url = determineUrl(); Properties props = new Properties(); try { loadProperties(url, props); } catch (FileNotFoundException e) { // debug here and no stack trace, as this can happen normally if default jline.rc file is missing Log.debug("Unable to read configuration: ", e.toString()); } catch (IOException e) { Log.warn("Unable to read configuration from: ", url, e); } return props; }
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(); } }
/** * @since 2.7 */ public static boolean isWindows() { return getOsName().startsWith("windows"); }
/** * @since 2.7 */ public static void reset() { Log.debug("Resetting"); properties = null; // force new properties to load getProperties(); }
public static boolean getBoolean(final String name) { return getBoolean(name, false); }
/** * @since 2.7 */ public static Properties getProperties() { // Not sure its worth to guard this with any synchronization, volatile field probably sufficient if (properties == null) { properties = initProperties(); } return properties; }
void setInput(final InputStream in) throws IOException { this.escapeTimeout = Configuration.getLong(JLINE_ESC_TIMEOUT, 100); boolean nonBlockingEnabled = escapeTimeout > 0L && terminal.isSupported() && in != null; /* * If we had a non-blocking thread already going, then shut it down * and start a new one. */ if (this.in != null) { this.in.shutdown(); } final InputStream wrapped = terminal.wrapInIfNeeded( in ); this.in = new NonBlockingInputStream(wrapped, nonBlockingEnabled); this.reader = new InputStreamReader( this.in, encoding ); }
private static URL getInputRc() throws IOException { String path = Configuration.getString(JLINE_INPUTRC); if (path == null) { File f = new File(Configuration.getUserHome(), INPUT_RC); if (!f.exists()) { f = new File(DEFAULT_INPUT_RC); } return f.toURI().toURL(); } else { return Urls.create(path); } }
private static Properties initProperties() { URL url = determineUrl(); Properties props = new Properties(); try { loadProperties(url, props); } catch (FileNotFoundException e) { // debug here and no stack trace, as this can happen normally if default jline.rc file is missing Log.debug("Unable to read configuration: ", e.toString()); } catch (IOException e) { Log.warn("Unable to read configuration from: ", url, e); } return props; }
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 boolean isHpux() { return getOsName().startsWith("hp"); }
public static String getString(final String name, final String defaultValue) { checkNotNull(name); String value; // Check sysprops first, it always wins value = System.getProperty(name); if (value == null) { // Next try userprops value = getProperties().getProperty(name); if (value == null) { // else use the default value = defaultValue; } } return value; }
@Override public void init() throws Exception { super.init(); setAnsiSupported(Configuration.getBoolean(ANSI, true)); // // FIXME: Need a way to disable direct console and sysin detection muck // setDirectConsole(Configuration.getBoolean(DIRECT_CONSOLE, true)); this.originalMode = getConsoleMode(); setConsoleMode(originalMode & ~ENABLE_ECHO_INPUT.code); setEchoEnabled(false); }
/** * @since 2.7 */ public static Properties getProperties() { // Not sure its worth to guard this with any synchronization, volatile field probably sufficient if (properties == null) { properties = initProperties(); } return properties; }