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

Switch to StdioInputMethod when TERM is 'dumb' #907

Merged
merged 3 commits into from
May 1, 2024

Conversation

dgutov
Copy link
Contributor

@dgutov dgutov commented Mar 22, 2024

This works around Reline's misbehavior on low-capability terminals, such as when IRB is launched inside Emacs (which can look like ruby/reline#616, even though that issue is about non-tty usage). It should also resolve #68 and resolve #113 which were filed out of similar need.

The existing solution we use in Emacs with inf-ruby is to detect the current version of the tool and launch it with both --nomultiline and --nosingleline when we think it supports those options. But that only covers one entry point -- having REPL launched from one of the few preset commands in inf-ruby, whereas all the other cases (custom console script by a user; or binding.irb invocation inside a test suite) remain problematic, requiring case-by-case solutions.

The provided simple change looks like a significant improvement in my testing.

This works around Reline's misbehavior on low-capability terminals,
such as when IRB is launched inside Emacs (ruby/reline#616).

It should also resolve ruby#68 and resolve ruby#113 which were filed out of
similar need.
@dgutov
Copy link
Contributor Author

dgutov commented Mar 22, 2024

N.B. the older "inverted triangle" issue seems to have been fixed in Reline, somewhere between the versions 0.1.5 and 0.4.3. But the weird input repetition is still a problem.

@@ -151,6 +151,10 @@ def initialize(irb, workspace = nil, input_method = nil)
@command_aliases = @user_aliases.merge(KEYWORD_ALIASES)
end

private def term_interactive?
STDIN.tty? && ENV['TERM'] != 'dumb'
Copy link
Member

Choose a reason for hiding this comment

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

How about STDIN.tty? && STDOUT.tty?? Does this solves your problem?

When STDIN and STDOUT are both tty, it is executed in an interactive terminal.
Reline and IRB both have a tty check, but there is an inconsistency. IRB only checks STDIN.tty?, and on the other hand, Reline only checks $stdout.tty?. If $stdout is not a tty or TERM is dumb, Reline enters unusable test mode.

ENV['TERM'] == 'dumb' is used for testing IRB with Reline. Although using ENV['TERM'] like this is a bit weird, changing the TERM=dumb behavior right now will break the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, both STDIN.tty? and STDOUT.tty? return true when the shell is running inside Emacs. But apparently some of the terminal features it's using don't work as expected in that environment. So treating "dumb" terminals differently makes sense to me (that's the definition - terminal with limited capabilities).

Do you know any other real-world "dumb" terminals? It could be useful to test IRB in one of them as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tests are indeed currently broken by this change, any recommendations for finding a fix would be welcome.

Copy link
Member

Choose a reason for hiding this comment

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

I see. Thanks for the explanation. I agree IRB should treat dumb terminals differently 👍

For test, could you add a way to test IRB by forcing term_interactive? to be true?
Let it return true if ENV["TEST_IRB_FORCE_INTERACTIVE"] is set, and in IRB's test which uses PTY.spawn, specify both TEST_IRB_FORCE_INTERACTIVE and TERM=dumb env.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, added.

dgutov added a commit to dgutov/irb that referenced this pull request Mar 22, 2024
@dgutov dgutov force-pushed the no_multiline_or_singleline_on_dumb_term branch from 8b8ad45 to 1edfbf1 Compare March 22, 2024 18:31
@dgutov
Copy link
Contributor Author

dgutov commented Mar 22, 2024

The "latest reline" breakage is the same on master.

@tompng
Copy link
Member

tompng commented May 1, 2024

Looks good! thank you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

Change the editor module using an environment variable? --inf-ruby-mode semantics
3 participants