mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Use Reline.encoding_system_needs if exists
This commit is contained in:
parent
a2638c0d87
commit
8c3efa4940
4 changed files with 20 additions and 7 deletions
|
@ -72,7 +72,7 @@ module IRB
|
||||||
end
|
end
|
||||||
history_file = IRB.rc_file("_history") unless history_file
|
history_file = IRB.rc_file("_history") unless history_file
|
||||||
if File.exist?(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|
|
f.each { |l|
|
||||||
l = l.chomp
|
l = l.chomp
|
||||||
if self.class == ReidlineInputMethod and history.last&.end_with?("\\")
|
if self.class == ReidlineInputMethod and history.last&.end_with?("\\")
|
||||||
|
@ -107,7 +107,7 @@ module IRB
|
||||||
raise
|
raise
|
||||||
end
|
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") }
|
hist = history.map{ |l| l.split("\n").join("\\\n") }
|
||||||
f.puts(hist[-num..-1] || hist)
|
f.puts(hist[-num..-1] || hist)
|
||||||
end
|
end
|
||||||
|
|
|
@ -296,14 +296,18 @@ module IRB # :nodoc:
|
||||||
DefaultEncodings = Struct.new(:external, :internal)
|
DefaultEncodings = Struct.new(:external, :internal)
|
||||||
class << IRB
|
class << IRB
|
||||||
private
|
private
|
||||||
def set_encoding(extern, intern = nil)
|
def set_encoding(extern, intern = nil, override: true)
|
||||||
verbose, $VERBOSE = $VERBOSE, nil
|
verbose, $VERBOSE = $VERBOSE, nil
|
||||||
Encoding.default_external = extern unless extern.nil? || extern.empty?
|
Encoding.default_external = extern unless extern.nil? || extern.empty?
|
||||||
Encoding.default_internal = intern unless intern.nil? || intern.empty?
|
Encoding.default_internal = intern unless intern.nil? || intern.empty?
|
||||||
[$stdin, $stdout, $stderr].each do |io|
|
[$stdin, $stdout, $stderr].each do |io|
|
||||||
io.set_encoding(extern, intern)
|
io.set_encoding(extern, intern)
|
||||||
end
|
end
|
||||||
|
if override
|
||||||
|
@CONF[:LC_MESSAGES].instance_variable_set(:@override_encoding, extern)
|
||||||
|
else
|
||||||
@CONF[:LC_MESSAGES].instance_variable_set(:@encoding, extern)
|
@CONF[:LC_MESSAGES].instance_variable_set(:@encoding, extern)
|
||||||
|
end
|
||||||
ensure
|
ensure
|
||||||
$VERBOSE = verbose
|
$VERBOSE = verbose
|
||||||
end
|
end
|
||||||
|
|
|
@ -133,6 +133,9 @@ module IRB
|
||||||
include Readline
|
include Readline
|
||||||
# Creates a new input method object using Readline
|
# Creates a new input method object using Readline
|
||||||
def initialize
|
def initialize
|
||||||
|
if Readline.respond_to?(:encoding_system_needs)
|
||||||
|
IRB.__send__(:set_encoding, Readline.encoding_system_needs.name, override: false)
|
||||||
|
end
|
||||||
super
|
super
|
||||||
|
|
||||||
@line_no = 0
|
@line_no = 0
|
||||||
|
@ -207,6 +210,7 @@ module IRB
|
||||||
include Reline
|
include Reline
|
||||||
# Creates a new input method object using Readline
|
# Creates a new input method object using Readline
|
||||||
def initialize
|
def initialize
|
||||||
|
IRB.__send__(:set_encoding, Reline.encoding_system_needs.name, override: false)
|
||||||
super
|
super
|
||||||
|
|
||||||
@line_no = 0
|
@line_no = 0
|
||||||
|
|
|
@ -24,6 +24,7 @@ module IRB # :nodoc:
|
||||||
@@loaded = []
|
@@loaded = []
|
||||||
|
|
||||||
def initialize(locale = nil)
|
def initialize(locale = nil)
|
||||||
|
@override_encoding = nil
|
||||||
@lang = @territory = @encoding_name = @modifier = nil
|
@lang = @territory = @encoding_name = @modifier = nil
|
||||||
@locale = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C"
|
@locale = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C"
|
||||||
if m = LOCALE_NAME_RE.match(@locale)
|
if m = LOCALE_NAME_RE.match(@locale)
|
||||||
|
@ -40,12 +41,16 @@ module IRB # :nodoc:
|
||||||
@encoding ||= (Encoding.find('locale') rescue Encoding::ASCII_8BIT)
|
@encoding ||= (Encoding.find('locale') rescue Encoding::ASCII_8BIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :lang, :territory, :encoding, :modifier
|
attr_reader :lang, :territory, :modifier
|
||||||
|
|
||||||
|
def encoding
|
||||||
|
@override_encoding || @encoding
|
||||||
|
end
|
||||||
|
|
||||||
def String(mes)
|
def String(mes)
|
||||||
mes = super(mes)
|
mes = super(mes)
|
||||||
if @encoding
|
if encoding
|
||||||
mes.encode(@encoding, undef: :replace)
|
mes.encode(encoding, undef: :replace)
|
||||||
else
|
else
|
||||||
mes
|
mes
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue