@Override public String readLine() { final String line = lineReader.readLine(prompt); addToHistory(line); return line; }
public void setReader(LineReader reader){ this.reader = (LineReaderImpl)reader; out = reader.getTerminal().writer(); }
lineReader.setVariable(LineReader.HISTORY_FILE, historyFilePath); LOGGER.info("Command history saved at: " + historyFilePath); } else {
.completer(completer) .build(); reader.setOpt(LineReader.Option.AUTO_FRESH_LINE); reader.unsetOpt(LineReader.Option.INSERT_TAB); final String line = reader.readLine(PROMPT); if (StringUtils.isBlank(line)) { continue; final ParsedLine parsedLine = reader.getParsedLine(); final String[] parsedArgs = parsedLine.words().toArray(new String[parsedLine.words().size()]); commandProcessor.process(parsedArgs);
lineReader.option(LineReader.Option.DISABLE_EVENT_EXPANSION, true); lineReader.setVariable(LineReader.ERRORS, 1); lineReader.option(LineReader.Option.CASE_INSENSITIVE, true);
if (line == null) { String s; while ((s = reader.readLine(p)) != null) { if (s.endsWith("\\")) { s = s.substring(0, s.length() -1); getReader().getTerminal().close(); } catch (IOException e) { ctx.printThrowable(e);
/** * Print confirmation message and get response * * @param message message to print * @return response read from terminal */ public String read(String message) { LineReader lr = SshShellCommandFactory.SSH_THREAD_CONTEXT.get().getLineReader(); if (message != null) { lr.getTerminal().writer().println(message); } lr.readLine(); if (lr.getTerminal() instanceof AbstractPosixTerminal) { lr.getTerminal().writer().println(); } return lr.getParsedLine().line(); }
@Override public String readLine(String prompt, Character mask) throws IOException { LineReader reader = LineReaderBuilder.builder() .terminal(jlineTerminal) .appName("karaf") .parser((line, cursor, context) -> new SimpleParsedLine(line, cursor)) .build(); reader.setOpt(LineReader.Option.DISABLE_EVENT_EXPANSION); reader.setVariable(LineReader.DISABLE_HISTORY, Boolean.TRUE); reader.setVariable(LineReader.DISABLE_COMPLETION, Boolean.TRUE); return reader.readLine(prompt, mask); }
private CharSequence readCommand(AtomicBoolean reading) throws UserInterruptException { CharSequence command = null; reading.set(true); try { reader.readLine(getPrompt(), getRPrompt(), maskingCallback, null); ParsedLine pl = reader.getParsedLine(); if (pl instanceof ParsedLineImpl) { command = ((ParsedLineImpl) pl).program(); } else if (pl != null) { command = pl.line(); } else { command = reader.getBuffer().toString(); } } catch (EndOfFileException e) { command = null; } catch (UserInterruptException e) { command = ""; // Do nothing } catch (Throwable t) { ShellUtil.logException(this, t); } finally { reading.set(false); } return command; }
terminal.flush(); if (reading.get() && !stopping.get()) { reader.callWidget(LineReader.REDRAW_LINE); reader.callWidget(LineReader.REDISPLAY); break; reader.readLine(prompt, rprompt, (Character) null, null); } finally { reading.set(false); ParsedLine parsedLine = reader.getParsedLine(); if (parsedLine == null) { throw new EndOfFileException(); reader.getHistory().save(); } catch (IOException e1) {
reader.setVariable(LineReader.HISTORY_FILE, file); String maxSizeStr = System.getProperty(SHELL_HISTORY_MAXSIZE); if (maxSizeStr != null) { reader.setVariable(LineReader.HISTORY_SIZE, Integer.parseInt(maxSizeStr)); reader.setVariable(LineReader.HISTORY_FILE_SIZE, Integer.parseInt(maxFileSizeStr)); history = new HistoryWrapper(reader.getHistory()); session.put(".commandSession", session); session.put(".jline.reader", reader); session.put(".jline.terminal", reader.getTerminal()); session.put(".jline.history", reader.getHistory()); session.put(Session.SCOPE, "shell:bundle:*"); session.put(Session.SUBSHELL, ""); session.put(Shell.VAR_COMPLETIONS, new HashMap<>()); session.put(Shell.VAR_READER, reader); session.put(Shell.VAR_TERMINAL, reader.getTerminal()); session.put(CommandSession.OPTION_NO_GLOB, Boolean.TRUE); session.currentDir(Paths.get(System.getProperty("user.dir")).toAbsolutePath().normalize());
private void runInteractive() { SignalHandler handler = signal -> _logger.debugf("Client: Ignoring signal: %s\n", signal); Signal.handle(new Signal("INT"), handler); try { while (!_exit) { try { String rawLine = _reader.readLine("batfish> "); if (rawLine == null) { break; } processCommand(rawLine); } catch (UserInterruptException e) { continue; } } } catch (EndOfFileException e) { // ignored } catch (Throwable t) { t.printStackTrace(); } finally { try { _reader.getHistory().save(); } catch (IOException e) { e.printStackTrace(); } } }
private static void setVar(LineReader reader, String key, String val) { if (LineReader.KEYMAP.equalsIgnoreCase(key)) { reader.setKeyMap(val); return; } for (LineReader.Option option : LineReader.Option.values()) { if (option.name().toLowerCase(Locale.ENGLISH).replace('_', '-').equals(val)) { if ("on".equalsIgnoreCase(val)) { reader.setOpt(option); } else if ("off".equalsIgnoreCase(val)) { reader.unsetOpt(option); } return; } } reader.setVariable(key, val); }
public void warning(String message) { if (getReader() == null) { System.out.println(message); return; } if (isWaitingForCommand()) getReader().callWidget(LineReader.CLEAR); getReader().getTerminal().writer().print(getSimpleFormatter().format(new LogRecord(Level.WARNING, message))); if (isWaitingForCommand()) getReader().callWidget(LineReader.REDRAW_LINE); if (isWaitingForCommand()) getReader().callWidget(LineReader.REDISPLAY); getReader().getTerminal().writer().flush(); if (getLogger() != null) getLogger().warning(message); }
private void setLineReaderHistoryIntVariable( String variableName, String value, SqlLineProperty property) { LineReader lineReader = sqlLine.getLineReader(); if (lineReader == null) { return; } int currentValue = getInt(property); try { if (DEFAULT.equals(value)) { if (currentValue == (Integer) property.defaultValue()) { return; } else { lineReader.setVariable(variableName, property.defaultValue()); lineReader.getHistory().save(); propertiesMap.put(property, property.defaultValue()); return; } } int parsedValue = Integer.parseInt(value); if (parsedValue == currentValue) { return; } else { lineReader.setVariable(variableName, parsedValue); lineReader.getHistory().save(); propertiesMap.put(property, parsedValue); } } catch (Exception e) { sqlLine.handleException(e); } }
History history = reader.getHistory(); if (opt.isSet("clear")) { history.purge(); out.println(sb.toAnsi(reader.getTerminal()));
Path historyPath = Paths.get(System.getenv(ENV_HOME), HISTORY_FILE); historyPath.toFile().createNewFile(); _reader.setVariable(LineReader.HISTORY_FILE, historyPath.toAbsolutePath().toString()); _reader .getTerminal() .handle(org.jline.terminal.Terminal.Signal.INT, signal -> handleSigInt()); _reader.unsetOpt(Option.INSERT_TAB); // supports completion with nothing entered PrintWriter pWriter = new PrintWriter(_reader.getTerminal().output(), true); OutputStream os = new WriterOutputStream(pWriter, StandardCharsets.UTF_8); PrintStream ps = new PrintStream(os, true);
if (Files.isDirectory(p)) { candidates.add(new Candidate( value + (reader.isSet(Option.AUTO_PARAM_SLASH) ? sep : ""), getDisplay(reader.getTerminal(), p), null, null, reader.isSet(Option.AUTO_REMOVE_SLASH) ? sep : null, null, false)); } else { candidates.add(new Candidate(value, getDisplay(reader.getTerminal(), p), null, null, null, null, true));