Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use simplified keymap for dumb terminal #874

Merged
merged 2 commits into from
Oct 20, 2023
Merged

Conversation

hvesalai
Copy link
Contributor

Fixes #864

@hvesalai
Copy link
Contributor Author

hvesalai commented Oct 18, 2023

Side note: during fixing this I run into some other problems. Most notably current implementation inhibits CRs from dumb terminal which means if you run

env TERM=dumb ./build repl

The carriage return key will not do anything. The only way to do ACCEPT_LINE is CTRL-J (i.e. LF)

This problem stems from the line https://github.com/jline/jline3/blob/master/reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java#L639

@hvesalai
Copy link
Contributor Author

hvesalai commented Oct 18, 2023

Side note 2: the first test in reader/src/test/java/org/jline/terminal/impl/AbstractWindowsTerminalTest.java (testBracketingPasteSmall()) was failing already before I started making this change and I didn't fix it.

It should be noted that it will not work on dumb terminals unless the respective bind is added to the dumb terminal bindings, i.e. bind(dumb, BEGIN_PASTE, BRACKETED_PASTE_BEGIN);

Doing that binding would be nonsensical since bracketed paste is not turned on for dumb
https://github.com/jline/jline3/blob/master/reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java#L631

public KeyMap<Binding> dumb() {
KeyMap<Binding> dumb = new KeyMap<>();
bind(dumb, SELF_INSERT, range("^@-^?"));
bind(dumb, ACCEPT_LINE, "\r", "\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would adding "\r\n" as an additional key binding help with the cr/lf issue on dumb terminals ?

Copy link
Contributor Author

@hvesalai hvesalai Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would not be deterministic then. How will the system know if to expect only \r or \r\n. Remember that there might be no immediate input after the \r. Consider the following interaction:

Time n: user inputs something that triggers SELF_INSERTs, such as "Hello"
Time n+1: user inputs \r.
Time n+m: user inputs a new thing that trigger SELF_INSERTs, not being \n, for example, "World"

Surely we cannot wait for a period of unkown m to determine whether the \r at n+1 should have triggered ACCEPT_LINE.

Copy link
Contributor Author

@hvesalai hvesalai Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider above with this user over a slow connection:

Time n: process is piped something that triggers SELF_INSERTs, such as "Hello"
Time n+1: process is piped \r
Time n+m: process is piped \n

Waiting for the \n here would be possible (using a short timeout > m), but that would mean that a dumb terminal would always wait after a \r to see if there is a \n following it. Sometimes it could be available, sometimes not. The bottom line is that it would in any case slow down the process.

@hvesalai
Copy link
Contributor Author

@gnodet this PR is actually more important for me. I think it should be quite clean, so maybe you could merge this now and I can continue with the other PR as needed.

Copy link
Member

@gnodet gnodet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@gnodet
Copy link
Member

gnodet commented Oct 20, 2023

@hvesalai Unit tests are failing...

@hvesalai
Copy link
Contributor Author

hvesalai commented Oct 20, 2023

@gnodet yes I know. See note here #874 (comment)

I wanted to get your feedback on how to fix this.

@gnodet
Copy link
Member

gnodet commented Oct 20, 2023

@gnodet yes I know. See note here #874 (comment)

I wanted to get your feedback on how to fix this.

Something like the following should work:

diff --git a/reader/src/test/java/org/jline/terminal/impl/AbstractWindowsTerminalTest.java b/reader/src/test/java/org/jline/terminal/impl/AbstractWindowsTerminalTest.java
index f3dee5e6..85c9f30a 100644
--- a/reader/src/test/java/org/jline/terminal/impl/AbstractWindowsTerminalTest.java
+++ b/reader/src/test/java/org/jline/terminal/impl/AbstractWindowsTerminalTest.java
@@ -87,7 +87,7 @@ public class AbstractWindowsTerminalTest {
                     null,
                     new AnsiWriter(new BufferedWriter(sw)),
                     "name",
-                    AbstractWindowsTerminal.TYPE_DUMB,
+                    "windows",
                     Charset.defaultCharset(),
                     false,
                     SignalHandler.SIG_DFL,
(END)

@hvesalai
Copy link
Contributor Author

@gnodet that fixes it, thank you! Pushed the fix to this PR.

@gnodet gnodet merged commit 60c9297 into jline:master Oct 20, 2023
3 checks passed
@gnodet gnodet added this to the 3.24.0 milestone Oct 24, 2023
@gnodet gnodet mentioned this pull request Oct 25, 2023
@gnodet gnodet modified the milestones: 3.24.0, 3.26.0 Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vi-style paren blinking causes unwanted "echo" in emacs
2 participants