Skip to content

Commit

Permalink
Implement doc display dialog in conjunction with autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed Aug 27, 2021
1 parent 063d9c7 commit e97bbc4
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion lib/reline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,39 @@ def get_screen_size
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
Expand Down

0 comments on commit e97bbc4

Please sign in to comment.