[前][次][番号順一覧][スレッド一覧]

ruby-changes:67681

From: aycabta <ko1@a...>
Date: Fri, 10 Sep 2021 09:05:00 +0900 (JST)
Subject: [ruby-changes:67681] c25511ef46 (master): [ruby/reline] Add a test for dialog with scroll key

https://git.ruby-lang.org/ruby.git/commit/?id=c25511ef46

From c25511ef46c047e970e45e363288e8c005284c31 Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Fri, 10 Sep 2021 04:58:35 +0900
Subject: [ruby/reline] Add a test for dialog with scroll key

https://github.com/ruby/reline/commit/99640abf75
---
 test/reline/yamatanooroti/multiline_repl    | 51 ++++++++++++++++++++++-------
 test/reline/yamatanooroti/test_rendering.rb | 17 +++++++++-
 2 files changed, 56 insertions(+), 12 deletions(-)

diff --git a/test/reline/yamatanooroti/multiline_repl b/test/reline/yamatanooroti/multiline_repl
index f3a1097..1346a83 100755
--- a/test/reline/yamatanooroti/multiline_repl
+++ b/test/reline/yamatanooroti/multiline_repl
@@ -30,18 +30,47 @@ opt.on('--dynamic-prompt-returns-empty') { https://github.com/ruby/ruby/blob/trunk/test/reline/yamatanooroti/multiline_repl#L30
 opt.on('--auto-indent') {
   AutoIndent.new
 }
-opt.on('--simple-dialog') {
+opt.on('--dialog VAL') { |v|
   Reline.add_dialog_proc(:simple_dialog, lambda {
-    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
-    Reline::DialogRenderInfo.new(pos: cursor_pos, contents: contents)
-  })
+    if v.include?('simple')
+      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
+    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') {
   Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|
diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb
index cd401e2..278850a 100644
--- a/test/reline/yamatanooroti/test_rendering.rb
+++ b/test/reline/yamatanooroti/test_rendering.rb
@@ -836,7 +836,7 @@ begin https://github.com/ruby/ruby/blob/trunk/test/reline/yamatanooroti/test_rendering.rb#L836
     end
 
     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('b')
       write('c')
@@ -854,6 +854,21 @@ begin https://github.com/ruby/ruby/blob/trunk/test/reline/yamatanooroti/test_rendering.rb#L854
       EOC
     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
       start_terminal(20, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete}, startup_message: 'Multiline REPL.')
       write("Stri")
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]