ruby-changes:59698
From: aycabta <ko1@a...>
Date: Tue, 14 Jan 2020 15:45:12 +0900 (JST)
Subject: [ruby-changes:59698] 8c3efa4940 (master): Use Reline.encoding_system_needs if exists
https://git.ruby-lang.org/ruby.git/commit/?id=8c3efa4940 From 8c3efa494091e6e0001f4a708fb7568c242387b9 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Tue, 14 Jan 2020 15:40:03 +0900 Subject: Use Reline.encoding_system_needs if exists diff --git a/lib/irb/ext/save-history.rb b/lib/irb/ext/save-history.rb index c0d4d37..edc4f23 100644 --- a/lib/irb/ext/save-history.rb +++ b/lib/irb/ext/save-history.rb @@ -72,7 +72,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/ext/save-history.rb#L72 end history_file = IRB.rc_file("_history") unless history_file if File.exist?(history_file) - open(history_file) do |f| + open(history_file, "r:#{IRB.conf[:LC_MESSAGES].encoding}") do |f| f.each { |l| l = l.chomp if self.class == ReidlineInputMethod and history.last&.end_with?("\\") @@ -107,7 +107,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/ext/save-history.rb#L107 raise end - open(history_file, 'w', 0600 ) do |f| + open(history_file, "w:#{IRB.conf[:LC_MESSAGES].encoding}", 0600) do |f| hist = history.map{ |l| l.split("\n").join("\\\n") } f.puts(hist[-num..-1] || hist) end diff --git a/lib/irb/init.rb b/lib/irb/init.rb index 11f940d..37d1f8d 100644 --- a/lib/irb/init.rb +++ b/lib/irb/init.rb @@ -296,14 +296,18 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/init.rb#L296 DefaultEncodings = Struct.new(:external, :internal) class << IRB private - def set_encoding(extern, intern = nil) + def set_encoding(extern, intern = nil, override: true) verbose, $VERBOSE = $VERBOSE, nil Encoding.default_external = extern unless extern.nil? || extern.empty? Encoding.default_internal = intern unless intern.nil? || intern.empty? [$stdin, $stdout, $stderr].each do |io| io.set_encoding(extern, intern) end - @CONF[:LC_MESSAGES].instance_variable_set(:@encoding, extern) + if override + @CONF[:LC_MESSAGES].instance_variable_set(:@override_encoding, extern) + else + @CONF[:LC_MESSAGES].instance_variable_set(:@encoding, extern) + end ensure $VERBOSE = verbose end diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb index a1777d7..9fbbaeb 100644 --- a/lib/irb/input-method.rb +++ b/lib/irb/input-method.rb @@ -133,6 +133,9 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/input-method.rb#L133 include Readline # Creates a new input method object using Readline def initialize + if Readline.respond_to?(:encoding_system_needs) + IRB.__send__(:set_encoding, Readline.encoding_system_needs.name, override: false) + end super @line_no = 0 @@ -207,6 +210,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/input-method.rb#L210 include Reline # Creates a new input method object using Readline def initialize + IRB.__send__(:set_encoding, Reline.encoding_system_needs.name, override: false) super @line_no = 0 diff --git a/lib/irb/locale.rb b/lib/irb/locale.rb index ba833ec..bb44b41 100644 --- a/lib/irb/locale.rb +++ b/lib/irb/locale.rb @@ -24,6 +24,7 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/locale.rb#L24 @@loaded = [] def initialize(locale = nil) + @override_encoding = nil @lang = @territory = @encoding_name = @modifier = nil @locale = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C" if m = LOCALE_NAME_RE.match(@locale) @@ -40,12 +41,16 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/locale.rb#L41 @encoding ||= (Encoding.find('locale') rescue Encoding::ASCII_8BIT) end - attr_reader :lang, :territory, :encoding, :modifier + attr_reader :lang, :territory, :modifier + + def encoding + @override_encoding || @encoding + end def String(mes) mes = super(mes) - if @encoding - mes.encode(@encoding, undef: :replace) + if encoding + mes.encode(encoding, undef: :replace) else mes end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/