private CharSequence getFirstWord() { String s = buf.toString(); int i = 0; while (i < s.length() && !Character.isWhitespace(s.charAt(i))) { i++; } return s.substring(0, i); }
protected boolean insertTab() { return isSet(Option.INSERT_TAB) && getLastBinding().equals("\t") && buf.toString().matches("(^|[\\s\\S]*\n)[\r\n\t ]*"); }
protected boolean killBuffer() { killRing.add(buf.toString()); buf.clear(); return true; }
protected boolean expandHistory() { String str = buf.toString(); String exp = expander.expandHistory(history, str); if (!exp.equals(str)) { buf.clear(); buf.write(exp); return true; } else { return false; } }
String str = buf.toString(); String historyLine = str;
protected boolean historySearchForward() { if (historyBuffer == null || buf.length() == 0 || !buf.toString().equals(history.current())) { historyBuffer = buf.copy(); searchBuffer = getFirstWord(); if (searchIndex == -1) { history.moveToEnd(); if (!buf.toString().equals(historyBuffer.toString())) { setBuffer(historyBuffer.toString()); historyBuffer = null; } else { } else { history.moveToEnd(); setBuffer(historyBuffer.toString()); return false; if (!buf.toString().equals(historyBuffer.toString())) { setBuffer(historyBuffer.toString()); historyBuffer = null; } else {
/** * Move up or down the history tree. * @param next <code>true</code> to go to the next, <code>false</code> for the previous. * @return <code>true</code> if successful, <code>false</code> otherwise */ protected boolean moveHistory(final boolean next) { if (!buf.toString().equals(history.current())) { modifiedHistory.put(history.index(), buf.toString()); } if (next && !history.next()) { return false; } else if (!next && !history.previous()) { return false; } setBuffer(modifiedHistory.containsKey(history.index()) ? modifiedHistory.get(history.index()) : history.current()); return true; }
protected boolean acceptLine() { parsedLine = null; if (!isSet(Option.DISABLE_EVENT_EXPANSION)) { try { String str = buf.toString(); String exp = expander.expandHistory(history, str); if (!exp.equals(str)) { buf.clear(); buf.write(exp); if (isSet(Option.HISTORY_VERIFY)) { return true; } } } catch (IllegalArgumentException e) { // Ignore } } try { parsedLine = parser.parse(buf.toString(), buf.cursor(), ParseContext.ACCEPT_LINE); } catch (EOFError e) { buf.write("\n"); return true; } catch (SyntaxError e) { // do nothing } callWidget(CALLBACK_FINISH); state = State.DONE; return true; }
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; }
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; }
protected boolean historySearchBackward() { if (historyBuffer == null || buf.length() == 0 || !buf.toString().equals(history.current())) { historyBuffer = buf.copy(); searchBuffer = getFirstWord(); } int searchIndex = searchBackwards(searchBuffer.toString(), history.index(), true); if (searchIndex == -1) { return false; } else { // Maintain cursor position while searching. if (history.moveTo(searchIndex)) { setBuffer(history.current()); } else { return false; } } return true; }
if (searchBackward) { boolean nextOnly = next; pair = matches(pat, buf.toString(), searchIndex).stream() .filter(p -> nextOnly ? p.v < buf.cursor() : p.v <= buf.cursor()) .max(Comparator.comparing(Pair::getV)) pair = matches(pat, buf.toString(), searchIndex).stream() .filter(p -> nextOnly ? p.v > buf.cursor() : p.v >= buf.cursor()) .min(Comparator.comparing(Pair::getV)) .orElse(null); if (pair == null && searchIndex >= 0) { pair = matches(pat, originalBuffer.toString(), -1).stream() .min(Comparator.comparing(Pair::getV)) .orElse(null); buf.write(history.get(searchIndex)); } else { buf.write(originalBuffer.toString());
protected boolean viYankTo() { int cursorStart = buf.cursor(); Binding o = readBinding(getKeys()); if (o instanceof Reference) { // TODO: be smarter on how to get the vi range String op = viDeleteChangeYankToRemap(((Reference) o).name()); // Similar to delete-to, a "yy" yanks the whole line. if (VI_YANK.equals(op)) { yankBuffer = buf.toString(); return true; } else { viMoveMode = ViMoveMode.YANK; Widget widget = widgets.get(op); if (widget != null && !widget.apply()) { return false; } viMoveMode = ViMoveMode.NORMAL; } return viYankTo(cursorStart, buf.cursor()); } else { pushBackBinding(); return false; } }
/** * Compute the full string to be displayed with the left, right and secondary prompts * @param secondaryPrompts a list to store the secondary prompts * @return the displayed string including the buffer, left prompts and the help below */ public AttributedString getDisplayedBufferWithPrompts(List<AttributedString> secondaryPrompts) { AttributedString attBuf = getHighlightedBuffer(buf.toString()); AttributedString tNewBuf = insertSecondaryPrompts(attBuf, secondaryPrompts); AttributedStringBuilder full = new AttributedStringBuilder().tabs(TAB_WIDTH); full.append(prompt); full.append(tNewBuf); if (post != null) { full.append("\n"); full.append(post.get()); } return full.toAttributedString(); }
AttributedString text = insertSecondaryPrompts(AttributedStringBuilder.append(prompt, buf.toString()), new ArrayList<>()); int promptLines = text.columnSplitLength(size.getColumns(), false, display.delayLineWrap()).size(); PostResult postResult = computePost(possible, null, null, completed); AttributedString t = insertSecondaryPrompts(AttributedStringBuilder.append(prompt, buf.toString()), new ArrayList<>()); int pl = t.columnSplitLength(size.getColumns(), false, display.delayLineWrap()).size(); PostResult pr = computePost(cands, null, null, current);
line = wrap(parser.parse(buf.toString(), buf.cursor(), ParseContext.COMPLETE)); } catch (Exception e) { Log.info("Error while parsing line", e);
AttributedString text = insertSecondaryPrompts(AttributedStringBuilder.append(prompt, buf.toString()), new ArrayList<>()); int promptLines = text.columnSplitLength(size.getColumns(), false, display.delayLineWrap()).size(); if (pr.lines > size.getRows() - promptLines) {
concat(getHighlightedBuffer(buf.toString()).columnSplitLength(Integer.MAX_VALUE), sb); AttributedString full = sb.toAttributedString();