mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Add --colorize and --nocolorize options to IRB
This commit is contained in:
parent
df6a673ca5
commit
3a9008b984
8 changed files with 28 additions and 4 deletions
|
@ -54,6 +54,8 @@ irbの使い方は, Rubyさえ知っていればいたって簡単です. 基本
|
|||
--noreadline readlineライブラリを利用しない. デフォルトの動作は,
|
||||
inf-ruby-mode以外でreadlineライブラリを利用しよう
|
||||
とする.
|
||||
--colorize 色付けを利用する.
|
||||
--nocolorize 色付けを利用しない.
|
||||
--prompt prompt-mode
|
||||
--prompt-mode prompt-mode
|
||||
プロンプトモードを切替えます. 現在定義されているプ
|
||||
|
|
|
@ -62,6 +62,8 @@ require "irb/version"
|
|||
# --noinspect Don't use inspect for output
|
||||
# --readline Use Readline extension module
|
||||
# --noreadline Don't use Readline extension module
|
||||
# --colorize Use colorization
|
||||
# --nocolorize Don't use colorization
|
||||
# --prompt prompt-mode
|
||||
# --prompt-mode prompt-mode
|
||||
# Switch prompt mode. Pre-defined prompt modes are
|
||||
|
@ -96,6 +98,7 @@ require "irb/version"
|
|||
# IRB.conf[:BACK_TRACE_LIMIT]=16
|
||||
# IRB.conf[:USE_LOADER] = false
|
||||
# IRB.conf[:USE_READLINE] = nil
|
||||
# IRB.conf[:USE_COLORIZE] = true
|
||||
# IRB.conf[:USE_TRACER] = false
|
||||
# IRB.conf[:IGNORE_SIGINT] = true
|
||||
# IRB.conf[:IGNORE_EOF] = false
|
||||
|
|
|
@ -142,6 +142,10 @@ module IRB
|
|||
#
|
||||
# See #use_readline= for more information.
|
||||
attr_reader :use_readline
|
||||
# Whether colorization is enabled or not.
|
||||
#
|
||||
# A copy of the default <code>IRB.conf[:USE_COLORIZE]</code>
|
||||
attr_reader :use_colorize
|
||||
# A copy of the default <code>IRB.conf[:INSPECT_MODE]</code>
|
||||
attr_reader :inspect_mode
|
||||
|
||||
|
@ -222,6 +226,8 @@ module IRB
|
|||
|
||||
# Alias for #use_readline
|
||||
alias use_readline? use_readline
|
||||
# Alias for #use_colorize
|
||||
alias use_colorize? use_colorize
|
||||
# Alias for #rc
|
||||
alias rc? rc
|
||||
alias ignore_sigint? ignore_sigint
|
||||
|
|
|
@ -44,6 +44,7 @@ module IRB # :nodoc:
|
|||
@CONF[:IRB_RC] = nil
|
||||
|
||||
@CONF[:USE_READLINE] = false unless defined?(ReadlineInputMethod)
|
||||
@CONF[:USE_COLORIZE] = true
|
||||
@CONF[:INSPECT_MODE] = true
|
||||
@CONF[:USE_TRACER] = false
|
||||
@CONF[:USE_LOADER] = false
|
||||
|
@ -171,6 +172,10 @@ module IRB # :nodoc:
|
|||
@CONF[:VERBOSE] = true
|
||||
when "--noverbose"
|
||||
@CONF[:VERBOSE] = false
|
||||
when "--colorize"
|
||||
@CONF[:USE_COLORIZE] = true
|
||||
when "--nocolorize"
|
||||
@CONF[:USE_COLORIZE] = false
|
||||
when /^--prompt-mode(?:=(.+))?/, /^--prompt(?:=(.+))?/
|
||||
opt = $1 || argv.shift
|
||||
prompt_mode = opt.upcase.tr("-", "_").intern
|
||||
|
|
|
@ -107,7 +107,7 @@ module IRB # :nodoc:
|
|||
Inspector.def_inspector([true, :p, :inspect]){|v|
|
||||
begin
|
||||
result = v.inspect
|
||||
if Color.inspect_colorable?(v)
|
||||
if IRB.conf[:MAIN_CONTEXT]&.use_colorize? && Color.inspect_colorable?(v)
|
||||
result = Color.colorize_code(result)
|
||||
end
|
||||
result
|
||||
|
@ -117,7 +117,7 @@ module IRB # :nodoc:
|
|||
}
|
||||
Inspector.def_inspector([:pp, :pretty_inspect], proc{require "pp"}){|v|
|
||||
result = v.pretty_inspect.chomp
|
||||
if Color.inspect_colorable?(v)
|
||||
if IRB.conf[:MAIN_CONTEXT]&.use_colorize? && Color.inspect_colorable?(v)
|
||||
result = Color.colorize_code(result)
|
||||
end
|
||||
result
|
||||
|
|
|
@ -26,6 +26,8 @@ Usage: irb.rb [options] [programfile] [arguments]
|
|||
--noinspect Don't use inspect for output
|
||||
--readline Use Readline extension module
|
||||
--noreadline Don't use Readline extension module
|
||||
--colorize Use colorization
|
||||
--nocolorize Don't use colorization
|
||||
--prompt prompt-mode/--prompt-mode prompt-mode
|
||||
Switch prompt mode. Pre-defined prompt modes are
|
||||
`default', `simple', `xmp' and `inf-ruby'
|
||||
|
|
|
@ -25,6 +25,8 @@ Usage: irb.rb [options] [programfile] [arguments]
|
|||
--noinspect 結果出力にinspectを用いない.
|
||||
--readline readlineライブラリを利用する.
|
||||
--noreadline readlineライブラリを利用しない.
|
||||
--colorize 色付けを利用する.
|
||||
--nocolorize 色付けを利用しない.
|
||||
--prompt prompt-mode/--prompt-mode prompt-mode
|
||||
プロンプトモードを切替えます. 現在定義されているプ
|
||||
ロンプトモードは, default, simple, xmp, inf-rubyが
|
||||
|
|
|
@ -131,13 +131,17 @@ EOF
|
|||
return
|
||||
end
|
||||
end
|
||||
lines = Color.colorize_code(code).lines
|
||||
lines = IRB.conf[:MAIN_CONTEXT]&.use_colorize? ? Color.colorize_code(code).lines : code.lines
|
||||
pos -= 1
|
||||
|
||||
start_pos = [pos - 5, 0].max
|
||||
end_pos = [pos + 5, lines.size - 1].min
|
||||
|
||||
fmt = " %2s #{Color.colorize("%#{end_pos.to_s.length}d", [:BLUE, :BOLD])}: %s"
|
||||
if IRB.conf[:MAIN_CONTEXT]&.use_colorize?
|
||||
fmt = " %2s #{Color.colorize("%#{end_pos.to_s.length}d", [:BLUE, :BOLD])}: %s"
|
||||
else
|
||||
fmt = " %2s %#{end_pos.to_s.length}d: %s"
|
||||
end
|
||||
body = (start_pos..end_pos).map do |current_pos|
|
||||
sprintf(fmt, pos == current_pos ? '=>' : '', current_pos + 1, lines[current_pos])
|
||||
end.join("")
|
||||
|
|
Loading…
Reference in a new issue