1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Add --autocomplete / --noautocomplete options

This commit is contained in:
aycabta 2021-08-30 02:08:16 +09:00
parent b6b2b767ed
commit ece4ed0da7
9 changed files with 34 additions and 2 deletions

View file

@ -59,7 +59,10 @@ irbの使い方は, Rubyさえ知っていればいたって簡単です. 基本
用しようとする. 用しようとする.
--colorize 色付けを利用する. --colorize 色付けを利用する.
--nocolorize 色付けを利用しない. --nocolorize 色付けを利用しない.
--prompt prompt-mode/--prompt-mode prompt-mode --autocomplete オートコンプリートを利用する.
--noautocomplete オートコンプリートを利用しない.
--prompt prompt-mode
--prompt-mode prompt-mode
プロンプトモードを切替えます. 現在定義されているプ プロンプトモードを切替えます. 現在定義されているプ
ロンプトモードは, default, simple, xmp, inf-rubyが ロンプトモードは, default, simple, xmp, inf-rubyが
用意されています. 用意されています.

View file

@ -72,6 +72,8 @@ require_relative "irb/easter-egg"
# --nosingleline Don't use singleline editor module # --nosingleline Don't use singleline editor module
# --colorize Use colorization # --colorize Use colorization
# --nocolorize Don't use colorization # --nocolorize Don't use colorization
# --autocomplete Use autocompletion
# --noautocomplete Don't use autocompletion
# --prompt prompt-mode/--prompt-mode prompt-mode # --prompt prompt-mode/--prompt-mode prompt-mode
# Switch prompt mode. Pre-defined prompt modes are # Switch prompt mode. Pre-defined prompt modes are
# `default', `simple', `xmp' and `inf-ruby' # `default', `simple', `xmp' and `inf-ruby'
@ -114,6 +116,7 @@ require_relative "irb/easter-egg"
# IRB.conf[:USE_SINGLELINE] = nil # IRB.conf[:USE_SINGLELINE] = nil
# IRB.conf[:USE_COLORIZE] = true # IRB.conf[:USE_COLORIZE] = true
# IRB.conf[:USE_TRACER] = false # IRB.conf[:USE_TRACER] = false
# IRB.conf[:USE_AUTOCOMPLETE] = true
# IRB.conf[:IGNORE_SIGINT] = true # IRB.conf[:IGNORE_SIGINT] = true
# IRB.conf[:IGNORE_EOF] = false # IRB.conf[:IGNORE_EOF] = false
# IRB.conf[:PROMPT_MODE] = :DEFAULT # IRB.conf[:PROMPT_MODE] = :DEFAULT

View file

@ -54,6 +54,7 @@ module IRB
@use_multiline = nil @use_multiline = nil
end end
@use_colorize = IRB.conf[:USE_COLORIZE] @use_colorize = IRB.conf[:USE_COLORIZE]
@use_autocomplete = IRB.conf[:USE_AUTOCOMPLETE]
@verbose = IRB.conf[:VERBOSE] @verbose = IRB.conf[:VERBOSE]
@io = nil @io = nil
@ -185,6 +186,8 @@ module IRB
# #
# A copy of the default <code>IRB.conf[:USE_COLORIZE]</code> # A copy of the default <code>IRB.conf[:USE_COLORIZE]</code>
attr_reader :use_colorize attr_reader :use_colorize
# A copy of the default <code>IRB.conf[:USE_AUTOCOMPLETE]</code>
attr_reader :use_autocomplete
# A copy of the default <code>IRB.conf[:INSPECT_MODE]</code> # A copy of the default <code>IRB.conf[:INSPECT_MODE]</code>
attr_reader :inspect_mode attr_reader :inspect_mode
@ -311,6 +314,8 @@ module IRB
alias use_readline? use_singleline alias use_readline? use_singleline
# Alias for #use_colorize # Alias for #use_colorize
alias use_colorize? use_colorize alias use_colorize? use_colorize
# Alias for #use_autocomplete
alias use_autocomplete? use_autocomplete
# Alias for #rc # Alias for #rc
alias rc? rc alias rc? rc
alias ignore_sigint? ignore_sigint alias ignore_sigint? ignore_sigint

View file

@ -45,6 +45,7 @@ module IRB # :nodoc:
@CONF[:USE_SINGLELINE] = false unless defined?(ReadlineInputMethod) @CONF[:USE_SINGLELINE] = false unless defined?(ReadlineInputMethod)
@CONF[:USE_COLORIZE] = !ENV['NO_COLOR'] @CONF[:USE_COLORIZE] = !ENV['NO_COLOR']
@CONF[:USE_AUTOCOMPLETE] = true
@CONF[:INSPECT_MODE] = true @CONF[:INSPECT_MODE] = true
@CONF[:USE_TRACER] = false @CONF[:USE_TRACER] = false
@CONF[:USE_LOADER] = false @CONF[:USE_LOADER] = false
@ -274,6 +275,10 @@ module IRB # :nodoc:
@CONF[:USE_COLORIZE] = true @CONF[:USE_COLORIZE] = true
when "--nocolorize" when "--nocolorize"
@CONF[:USE_COLORIZE] = false @CONF[:USE_COLORIZE] = false
when "--autocomplete"
@CONF[:USE_AUTOCOMPLETE] = true
when "--noautocomplete"
@CONF[:USE_AUTOCOMPLETE] = false
when /^--prompt-mode(?:=(.+))?/, /^--prompt(?:=(.+))?/ when /^--prompt-mode(?:=(.+))?/, /^--prompt(?:=(.+))?/
opt = $1 || argv.shift opt = $1 || argv.shift
prompt_mode = opt.upcase.tr("-", "_").intern prompt_mode = opt.upcase.tr("-", "_").intern

View file

@ -295,6 +295,10 @@ module IRB
end end
end end
Reline.dig_perfect_match_proc = IRB::InputCompletor::PerfectMatchedProc Reline.dig_perfect_match_proc = IRB::InputCompletor::PerfectMatchedProc
Reline.autocompletion = IRB.conf[:USE_AUTOCOMPLETE]
if IRB.conf[:USE_AUTOCOMPLETE]
Reline.add_dialog_proc(:show_doc, SHOW_DOC_DIALOG, Reline::DEFAULT_DIALOG_CONTEXT)
end
end end
def check_termination(&block) def check_termination(&block)
@ -361,7 +365,6 @@ module IRB
Reline.output = @stdout Reline.output = @stdout
Reline.prompt_proc = @prompt_proc Reline.prompt_proc = @prompt_proc
Reline.auto_indent_proc = @auto_indent_proc if @auto_indent_proc Reline.auto_indent_proc = @auto_indent_proc if @auto_indent_proc
Reline.add_dialog_proc(:show_doc, SHOW_DOC_DIALOG, Reline::DEFAULT_DIALOG_CONTEXT)
if l = readmultiline(@prompt, false, &@check_termination_proc) if l = readmultiline(@prompt, false, &@check_termination_proc)
HISTORY.push(l) if !l.empty? HISTORY.push(l) if !l.empty?
@line[@line_no += 1] = l + "\n" @line[@line_no += 1] = l + "\n"

View file

@ -30,6 +30,8 @@ Usage: irb.rb [options] [programfile] [arguments]
--nosingleline Don't use singleline editor module --nosingleline Don't use singleline editor module
--colorize Use colorization --colorize Use colorization
--nocolorize Don't use colorization --nocolorize Don't use colorization
--autocomplete Use autocompletion
--noautocomplete Don't use autocompletion
--prompt prompt-mode/--prompt-mode prompt-mode --prompt prompt-mode/--prompt-mode prompt-mode
Switch prompt mode. Pre-defined prompt modes are Switch prompt mode. Pre-defined prompt modes are
`default', `simple', `xmp' and `inf-ruby' `default', `simple', `xmp' and `inf-ruby'

View file

@ -29,6 +29,8 @@ Usage: irb.rb [options] [programfile] [arguments]
--nosingleline シングルラインエディタを利用しない. --nosingleline シングルラインエディタを利用しない.
--colorize 色付けを利用する. --colorize 色付けを利用する.
--nocolorize 色付けを利用しない. --nocolorize 色付けを利用しない.
--autocomplete オートコンプリートを利用する.
--noautocomplete オートコンプリートを利用しない.
--prompt prompt-mode/--prompt-mode prompt-mode --prompt prompt-mode/--prompt-mode prompt-mode
プロンプトモードを切替えます. 現在定義されているプ プロンプトモードを切替えます. 現在定義されているプ
ロンプトモードは, default, simple, xmp, inf-rubyが ロンプトモードは, default, simple, xmp, inf-rubyが

View file

@ -18,6 +18,7 @@
.Op Fl - Ns Oo no Oc Ns singleline .Op Fl - Ns Oo no Oc Ns singleline
.Op Fl - Ns Oo no Oc Ns echo .Op Fl - Ns Oo no Oc Ns echo
.Op Fl - Ns Oo no Oc Ns colorize .Op Fl - Ns Oo no Oc Ns colorize
.Op Fl - Ns Oo no Oc Ns autocomplete
.Op Fl - Ns Oo no Oc Ns verbose .Op Fl - Ns Oo no Oc Ns verbose
.Op Fl -prompt Ar mode .Op Fl -prompt Ar mode
.Op Fl -prompt-mode Ar mode .Op Fl -prompt-mode Ar mode
@ -118,6 +119,13 @@ Use colorization.
Don't use colorization. Don't use colorization.
.Pp .Pp
.Pp .Pp
.It Fl -autocomplete
Use autocompletion.
.Pp
.It Fl -noautocomplete
Don't use autocompletion.
.Pp
.Pp
.It Fl -verbose .It Fl -verbose
Show details. Show details.
.Pp .Pp

View file

@ -159,6 +159,7 @@ module TestIRB
def test_default_config def test_default_config
assert_equal(true, @context.use_colorize?) assert_equal(true, @context.use_colorize?)
assert_equal(true, @context.use_autocomplete?)
end end
def test_assignment_expression def test_assignment_expression