diff options
author | TOMITA Masahiro <tommy@tmtm.org> | 2021-09-26 15:39:45 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2021-10-03 14:26:53 +0900 |
commit | ef350b3a5645a97270cbc72356eba671a1a41c20 (patch) | |
tree | a3c3d7ad0374e112e3a202688227a2b6ed7e07e8 /lib/reline/line_editor.rb | |
parent | 2a3d0fbe172d52be9a64e0bd366c5f74177bd881 (diff) | |
download | ruby-ef350b3a5645a97270cbc72356eba671a1a41c20.tar.gz |
[ruby/reline] Simplify SIGWINCH handler to avoid aborting when resizing.
https://github.com/ruby/reline/commit/481add0537
Diffstat (limited to 'lib/reline/line_editor.rb')
-rw-r--r-- | lib/reline/line_editor.rb | 75 |
1 files changed, 41 insertions, 34 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index f041233df4..afb0b49f1c 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -178,43 +178,49 @@ class Reline::LineEditor rescue ArgumentError end Reline::IOGate.set_winch_handler do - @rest_height = (Reline::IOGate.get_screen_size.first - 1) - Reline::IOGate.cursor_pos.y - old_screen_size = @screen_size - @screen_size = Reline::IOGate.get_screen_size - @screen_height = @screen_size.first - if old_screen_size.last < @screen_size.last # columns increase - @rerender_all = true - rerender - else - back = 0 - new_buffer = whole_lines - prompt, prompt_width, prompt_list = check_multiline_prompt(new_buffer, prompt) - new_buffer.each_with_index do |line, index| - prompt_width = calculate_width(prompt_list[index], true) if @prompt_proc - width = prompt_width + calculate_width(line) - height = calculate_height_by_width(width) - back += height - end - @highest_in_all = back - @highest_in_this = calculate_height_by_width(prompt_width + @cursor_max) - @first_line_started_from = - if @line_index.zero? - 0 - else - calculate_height_by_lines(@buffer_of_lines[0..(@line_index - 1)], prompt_list || prompt) - end - if @prompt_proc - prompt = prompt_list[@line_index] - prompt_width = calculate_width(prompt, true) + @resized = true + end + @block_elem_width = Reline::Unicode.calculate_width('█') + end + + def resize + return unless @resized + @resized = false + @rest_height = (Reline::IOGate.get_screen_size.first - 1) - Reline::IOGate.cursor_pos.y + old_screen_size = @screen_size + @screen_size = Reline::IOGate.get_screen_size + @screen_height = @screen_size.first + if old_screen_size.last < @screen_size.last # columns increase + @rerender_all = true + rerender + else + back = 0 + new_buffer = whole_lines + prompt, prompt_width, prompt_list = check_multiline_prompt(new_buffer, prompt) + new_buffer.each_with_index do |line, index| + prompt_width = calculate_width(prompt_list[index], true) if @prompt_proc + width = prompt_width + calculate_width(line) + height = calculate_height_by_width(width) + back += height + end + @highest_in_all = back + @highest_in_this = calculate_height_by_width(prompt_width + @cursor_max) + @first_line_started_from = + if @line_index.zero? + 0 + else + calculate_height_by_lines(@buffer_of_lines[0..(@line_index - 1)], prompt_list || prompt) end - calculate_nearest_cursor - @started_from = calculate_height_by_width(prompt_width + @cursor) - 1 - Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last) - @highest_in_this = calculate_height_by_width(prompt_width + @cursor_max) - @rerender_all = true + if @prompt_proc + prompt = prompt_list[@line_index] + prompt_width = calculate_width(prompt, true) end + calculate_nearest_cursor + @started_from = calculate_height_by_width(prompt_width + @cursor) - 1 + Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last) + @highest_in_this = calculate_height_by_width(prompt_width + @cursor_max) + @rerender_all = true end - @block_elem_width = Reline::Unicode.calculate_width('█') end def finalize @@ -264,6 +270,7 @@ class Reline::LineEditor @auto_indent_proc = nil @dialogs = [] @last_key = nil + @resized = false reset_line end |