Skip to content

Commit

Permalink
Use singleline/multiline instead of readline/reidline
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed Oct 30, 2019
1 parent 5f1fadc commit ae47a91
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 76 deletions.
34 changes: 21 additions & 13 deletions doc/irb/irb.rd.ja
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ irbの使い方は, Rubyさえ知っていればいたって簡単です. 基本
--noecho 実行結果を表示しない
--inspect 結果出力にinspectを用いる(bcモード以外はデフォルト).
--noinspect 結果出力にinspectを用いない.
--readline readlineライブラリを利用する.
--noreadline readlineライブラリを利用しない. デフォルトの動作は,
inf-ruby-mode以外でreadlineライブラリを利用しよう
とする.
--singleline シングルラインエディタを利用する.
--nosingleline シングルラインエディタを利用しない. デフォルトの動
作は, inf-ruby-mode以外でシングルラインエディタを利
用しようとする.
--colorize 色付けを利用する.
--nocolorize 色付けを利用しない.
--prompt prompt-mode
Expand All @@ -64,7 +64,7 @@ irbの使い方は, Rubyさえ知っていればいたって簡単です. 基本
ドになっています.

--inf-ruby-mode emacsのinf-ruby-mode用のプロンプト表示を行なう. 特
に指定がない限り, readlineライブラリは使わなくなる.
に指定がない限り, ラインエディタは使わなくなる.
--simple-prompt
非常にシンプルなプロンプトを用いるモードです.
--noprompt プロンプト表示を行なわない.
Expand All @@ -91,7 +91,7 @@ irb起動時に``~/.irbrc''を読み込みます. もし存在しない場合は
IRB.conf[:IRB_RC] = nil
IRB.conf[:BACK_TRACE_LIMIT]=16
IRB.conf[:USE_LOADER] = false
IRB.conf[:USE_READLINE] = nil
IRB.conf[:USE_SINGLELINE] = nil
IRB.conf[:USE_TRACER] = false
IRB.conf[:IGNORE_SIGINT] = true
IRB.conf[:IGNORE_EOF] = false
Expand Down Expand Up @@ -193,7 +193,8 @@ irb拡張コマンドは, 簡単な名前と頭に`irb_'をつけた名前と両
実行中: 実行を中止する.

--- conf.inf_ruby_mode = true/false
inf-ruby-mode用のプロンプト表示を行なう. デフォルトはfalse.
inf-ruby-mode用のプロンプト表示を行なう. デフォルトはfalse. 特に指定
がない限り, ラインエディタは使わなくなる.

--- conf.inspect_mode = true/false/nil
インスペクトモードを設定する.
Expand Down Expand Up @@ -221,12 +222,19 @@ irb拡張コマンドは, 簡単な名前と頭に`irb_'をつけた名前と両
--- conf.use_prompt = true/false
プロンプト表示するかどうか? デフォルトではプロンプトを表示する.

--- conf.use_readline = true/false/nil
readlineを使うかどうか?
true: readlineを使う.
false: readlineを使わない.
nil: (デフォルト)inf-ruby-mode以外でreadlineライブラリを利用しよ
うとする.
--- conf.use_multiline = true/false/nil
マルチラインエディタを使うかどうか?
true: マルチラインエディタを使う.
false: マルチラインエディタを使わない.
nil: (デフォルト)inf-ruby-mode以外でマルチラインエディタを利用しよう
とする.

--- conf.use_singleline = true/false/nil
シングルラインエディタを使うかどうか?
true: シングルラインエディタを使う.
false: シングルラインエディタを使わない.
nil: (デフォルト)inf-ruby-modeとマルチラインエディタ以外でシングルラ
インエディタを利用しようとする.
#
#--- conf.verbose=T/F
# irbからいろいろなメッセージを出力するか?
Expand Down
18 changes: 9 additions & 9 deletions lib/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
# irb(main):006:1> end
# #=> nil
#
# The Readline extension module can be used with irb. Use of Readline is
# default if it's installed.
# The singleline editor module or multiline editor module can be used with irb.
# Use of multiline editor is default if it's installed.
#
# == Command line options
#
Expand All @@ -61,18 +61,18 @@
# -W[level=2] Same as `ruby -W`
# --inspect Use `inspect' for output (default except for bc mode)
# --noinspect Don't use inspect for output
# --reidline Use Reidline extension module
# --noreidline Don't use Reidline extension module
# --readline Use Readline extension module
# --noreadline Don't use Readline extension module
# --multiline Use multiline editor module
# --nomultiline Don't use multiline editor module
# --singleline Use singleline editor module
# --nosingleline Don't use singleline editor 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'
# --inf-ruby-mode Use prompt appropriate for inf-ruby-mode on emacs.
# Suppresses --reidline and --readline.
# Suppresses --multiline and --singleline.
# --simple-prompt Simple prompt mode
# --noprompt No prompt mode
# --tracer Display trace for each execution of commands.
Expand Down Expand Up @@ -100,8 +100,8 @@
# IRB.conf[:IRB_RC] = nil
# IRB.conf[:BACK_TRACE_LIMIT]=16
# IRB.conf[:USE_LOADER] = false
# IRB.conf[:USE_REIDLINE] = nil
# IRB.conf[:USE_READLINE] = nil
# IRB.conf[:USE_MULTILINE] = nil
# IRB.conf[:USE_SINGLELINE] = nil
# IRB.conf[:USE_COLORIZE] = true
# IRB.conf[:USE_TRACER] = false
# IRB.conf[:IGNORE_SIGINT] = true
Expand Down
65 changes: 35 additions & 30 deletions lib/irb/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,20 @@ def initialize(irb, workspace = nil, input_method = nil, output_method = nil)
@rc = IRB.conf[:RC]
@load_modules = IRB.conf[:LOAD_MODULES]

@use_readline = IRB.conf[:USE_READLINE]
@use_reidline = IRB.conf[:USE_REIDLINE]
if IRB.conf.has_key?(:USE_SINGLELINE)
@use_singleline = IRB.conf[:USE_SINGLELINE]
elsif IRB.conf.has_key?(:USE_READLINE) # backward compatibility
@use_singleline = IRB.conf[:USE_READLINE]
else
@use_singleline = nil
end
if IRB.conf.has_key?(:USE_MULTILINE)
@use_multiline = IRB.conf[:USE_MULTILINE]
elsif IRB.conf.has_key?(:USE_REIDLINE) # backward compatibility
@use_multiline = IRB.conf[:USE_REIDLINE]
else
@use_multiline = nil
end
@use_colorize = IRB.conf[:USE_COLORIZE]
@verbose = IRB.conf[:VERBOSE]
@io = nil
Expand All @@ -67,9 +79,9 @@ def initialize(irb, workspace = nil, input_method = nil, output_method = nil)
case input_method
when nil
@io = nil
case use_reidline?
case use_multiline?
when nil
if STDIN.tty? && IRB.conf[:PROMPT_MODE] != :INF_RUBY && !use_readline?
if STDIN.tty? && IRB.conf[:PROMPT_MODE] != :INF_RUBY && !use_singleline?
@io = ReidlineInputMethod.new
else
@io = nil
Expand All @@ -80,7 +92,7 @@ def initialize(irb, workspace = nil, input_method = nil, output_method = nil)
@io = ReidlineInputMethod.new
end
unless @io
case use_readline?
case use_singleline?
when nil
if (defined?(ReadlineInputMethod) && STDIN.tty? &&
IRB.conf[:PROMPT_MODE] != :INF_RUBY)
Expand Down Expand Up @@ -161,18 +173,14 @@ def main
# +input_method+ passed to Context.new
attr_accessor :irb_path

# Whether +Reidline+ is enabled or not.
#
# A copy of the default <code>IRB.conf[:USE_REIDLINE]</code>
#
# See #use_reidline= for more information.
attr_reader :use_reidline
# Whether +Readline+ is enabled or not.
# Whether multiline editor mode is enabled or not.
#
# A copy of the default <code>IRB.conf[:USE_READLINE]</code>
# A copy of the default <code>IRB.conf[:USE_MULTILINE]</code>
attr_reader :use_multiline
# Whether singleline editor mode is enabled or not.
#
# See #use_readline= for more information.
attr_reader :use_readline
# A copy of the default <code>IRB.conf[:USE_SINGLELINE]</code>
attr_reader :use_singleline
# Whether colorization is enabled or not.
#
# A copy of the default <code>IRB.conf[:USE_COLORIZE]</code>
Expand Down Expand Up @@ -264,10 +272,18 @@ def main
# See IRB@Command+line+options for more command line options.
attr_accessor :back_trace_limit

# Alias for #use_reidline
alias use_reidline? use_reidline
# Alias for #use_readline
alias use_readline? use_readline
# Alias for #use_multiline
alias use_multiline? use_multiline
# Alias for #use_singleline
alias use_singleline? use_singleline
# backward compatibility
alias use_reidline use_multiline
# backward compatibility
alias use_reidline? use_multiline
# backward compatibility
alias use_readline use_singleline
# backward compatibility
alias use_readline? use_singleline
# Alias for #use_colorize
alias use_colorize? use_colorize
# Alias for #rc
Expand Down Expand Up @@ -398,17 +414,6 @@ def inspect_mode=(opt)
@inspect_mode
end

# Obsolete method.
#
# Can be set using the +--noreadline+ and +--readline+ command line
# options.
#
# See IRB@Command+line+options for more command line options.
def use_readline=(opt)
print "This method is obsolete."
print "Do nothing."
end

def evaluate(line, line_no, exception: nil) # :nodoc:
@line_no = line_no
if exception
Expand Down
18 changes: 9 additions & 9 deletions lib/irb/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def IRB.init_config(ap_path)
@CONF[:LOAD_MODULES] = []
@CONF[:IRB_RC] = nil

@CONF[:USE_READLINE] = false unless defined?(ReadlineInputMethod)
@CONF[:USE_SINGLELINE] = false unless defined?(ReadlineInputMethod)
@CONF[:USE_COLORIZE] = true
@CONF[:INSPECT_MODE] = true
@CONF[:USE_TRACER] = false
Expand Down Expand Up @@ -161,14 +161,14 @@ def IRB.parse_opts(argv: ::ARGV)
end
when "--noinspect"
@CONF[:INSPECT_MODE] = false
when "--readline"
@CONF[:USE_READLINE] = true
when "--noreadline"
@CONF[:USE_READLINE] = false
when "--reidline"
@CONF[:USE_REIDLINE] = true
when "--noreidline"
@CONF[:USE_REIDLINE] = false
when "--singleline", "--readline"
@CONF[:USE_SINGLELINE] = true
when "--nosingleline", "--noreadline"
@CONF[:USE_SINGLELINE] = false
when "--multiline", "--reidline"
@CONF[:USE_MULTILINE] = true
when "--nomultiline", "--noreidline"
@CONF[:USE_MULTILINE] = false
when "--echo"
@CONF[:ECHO] = true
when "--noecho"
Expand Down
12 changes: 7 additions & 5 deletions lib/irb/lc/help-message
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ Usage: irb.rb [options] [programfile] [arguments]
when new workspace was created
--echo Show result(default)
--noecho Don't show result
--inspect Use `inspect' for output
--noinspect Don't use inspect for output
--readline Use Readline extension module
--noreadline Don't use Readline extension module
--inspect Use `inspect' for output
--noinspect Don't use inspect for output
--multiline Use multiline editor module
--nomultiline Don't use multiline editor module
--singleline Use singleline editor module
--nosingleline Don't use singleline editor 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'
--inf-ruby-mode Use prompt appropriate for inf-ruby-mode on emacs.
Suppresses --readline.
Suppresses --multiline and --singleline.
--sample-book-mode/--simple-prompt
Simple prompt mode
--noprompt No prompt mode
Expand Down
9 changes: 6 additions & 3 deletions lib/irb/lc/ja/help-message
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ Usage: irb.rb [options] [programfile] [arguments]
--noecho 実行結果を表示しない.
--inspect 結果出力にinspectを用いる.
--noinspect 結果出力にinspectを用いない.
--readline readlineライブラリを利用する.
--noreadline readlineライブラリを利用しない.
--multiline マルチラインエディタを利用する.
--nomultiline マルチラインエディタを利用しない.
--singleline シングルラインエディタを利用する.
--nosingleline シングルラインエディタを利用しない.
--colorize 色付けを利用する.
--nocolorize 色付けを利用しない.
--prompt prompt-mode/--prompt-mode prompt-mode
プロンプトモードを切替えます. 現在定義されているプ
ロンプトモードは, default, simple, xmp, inf-rubyが
用意されています.
--inf-ruby-mode emacsのinf-ruby-mode用のプロンプト表示を行なう. 特
に指定がない限り, readlineライブラリは使わなくなる.
に指定がない限り, シングルラインエディタとマルチラ
インエディタは使わなくなる.
--sample-book-mode/--simple-prompt
非常にシンプルなプロンプトを用いるモードです.
--noprompt プロンプト表示を行なわない.
Expand Down
19 changes: 13 additions & 6 deletions man/irb.1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
.Op Fl E Ar external Ns Op : Ns Ar internal
.Op Fl W Ns Op Ar level
.Op Fl - Ns Oo no Oc Ns inspect
.Op Fl - Ns Oo no Oc Ns readline
.Op Fl - Ns Oo no Oc Ns multiline
.Op Fl - Ns Oo no Oc Ns singleline
.Op Fl - Ns Oo no Oc Ns echo
.Op Fl - Ns Oo no Oc Ns colorize
.Op Fl - Ns Oo no Oc Ns verbose
Expand Down Expand Up @@ -90,11 +91,17 @@ Uses `inspect' for output (default except for bc mode)
.It Fl -noinspect
Doesn't use inspect for output
.Pp
.It Fl -readline
Uses Readline extension module.
.It Fl -multiline
Uses multiline editor module.
.Pp
.It Fl -noreadline
Doesn't use Readline extension module.
.It Fl -nomultiline
Doesn't use multiline editor module.
.Pp
.It Fl -singleline
Uses singleline editor module.
.Pp
.It Fl -nosingleline
Doesn't use singleline editor module.
.Pp
.Pp
.It Fl -echo
Expand Down Expand Up @@ -124,7 +131,7 @@ Switch prompt mode. Pre-defined prompt modes are
.Pp
.It Fl -inf-ruby-mode
Uses prompt appropriate for inf-ruby-mode on emacs.
Suppresses --readline.
Suppresses --multiline and --singleline.
.Pp
.It Fl -simple-prompt
Makes prompts simple.
Expand Down
2 changes: 1 addition & 1 deletion test/irb/test_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def reset

def setup
IRB.init_config(nil)
IRB.conf[:USE_READLINE] = false
IRB.conf[:USE_SINGLELINE] = false
IRB.conf[:VERBOSE] = false
workspace = IRB::WorkSpace.new(Object.new)
@context = IRB::Context.new(nil, workspace, TestInputMethod.new)
Expand Down

0 comments on commit ae47a91

Please sign in to comment.