diff options
author | Stan Lo <[email protected]> | 2023-03-29 14:51:22 +0100 |
---|---|---|
committer | git <[email protected]> | 2023-03-29 13:51:27 +0000 |
commit | b168141c7888a5237249b13d630f2a56a66f53f9 (patch) | |
tree | 78612f6c152ba82d447720b28877eb50383d7b4d /lib/reline/line_editor.rb | |
parent | 02ecdf85c5896e8da9abe4765147e995396377a5 (diff) |
[ruby/reline] Drop Dialog#scrollbar_pos as we can store it in a
local variable
(https://github.com/ruby/reline/pull/529)
https://github.com/ruby/reline/commit/d0139975fd
Co-authored-by: tomoya ishida <[email protected]>
Diffstat (limited to 'lib/reline/line_editor.rb')
-rw-r--r-- | lib/reline/line_editor.rb | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index cd6b1cd408..6e34c28b53 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -586,7 +586,7 @@ class Reline::LineEditor class Dialog attr_reader :name, :contents, :width - attr_accessor :scroll_top, :scrollbar_pos, :pointer, :column, :vertical_offset, :lines_backup, :trap_key + attr_accessor :scroll_top, :pointer, :column, :vertical_offset, :lines_backup, :trap_key def initialize(name, config, proc_scope) @name = name @@ -709,13 +709,13 @@ class Reline::LineEditor position_ratio = dialog.scroll_top.zero? ? 0.0 : ((dialog.scroll_top * 2).to_f / moving_distance) bar_height = (bar_max_height * ((dialog.contents.size * 2).to_f / (dialog_render_info.contents.size * 2))).floor.to_i bar_height = MINIMUM_SCROLLBAR_HEIGHT if bar_height < MINIMUM_SCROLLBAR_HEIGHT - dialog.scrollbar_pos = ((bar_max_height - bar_height) * position_ratio).floor.to_i + scrollbar_pos = ((bar_max_height - bar_height) * position_ratio).floor.to_i else - dialog.scrollbar_pos = nil + scrollbar_pos = nil end upper_space = @first_line_started_from - @started_from dialog.column = dialog_render_info.pos.x - dialog.width += @block_elem_width if dialog.scrollbar_pos + dialog.width += @block_elem_width if scrollbar_pos diff = (dialog.column + dialog.width) - (@screen_size.last) if diff > 0 dialog.column -= diff @@ -747,16 +747,16 @@ class Reline::LineEditor fg_color = dialog_render_info.fg_color bg_color = dialog_render_info.bg_color end - str_width = dialog.width - (dialog.scrollbar_pos.nil? ? 0 : @block_elem_width) + str_width = dialog.width - (scrollbar_pos.nil? ? 0 : @block_elem_width) str = padding_space_with_escape_sequences(Reline::Unicode.take_range(item, 0, str_width), str_width) @output.write "\e[#{bg_color}m\e[#{fg_color}m#{str}" - if dialog.scrollbar_pos + if scrollbar_pos @output.write "\e[37m" - if dialog.scrollbar_pos <= (i * 2) and (i * 2 + 1) < (dialog.scrollbar_pos + bar_height) + if scrollbar_pos <= (i * 2) and (i * 2 + 1) < (scrollbar_pos + bar_height) @output.write @full_block - elsif dialog.scrollbar_pos <= (i * 2) and (i * 2) < (dialog.scrollbar_pos + bar_height) + elsif scrollbar_pos <= (i * 2) and (i * 2) < (scrollbar_pos + bar_height) @output.write @upper_half_block - elsif dialog.scrollbar_pos <= (i * 2 + 1) and (i * 2) < (dialog.scrollbar_pos + bar_height) + elsif scrollbar_pos <= (i * 2 + 1) and (i * 2) < (scrollbar_pos + bar_height) @output.write @lower_half_block else @output.write ' ' * @block_elem_width |