summaryrefslogtreecommitdiff
path: root/lib/reline.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2021-05-13 14:42:00 -0700
committeraycabta <aycabta@gmail.com>2021-06-21 17:58:48 +0900
commit242bad9a87dbfc8a6af829ee3da3853925be14ab (patch)
treeaa0f7e6aff0dd1d7772ada25f1efc4fdcfceadab /lib/reline.rb
parent26f31f880cef107d4c13dfe90a988c0f2e185338 (diff)
[ruby/reline] Fix Reline::Unicode.calculate_width when input is not a TTY
This fixes an error when output is redirected: ``` $ run_ruby -rreline -e '$stderr.puts Reline::Unicode.calculate_width("\u221a").inspect' </dev/null >/dev/null /home/jeremy/tmp/ruby/lib/reline/ansi.rb:189:in `raw': Operation not supported by device (Errno::ENODEV) ``` The @@encoding -> defined?(@@encoding) changes is necessary because without that part of the commit, the following error would be raised by the above command: ``` /home/jeremy/tmp/reline/lib/reline/general_io.rb:10:in `encoding': uninitialized class variable @@encoding in Reline::GeneralIO (NameError) ``` Problem reported and initial patch for Windows provided by Richard Sharman. I tested this only on OpenBSD, but hopefully it works for other operating systems. Fixes [Bug #17493] https://github.com/ruby/reline/commit/c001971bb3
Diffstat (limited to 'lib/reline.rb')
-rw-r--r--lib/reline.rb18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/reline.rb b/lib/reline.rb
index 6fc27caecd..26cf9119ee 100644
--- a/lib/reline.rb
+++ b/lib/reline.rb
@@ -453,17 +453,25 @@ module Reline
end
end
+require 'reline/general_io'
if RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
require 'reline/windows'
if Reline::Windows.msys_tty?
- require 'reline/ansi'
- Reline::IOGate = Reline::ANSI
+ Reline::IOGate = if ENV['TERM'] == 'dumb'
+ Reline::GeneralIO
+ else
+ require 'reline/ansi'
+ Reline::ANSI
+ end
else
Reline::IOGate = Reline::Windows
end
else
- require 'reline/ansi'
- Reline::IOGate = Reline::ANSI
+ Reline::IOGate = if $stdout.isatty
+ require 'reline/ansi'
+ Reline::ANSI
+ else
+ Reline::GeneralIO
+ end
end
Reline::HISTORY = Reline::History.new(Reline.core.config)
-require 'reline/general_io'