Skip to content

Commit

Permalink
Add a "fresh-line" widget, fixes #73
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Dec 16, 2016
1 parent 75251a5 commit 435ce36
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/jline/reader/LineReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public interface LineReader {
String EXPAND_OR_COMPLETE = "expand-or-complete";
String EXPAND_OR_COMPLETE_PREFIX = "expand-or-complete-prefix";
String EXPAND_WORD = "expand-word";
String FRESH_LINE = "fresh-line";
String FORWARD_CHAR = "forward-char";
String FORWARD_WORD = "forward-word";
String HISTORY_BEGINNING_SEARCH_BACKWARD = "history-beginning-search-backward";
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/jline/reader/impl/LineReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ public String readLine(String prompt, String rightPrompt, Character mask, String
if (!dumb) {
terminal.puts(Capability.keypad_xmit);
if (isSet(Option.AUTO_FRESH_LINE))
freshLine();
callWidget(FRESH_LINE);
if (isSet(Option.MOUSE))
terminal.trackMouse(Terminal.MouseTracking.Normal);
}
Expand Down Expand Up @@ -585,7 +585,7 @@ public String readLine(String prompt, String rightPrompt, Character mask, String
}

/** Make sure we position the cursor on column 0 */
void freshLine() {
protected boolean freshLine() {
AttributedStringBuilder sb = new AttributedStringBuilder();
sb.style(AttributedStyle.DEFAULT.foreground(AttributedStyle.BLACK + AttributedStyle.BRIGHT));
sb.append("~");
Expand All @@ -597,6 +597,7 @@ void freshLine() {
sb.append(" ");
sb.append(KeyMap.key(terminal, Capability.carriage_return));
print(sb.toAnsi(terminal));
return true;
}

@Override
Expand Down Expand Up @@ -3093,6 +3094,7 @@ protected Map<String, Widget> builtinWidgets() {
widgets.put(EXPAND_OR_COMPLETE, this::expandOrComplete);
widgets.put(EXPAND_OR_COMPLETE_PREFIX, this::expandOrCompletePrefix);
widgets.put(EXPAND_WORD, this::expandWord);
widgets.put(FRESH_LINE, this::freshLine);
widgets.put(FORWARD_CHAR, this::forwardChar);
widgets.put(FORWARD_WORD, this::forwardWord);
widgets.put(HISTORY_INCREMENTAL_SEARCH_BACKWARD, this::historyIncrementalSearchBackward);
Expand Down

0 comments on commit 435ce36

Please sign in to comment.