Skip to content

Commit

Permalink
Use simplified keymap for dumb terminal (#874)
Browse files Browse the repository at this point in the history
  • Loading branch information
hvesalai authored Oct 20, 2023
1 parent 58fd8f9 commit 60c9297
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions reader/src/main/java/org/jline/reader/LineReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ public interface LineReader {
String MAIN = "main";
String EMACS = "emacs";
String SAFE = ".safe";
String DUMB = "dumb";
String MENU = "menu";

//
Expand Down
15 changes: 13 additions & 2 deletions reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -5997,6 +5997,8 @@ public Map<String, KeyMap<Binding>> defaultKeyMaps() {
keyMaps.put(VIOPP, viOpp());
keyMaps.put(VISUAL, visual());
keyMaps.put(SAFE, safe());
keyMaps.put(DUMB, dumb());

if (getBoolean(BIND_TTY_SPECIAL_CHARS, true)) {
Attributes attr = terminal.getAttributes();
bindConsoleChars(keyMaps.get(EMACS), attr);
Expand All @@ -6007,8 +6009,9 @@ public Map<String, KeyMap<Binding>> defaultKeyMaps() {
keyMap.setUnicode(new Reference(SELF_INSERT));
keyMap.setAmbiguousTimeout(getLong(AMBIGUOUS_BINDING, DEFAULT_AMBIGUOUS_BINDING));
}
// By default, link main to emacs
keyMaps.put(MAIN, keyMaps.get(EMACS));
// By default, link main to emacs unless the temrinal is dumb
keyMaps.put(MAIN, keyMaps.get(isTerminalDumb() ? DUMB : EMACS));

return keyMaps;
}

Expand Down Expand Up @@ -6263,6 +6266,14 @@ public KeyMap<Binding> safe() {
return safe;
}

public KeyMap<Binding> dumb() {
KeyMap<Binding> dumb = new KeyMap<>();
bind(dumb, SELF_INSERT, range("^@-^?"));
bind(dumb, ACCEPT_LINE, "\r", "\n");
bind(dumb, BEEP, ctrl('G'));
return dumb;
}

public KeyMap<Binding> visual() {
KeyMap<Binding> visual = new KeyMap<>();
bind(visual, UP_LINE, key(Capability.key_up), "k");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public TestTerminal(StringWriter sw) throws IOException {
null,
new AnsiWriter(new BufferedWriter(sw)),
"name",
AbstractWindowsTerminal.TYPE_DUMB,
"windows",
Charset.defaultCharset(),
false,
SignalHandler.SIG_DFL,
Expand Down

0 comments on commit 60c9297

Please sign in to comment.