зеркало из https://github.com/github/ruby.git
Use Reline.encoding_system_needs if exists
This commit is contained in:
Родитель
a2638c0d87
Коммит
8c3efa4940
|
@ -72,7 +72,7 @@ module IRB
|
|||
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
|
|||
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
|
||||
|
|
|
@ -296,14 +296,18 @@ module IRB # :nodoc:
|
|||
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
|
||||
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
|
||||
|
|
|
@ -133,6 +133,9 @@ module IRB
|
|||
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
|
|||
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
|
||||
|
|
|
@ -24,6 +24,7 @@ module IRB # :nodoc:
|
|||
@@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:
|
|||
@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
|
||||
|
|
Загрузка…
Ссылка в новой задаче