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

[ruby/reline] Add a test for dialog with scroll key

99640abf75
This commit is contained in:
aycabta 2021-09-10 04:58:35 +09:00 committed by git
parent c94735fa24
commit c25511ef46
2 changed files with 56 additions and 12 deletions

View file

@ -30,8 +30,9 @@ opt.on('--dynamic-prompt-returns-empty') {
opt.on('--auto-indent') { opt.on('--auto-indent') {
AutoIndent.new AutoIndent.new
} }
opt.on('--simple-dialog') { opt.on('--dialog VAL') { |v|
Reline.add_dialog_proc(:simple_dialog, lambda { Reline.add_dialog_proc(:simple_dialog, lambda {
if v.include?('simple')
contents = <<~RUBY.split("\n") contents = <<~RUBY.split("\n")
Ruby is... Ruby is...
A dynamic, open source programming A dynamic, open source programming
@ -40,8 +41,36 @@ opt.on('--simple-dialog') {
syntax that is natural to read and syntax that is natural to read and
easy to write. easy to write.
RUBY RUBY
Reline::DialogRenderInfo.new(pos: cursor_pos, contents: contents) elsif v.include?('long')
}) contents = <<~RUBY.split("\n")
Ruby is...
A dynamic, open
source programming
language with a
focus on simplicity
and productivity.
It has an elegant
syntax that is
natural to read
and easy to write.
RUBY
end
if v.include?('scrollkey')
dialog.trap_key = nil
if key and key.match?(dialog.name)
if context.pointer.nil?
context.pointer = 0
elsif context.first > dialog.contents.size
context.pointer = 0
else
context.pointer += 1
end
end
dialog.trap_key = [?j.ord]
height = 4
end
Reline::DialogRenderInfo.new(pos: cursor_pos, contents: contents, height: height, pointer: context.pointer)
}, Struct.new(:pointer).new)
} }
opt.on('--complete') { opt.on('--complete') {
Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil| Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|

View file

@ -836,7 +836,7 @@ begin
end end
def test_simple_dialog def test_simple_dialog
start_terminal(20, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --simple-dialog}, startup_message: 'Multiline REPL.') start_terminal(20, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --dialog simple}, startup_message: 'Multiline REPL.')
write('a') write('a')
write('b') write('b')
write('c') write('c')
@ -854,6 +854,21 @@ begin
EOC EOC
end end
def test_simple_dialog_with_scroll_key
start_terminal(20, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --dialog long,scrollkey}, startup_message: 'Multiline REPL.')
write('a')
5.times{ write('j') }
close
assert_screen(<<~'EOC')
Multiline REPL.
prompt> a
A dynamic, open
source programming
language with a
focus on simplicity
EOC
end
def test_autocomplete def test_autocomplete
start_terminal(20, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete}, startup_message: 'Multiline REPL.') start_terminal(20, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete}, startup_message: 'Multiline REPL.')
write("Stri") write("Stri")