summaryrefslogtreecommitdiff
path: root/lib/reline
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
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')
-rw-r--r--lib/reline/general_io.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/reline/general_io.rb b/lib/reline/general_io.rb
index 4f605628a3..2f87d718c6 100644
--- a/lib/reline/general_io.rb
+++ b/lib/reline/general_io.rb
@@ -7,7 +7,7 @@ class Reline::GeneralIO
end
def self.encoding
- if @@encoding
+ if defined?(@@encoding)
@@encoding
elsif RUBY_PLATFORM =~ /mswin|mingw/
Encoding::UTF_8