From 242bad9a87dbfc8a6af829ee3da3853925be14ab Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Thu, 13 May 2021 14:42:00 -0700 Subject: [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 /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 --- lib/reline/general_io.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/reline') 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 -- cgit v1.2.3