From 8138d8d8b4fac0d05276b4e9a09e5d390728c916 Mon Sep 17 00:00:00 2001 From: tompng Date: Thu, 2 May 2024 03:32:33 +0900 Subject: [PATCH] Revert "Switch to StdioInputMethod when TERM is 'dumb' (#907)" This reverts commit 241e06173fd68b8e827aafc72a5113ee566c40fa. --- lib/irb.rb | 7 ++----- lib/irb/context.rb | 9 ++------- test/irb/helper.rb | 4 +--- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/lib/irb.rb b/lib/irb.rb index 5a064cfce..45a59087b 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -311,9 +311,7 @@ # ### Input Method # # The IRB input method determines how command input is to be read; by default, -# the input method for a session is IRB::RelineInputMethod. Unless the -# value of the TERM environment variable is 'dumb', in which case the -# most simplistic input method is used. +# the input method for a session is IRB::RelineInputMethod. # # You can set the input method by: # @@ -331,8 +329,7 @@ # IRB::ReadlineInputMethod. # * `--nosingleline` or `--multiline` sets the input method to # IRB::RelineInputMethod. -# * `--nosingleline` together with `--nomultiline` sets the -# input to IRB::StdioInputMethod. +# # # # Method `conf.use_multiline?` and its synonym `conf.use_reline` return: diff --git a/lib/irb/context.rb b/lib/irb/context.rb index 173f3dae5..22e855f1e 100644 --- a/lib/irb/context.rb +++ b/lib/irb/context.rb @@ -85,7 +85,7 @@ def initialize(irb, workspace = nil, input_method = nil) @io = nil case use_multiline? when nil - if term_interactive? && IRB.conf[:PROMPT_MODE] != :INF_RUBY && !use_singleline? + if STDIN.tty? && IRB.conf[:PROMPT_MODE] != :INF_RUBY && !use_singleline? # Both of multiline mode and singleline mode aren't specified. @io = RelineInputMethod.new(build_completor) else @@ -99,7 +99,7 @@ def initialize(irb, workspace = nil, input_method = nil) unless @io case use_singleline? when nil - if (defined?(ReadlineInputMethod) && term_interactive? && + if (defined?(ReadlineInputMethod) && STDIN.tty? && IRB.conf[:PROMPT_MODE] != :INF_RUBY) @io = ReadlineInputMethod.new else @@ -151,11 +151,6 @@ def initialize(irb, workspace = nil, input_method = nil) @command_aliases = @user_aliases.merge(KEYWORD_ALIASES) end - private def term_interactive? - return true if ENV['TEST_IRB_FORCE_INTERACTIVE'] - STDIN.tty? && ENV['TERM'] != 'dumb' - end - # because all input will eventually be evaluated as Ruby code, # command names that conflict with Ruby keywords need special workaround # we can remove them once we implemented a better command system for IRB diff --git a/test/irb/helper.rb b/test/irb/helper.rb index acaf6277f..591bd05b7 100644 --- a/test/irb/helper.rb +++ b/test/irb/helper.rb @@ -121,9 +121,7 @@ def run_ruby_file(&block) @envs["XDG_CONFIG_HOME"] ||= tmp_dir @envs["IRBRC"] = nil unless @envs.key?("IRBRC") - envs_for_spawn = @envs.merge('TERM' => 'dumb', 'TEST_IRB_FORCE_INTERACTIVE' => 'true') - - PTY.spawn(envs_for_spawn, *cmd) do |read, write, pid| + PTY.spawn(@envs.merge("TERM" => "dumb"), *cmd) do |read, write, pid| Timeout.timeout(TIMEOUT_SEC) do while line = safe_gets(read) lines << line