Skip to content

Commit

Permalink
Merge pull request #300 from aycabta/display-doc-in-gaps-on-narrow-sc…
Browse files Browse the repository at this point in the history
…reen

Display doc in gaps on narrow screen
  • Loading branch information
aycabta committed Oct 8, 2021
2 parents 8b3b3ac + ac471ee commit 77c3b98
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
29 changes: 27 additions & 2 deletions lib/irb/input-method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,39 @@ def auto_indent(&block)
end
return nil if doc.nil?
width = 40

right_x = cursor_pos_to_render.x + autocomplete_dialog.width
if right_x + width > screen_width
right_width = screen_width - (right_x + 1)
left_x = autocomplete_dialog.column - width
left_x = 0 if left_x < 0
left_width = width > autocomplete_dialog.column ? autocomplete_dialog.column : width
if right_width.positive? and left_width.positive?
if right_width >= left_width
width = right_width
x = right_x
else
width = left_width
x = left_x
end
elsif right_width.positive? and left_width <= 0
width = right_width
x = right_x
elsif right_width <= 0 and left_width.positive?
width = left_width
x = left_x
else # Both are negative width.
return nil
end
else
x = right_x
end
formatter = RDoc::Markup::ToAnsi.new
formatter.width = width
dialog.trap_key = alt_d
message = 'Press Alt+d to read the full document'
contents = [message] + doc.accept(formatter).split("\n")

x = cursor_pos_to_render.x + autocomplete_dialog.width
x = autocomplete_dialog.column - width if x + width >= screen_width
y = cursor_pos_to_render.y
DialogRenderInfo.new(pos: Reline::CursorPos.new(x, y), contents: contents, width: width, bg_color: '49')
}
Expand Down
46 changes: 46 additions & 0 deletions test/irb/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,52 @@ def test_symbol_with_backtick
EOC
end

def test_autocomplete_with_showdoc_in_gaps_on_narrow_screen_right
pend "Needs a dummy document to show doc"
write_irbrc <<~'LINES'
IRB.conf[:PROMPT][:MY_PROMPT] = {
:PROMPT_I => "%03n> ",
:PROMPT_N => "%03n> ",
:PROMPT_S => "%03n> ",
:PROMPT_C => "%03n> "
}
IRB.conf[:PROMPT_MODE] = :MY_PROMPT
puts 'start IRB'
LINES
start_terminal(4, 19, %W{ruby -I/home/aycabta/ruby/reline/lib -I#{@pwd}/lib #{@pwd}/exe/irb}, startup_message: 'start IRB')
write("Str\C-i")
close
assert_screen(<<~EOC)
001> String
StringPress A
StructString
of byte
EOC
end

def test_autocomplete_with_showdoc_in_gaps_on_narrow_screen_left
pend "Needs a dummy document to show doc"
write_irbrc <<~'LINES'
IRB.conf[:PROMPT][:MY_PROMPT] = {
:PROMPT_I => "%03n> ",
:PROMPT_N => "%03n> ",
:PROMPT_S => "%03n> ",
:PROMPT_C => "%03n> "
}
IRB.conf[:PROMPT_MODE] = :MY_PROMPT
puts 'start IRB'
LINES
start_terminal(4, 12, %W{ruby -I#{@pwd}/lib #{@pwd}/exe/irb}, startup_message: 'start IRB')
write("Str\C-i")
close
assert_screen(<<~EOC)
001> String
PressString
StrinStruct
of by
EOC
end

private def write_irbrc(content)
File.open(@irbrc_file, 'w') do |f|
f.write content
Expand Down

0 comments on commit 77c3b98

Please sign in to comment.