Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cut off the excess on narrow screen #371

Merged
merged 3 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def add_dialog_proc(name, p, context = nil)
@dialogs << Dialog.new(name, @config, DialogProcScope.new(self, @config, p, context))
end

DIALOG_HEIGHT = 20
DIALOG_DEFAULT_HEIGHT = 20
private def render_dialog(cursor_column)
@dialogs.each do |dialog|
render_each_dialog(dialog, cursor_column)
Expand Down Expand Up @@ -662,7 +662,7 @@ def add_dialog_proc(name, p, context = nil)
else
dialog.width = dialog.contents.map { |l| calculate_width(l, true) }.max
end
height = dialog_render_info.height || DIALOG_HEIGHT
height = dialog_render_info.height || DIALOG_DEFAULT_HEIGHT
height = dialog.contents.size if dialog.contents.size < height
if dialog.contents.size > height
if dialog.pointer
Expand Down Expand Up @@ -709,6 +709,10 @@ def add_dialog_proc(name, p, context = nil)
end
Reline::IOGate.hide_cursor
dialog.width += @block_elem_width if dialog.scrollbar_pos
if dialog.column < 0
dialog.column = 0
dialog.width = @screen_size.last
end
reset_dialog(dialog, old_dialog)
move_cursor_down(dialog.vertical_offset)
Reline::IOGate.move_cursor_column(dialog.column)
Expand Down
42 changes: 42 additions & 0 deletions test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,48 @@ def test_dialog_callback_returns_nil
EOC
end

def test_dialog_narrower_than_screen
start_terminal(20, 11, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --dialog simple}, startup_message: 'Multiline REPL.')
close
assert_screen(<<~'EOC')
Multiline R
EPL.
prompt>
Ruby is...
A dynamic,
language wi
and product
syntax that
easy to wri
EOC
end

def test_dialog_narrower_than_screen_with_scrollbar
start_terminal(20, 11, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete-long}, startup_message: 'Multiline REPL.')
write('S' + "\C-i" * 3)
close
assert_screen(<<~'EOC')
Multiline R
EPL.
prompt> Sym
String
Struct █
Symbol █
StopIterat█
SystemCall█
SystemExit█
SystemStac█
ScriptErro█
SyntaxErro█
Signal █
SizedQueue█
Set
SecureRand
Socket
StringIO
EOC
end

def test_rerender_argument_prompt_after_pasting
start_terminal(20, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
write('abcdef')
Expand Down