Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --autocomplete / --noautocomplete options #270

Merged
merged 4 commits into from
Aug 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/irb/irb.rd.ja
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ irbの使い方は, Rubyさえ知っていればいたって簡単です. 基本
用しようとする.
--colorize 色付けを利用する.
--nocolorize 色付けを利用しない.
--autocomplete オートコンプリートを利用する.
--noautocomplete オートコンプリートを利用しない.
--prompt prompt-mode
--prompt-mode prompt-mode
プロンプトモードを切替えます. 現在定義されているプ
Expand Down
2 changes: 1 addition & 1 deletion irb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = Gem::Requirement.new(">= 2.5")

spec.add_dependency "reline", ">= 0.2.8.pre.1"
spec.add_dependency "reline", ">= 0.2.8.pre.3"
end
3 changes: 3 additions & 0 deletions lib/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
# --nosingleline Don't use singleline editor module
# --colorize Use colorization
# --nocolorize Don't use colorization
# --autocomplete Use autocompletion
# --noautocomplete Don't use autocompletion
# --prompt prompt-mode/--prompt-mode prompt-mode
# Switch prompt mode. Pre-defined prompt modes are
# `default', `simple', `xmp' and `inf-ruby'
Expand Down Expand Up @@ -114,6 +116,7 @@
# IRB.conf[:USE_SINGLELINE] = nil
# IRB.conf[:USE_COLORIZE] = true
# IRB.conf[:USE_TRACER] = false
# IRB.conf[:USE_AUTOCOMPLETE] = true
# IRB.conf[:IGNORE_SIGINT] = true
# IRB.conf[:IGNORE_EOF] = false
# IRB.conf[:PROMPT_MODE] = :DEFAULT
Expand Down
5 changes: 5 additions & 0 deletions lib/irb/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def initialize(irb, workspace = nil, input_method = nil)
@use_multiline = nil
end
@use_colorize = IRB.conf[:USE_COLORIZE]
@use_autocomplete = IRB.conf[:USE_AUTOCOMPLETE]
@verbose = IRB.conf[:VERBOSE]
@io = nil

Expand Down Expand Up @@ -185,6 +186,8 @@ def main
#
# A copy of the default <code>IRB.conf[:USE_COLORIZE]</code>
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>
attr_reader :inspect_mode

Expand Down Expand Up @@ -311,6 +314,8 @@ def main
alias use_readline? use_singleline
# Alias for #use_colorize
alias use_colorize? use_colorize
# Alias for #use_autocomplete
alias use_autocomplete? use_autocomplete
# Alias for #rc
alias rc? rc
alias ignore_sigint? ignore_sigint
Expand Down
5 changes: 5 additions & 0 deletions lib/irb/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def IRB.init_config(ap_path)

@CONF[:USE_SINGLELINE] = false unless defined?(ReadlineInputMethod)
@CONF[:USE_COLORIZE] = !ENV['NO_COLOR']
@CONF[:USE_AUTOCOMPLETE] = true
@CONF[:INSPECT_MODE] = true
@CONF[:USE_TRACER] = false
@CONF[:USE_LOADER] = false
Expand Down Expand Up @@ -274,6 +275,10 @@ def IRB.parse_opts(argv: ::ARGV)
@CONF[:USE_COLORIZE] = true
when "--nocolorize"
@CONF[:USE_COLORIZE] = false
when "--autocomplete"
@CONF[:USE_AUTOCOMPLETE] = true
when "--noautocomplete"
@CONF[:USE_AUTOCOMPLETE] = false
when /^--prompt-mode(?:=(.+))?/, /^--prompt(?:=(.+))?/
opt = $1 || argv.shift
prompt_mode = opt.upcase.tr("-", "_").intern
Expand Down
5 changes: 4 additions & 1 deletion lib/irb/input-method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ def initialize
end
end
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

def check_termination(&block)
Expand Down Expand Up @@ -361,7 +365,6 @@ def gets
Reline.output = @stdout
Reline.prompt_proc = @prompt_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)
HISTORY.push(l) if !l.empty?
@line[@line_no += 1] = l + "\n"
Expand Down
2 changes: 2 additions & 0 deletions lib/irb/lc/help-message
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Usage: irb.rb [options] [programfile] [arguments]
--nosingleline Don't use singleline editor module
--colorize Use colorization
--nocolorize Don't use colorization
--autocomplete Use autocompletion
--noautocomplete Don't use autocompletion
--prompt prompt-mode/--prompt-mode prompt-mode
Switch prompt mode. Pre-defined prompt modes are
`default', `simple', `xmp' and `inf-ruby'
Expand Down
2 changes: 2 additions & 0 deletions lib/irb/lc/ja/help-message
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Usage: irb.rb [options] [programfile] [arguments]
--nosingleline シングルラインエディタを利用しない.
--colorize 色付けを利用する.
--nocolorize 色付けを利用しない.
--autocomplete オートコンプリートを利用する.
--noautocomplete オートコンプリートを利用しない.
--prompt prompt-mode/--prompt-mode prompt-mode
プロンプトモードを切替えます. 現在定義されているプ
ロンプトモードは, default, simple, xmp, inf-rubyが
Expand Down
8 changes: 8 additions & 0 deletions man/irb.1
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
.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 autocomplete
.Op Fl - Ns Oo no Oc Ns verbose
.Op Fl -prompt Ar mode
.Op Fl -prompt-mode Ar mode
Expand Down Expand Up @@ -118,6 +119,13 @@ Use colorization.
Don't use colorization.
.Pp
.Pp
.It Fl -autocomplete
Use autocompletion.
.Pp
.It Fl -noautocomplete
Don't use autocompletion.
.Pp
.Pp
.It Fl -verbose
Show details.
.Pp
Expand Down
1 change: 1 addition & 0 deletions test/irb/test_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def test_eval_object_without_inspect_method

def test_default_config
assert_equal(true, @context.use_colorize?)
assert_equal(true, @context.use_autocomplete?)
end

def test_assignment_expression
Expand Down
6 changes: 3 additions & 3 deletions test/irb/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_launch
write_irbrc <<~'LINES'
puts 'start IRB'
LINES
start_terminal(25, 80, %W{ruby -I#{@pwd}/lib -I#{@pwd}/../reline/lib #{@pwd}/exe/irb}, startup_message: 'start IRB')
start_terminal(25, 80, %W{ruby -I#{@pwd}/lib #{@pwd}/exe/irb}, startup_message: 'start IRB')
write(<<~EOC)
'Hello, World!'
EOC
Expand All @@ -46,7 +46,7 @@ def test_multiline_paste
write_irbrc <<~'LINES'
puts 'start IRB'
LINES
start_terminal(25, 80, %W{ruby -I#{@pwd}/lib -I#{@pwd}/../reline/lib #{@pwd}/exe/irb}, startup_message: 'start IRB')
start_terminal(25, 80, %W{ruby -I#{@pwd}/lib #{@pwd}/exe/irb}, startup_message: 'start IRB')
write(<<~EOC)
class A
def inspect; '#<A>'; end
Expand Down Expand Up @@ -85,7 +85,7 @@ def test_evaluate_each_toplevel_statement_by_multiline_paste
write_irbrc <<~'LINES'
puts 'start IRB'
LINES
start_terminal(40, 80, %W{ruby -I#{@pwd}/lib -I#{@pwd}/../reline/lib #{@pwd}/exe/irb}, startup_message: 'start IRB')
start_terminal(40, 80, %W{ruby -I#{@pwd}/lib #{@pwd}/exe/irb}, startup_message: 'start IRB')
write(<<~EOC)
class A
def inspect; '#<A>'; end
Expand Down