diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-18 13:09:26 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-18 13:09:26 +0000 |
commit | 5c1bd53c92f888f45f6a843f2ef70f2fcdac077f (patch) | |
tree | 5e59d6e126eff13c9e661aa12f0b33f5db20b6c8 /lib/irb/init.rb | |
parent | 52d481d8de7ee3e0dfaef7322d540f95223bf41b (diff) |
* lib/irb/init.rb (IRB.opt_parse): (M17N) adds -U and -E as command
line options. [ruby-dev:37161]. Fixes #711.
improved long optinos.
* lib/irb/init.rb (IRB.set_encoding): new subroutine for IRB.opt_parse
* lib/irb/input-method.rb (IRB::StdioInputMethod): (M17N) regards
scripts that user types as encoded in the external_encoding.
* lib/irb/input-method.rb (IRB::ReadlineInputMethod): ditto.
* lib/irb/input-method.rb (IRB::FileInputMethod): (M17N) respects
magic comment.
* lib/irb/help.rb (IRB.print_usage): (M17N) respects magic comment
in the resource file.
* lib/irb/lc/help-message: adds -U and -E.
* lib/irb/lc/ja/help-message: ditto. re-encoded from ISO-2022-JP into UTF-8.
* lib/irb/lc/ja/encoding_aliases.rb: new file. provides Japanese specific
character encoding name table for backward compatibility.
* lib/irb/lc/ja/error.rb: re-eoncoded from ISO-2022-JP into UTF-8.
magic comment.
* lib/irb/locale.rb: integrated with Ruby 1.9's M17N support.
* lib/irb/magic-file.rb: new file. utility to handle files with magic
comment and opens in the correct encoding.
* lib/irb/ruby-lex.rb (RubyLex#each_top_level_statement): recovers
character encoding for a statement after it lexed so that irb can
eval the statement in correct encoding.
* lib/irb/src_encoding.rb: new file. utility.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/irb/init.rb')
-rw-r--r-- | lib/irb/init.rb | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/lib/irb/init.rb b/lib/irb/init.rb index 576b99d1c8..62c862a1c3 100644 --- a/lib/irb/init.rb +++ b/lib/irb/init.rb @@ -139,6 +139,11 @@ module IRB when /^-I(.+)?/ opt = $1 || ARGV.shift load_path.concat(opt.split(File::PATH_SEPARATOR)) if opt + when '-U' + set_encoding("UTF-8", "UTF-8") + when /^-E(.+)?/, /^--encoding(?:=(.+))?/ + opt = $1 || ARGV.shift + set_encoding(*opt.split(':', 2)) when "--inspect" @CONF[:INSPECT_MODE] = true when "--noinspect" @@ -155,8 +160,9 @@ module IRB @CONF[:VERBOSE] = true when "--noverbose" @CONF[:VERBOSE] = false - when "--prompt-mode", "--prompt" - prompt_mode = ARGV.shift.upcase.tr("-", "_").intern + when /^--prompt-mode(?:=(.+))?/, /^--prompt(?:=(.+))?/ + opt = $1 || ARGV.shift + prompt_mode = opt.upcase.tr("-", "_").intern @CONF[:PROMPT_MODE] = prompt_mode when "--noprompt" @CONF[:PROMPT_MODE] = :NULL @@ -166,14 +172,14 @@ module IRB @CONF[:PROMPT_MODE] = :SIMPLE when "--tracer" @CONF[:USE_TRACER] = true - when "--back-trace-limit" - @CONF[:BACK_TRACE_LIMIT] = ARGV.shift.to_i - when "--context-mode" - @CONF[:CONTEXT_MODE] = ARGV.shift.to_i + when /^--back-trace-limit(?:=(.+))?/ + @CONF[:BACK_TRACE_LIMIT] = ($1 || ARGV.shift).to_i + when /^--context-mode(?:=(.+))?/ + @CONF[:CONTEXT_MODE] = ($1 || ARGV.shift).to_i when "--single-irb" @CONF[:SINGLE_IRB] = true - when "--irb_debug" - @CONF[:DEBUG_LEVEL] = ARGV.shift.to_i + when /^--irb_debug=(?:=(.+))?/ + @CONF[:DEBUG_LEVEL] = ($1 || ARGV.shift).to_i when "-v", "--version" print IRB.version, "\n" exit 0 @@ -181,6 +187,12 @@ module IRB require "irb/help" IRB.print_usage exit 0 + when "--" + if opt = ARGV.shfit + @CONF[:SCRIPT] = opt + $0 = opt + end + break when /^-/ IRB.fail UnrecognizedSwitch, opt else @@ -195,6 +207,7 @@ module IRB end end $LOAD_PATH.unshift(*load_path) + end # running config @@ -253,4 +266,21 @@ module IRB end end + + DefaultEncodings = Struct.new(:external, :internal) + class << IRB + private + def set_encoding(extern, intern = nil) + verbose, $VERBOSE = $VERBOSE, nil + Encoding.default_external = extern unless extern.nil? || extern.empty? + Encoding.default_internal = intern unless intern.nil? || intern.empty? + @CONF[:ENCODINGS] = IRB::DefaultEncodings.new(extern, intern) + [$stdin, $stdout, $stderr].each do |io| + io.set_encoding(extern, intern) + end + @CONF[:LC_MESSAGES].instance_variable_set(:@encoding, extern) + ensure + $VERBOSE = verbose + end + end end |