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

ruby-changes:67319

From: aycabta <ko1@a...>
Date: Sun, 29 Aug 2021 20:30:56 +0900 (JST)
Subject: [ruby-changes:67319] 7e8a627052 (master): [ruby/reline] Implement doc display dialog in conjunction with autocomplete

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

From 7e8a6270525f4ea944e8b3b3c3014a48bdb5a734 Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Fri, 27 Aug 2021 21:35:42 +0900
Subject: [ruby/reline] Implement doc display dialog in conjunction with
 autocomplete

https://github.com/ruby/reline/commit/e97bbc4ccf
---
 lib/reline.rb | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/lib/reline.rb b/lib/reline.rb
index 842f6ba..ddc4a06 100644
--- a/lib/reline.rb
+++ b/lib/reline.rb
@@ -209,14 +209,39 @@ module Reline https://github.com/ruby/ruby/blob/trunk/lib/reline.rb#L209
         y = 0
       end
       cursor_pos_to_render = Reline::CursorPos.new(x, y)
+      context.clear
+      context.push(cursor_pos_to_render, result, pointer)
       [cursor_pos_to_render, result, pointer]
     }
 
+    require 'rdoc'
+    SHOW_DOC_DIALOG = ->() {
+      if just_cursor_moving and completion_journey_data.nil?
+        return nil
+      end
+      cursor_pos_to_render, result, pointer = context.pop(3)
+      return nil if result.nil? or pointer.nil?
+      name = result[pointer]
+      driver = RDoc::RI::Driver.new
+      doc = RDoc::Markup::Document.new
+      begin
+        driver.add_method(doc, name)
+      rescue RDoc::RI::Driver::NotFoundError => e
+        return nil
+      end
+      formatter = RDoc::Markup::ToBs.new
+      formatter.width = 40
+      str = doc.accept(formatter)
+      [Reline::CursorPos.new(cursor_pos_to_render.x + 40, cursor_pos_to_render.y + pointer), str.split("\n"), nil]
+    }
+
     def readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination)
       unless confirm_multiline_termination
         raise ArgumentError.new('#readmultiline needs block to confirm multiline termination')
       end
-      add_dialog_proc(:autocomplete, DEFAULT_DIALOG_PROC_AUTOCOMPLETE)
+      context = []
+      add_dialog_proc(:autocomplete, DEFAULT_DIALOG_PROC_AUTOCOMPLETE, context)
+      add_dialog_proc(:show_doc, SHOW_DOC_DIALOG, context)
       inner_readline(prompt, add_hist, true, &confirm_multiline_termination)
 
       whole_buffer = line_editor.whole_buffer.dup
-- 
cgit v1.1


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

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