diff options
author | HASUMI Hitoshi <hasumikin@gmail.com> | 2023-11-06 23:40:38 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-11-06 14:40:42 +0000 |
commit | 16403f41abcbaccf32484d10575d3542dbb3247e (patch) | |
tree | afca50d51bcb5bcb432dc35581fa7f251ea02dc0 /lib/reline/line_editor.rb | |
parent | f6ba87ca8899cd753306ffbca475b16c367995a3 (diff) | |
download | ruby-16403f41abcbaccf32484d10575d3542dbb3247e.tar.gz |
[ruby/reline] Introduce a new class Reline::Face to configure
character attributes
(https://github.com/ruby/reline/pull/552)
* Reine::Face
* fix test_yamatanooroti
* Define singleton methods to make accessors to attributes of a face
* s/display/foreground/
* s/default/default_style/ && s/normal_line/default/ && s/enhanced_line/enhanced/
* fix typo
* FaceConfig.new now takes keyword arguments
* Update lib/reline/face.rb
Co-authored-by: Stan Lo <stan001212@gmail.com>
* Update test/reline/test_face.rb
Co-authored-by: Stan Lo <stan001212@gmail.com>
* Fix to correspond to frozen_string_literal
* Face::FaceConfig -> Face::Config
* ref https://github.com/ruby/reline/pull/552#pullrequestreview-1677282576
* delete unused ivar
* ref https://github.com/ruby/reline/pull/552#discussion_r1358783723
* insert "\e[0m" into all SGR
* tiny fix
* ESSENTIAL_DEFINE_NAMES
ref https://github.com/ruby/reline/pull/552#discussion_r1367722247
* Change to Hash-accessor style
- Reline::Face[:completion_dialog].enhanced ->
Reline::Face[:completion_dialog][:enhanced]
- Reline::Face.configs shows all defined values
* Cache array method call in local variable
* Tests for Face configuration variations
* resolve https://github.com/ruby/reline/pull/552#pullrequestreview-1710938154
* amend to
* check invalid SGR parameter in :style
* The order of define values should be preserved
* Update test/reline/test_face.rb
Co-authored-by: Stan Lo <stan001212@gmail.com>
* Update test/reline/test_face.rb
Co-authored-by: Stan Lo <stan001212@gmail.com>
* Add methods: load_initial_config and reset_to_initial_config. And teardown in tests
* omission in amending "style: :default" to "style: :reset"
* refs https://github.com/ruby/reline/issues/598
* Fix link
* amend method name
* Update lib/reline/face.rb
Co-authored-by: ima1zumi <52617472+ima1zumi@users.noreply.github.com>
---------
https://github.com/ruby/reline/commit/fdc1d3b1e5
Co-authored-by: Stan Lo <stan001212@gmail.com>
Co-authored-by: ima1zumi <52617472+ima1zumi@users.noreply.github.com>
Diffstat (limited to 'lib/reline/line_editor.rb')
-rw-r--r-- | lib/reline/line_editor.rb | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 0d990c2c0a..d71b903701 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -831,27 +831,24 @@ class Reline::LineEditor dialog.column = 0 dialog.width = @screen_size.last end + face = Reline::Face[dialog_render_info.face || :default] + scrollbar_sgr = face[:scrollbar] + default_sgr = face[:default] + enhanced_sgr = face[:enhanced] dialog.contents = contents.map.with_index do |item, i| - if i == pointer - fg_color = dialog_render_info.pointer_fg_color - bg_color = dialog_render_info.pointer_bg_color - else - fg_color = dialog_render_info.fg_color - bg_color = dialog_render_info.bg_color - end + line_sgr = i == pointer ? enhanced_sgr : default_sgr 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) - colored_content = "\e[#{bg_color}m\e[#{fg_color}m#{str}" + colored_content = "#{line_sgr}#{str}" if scrollbar_pos - color_seq = "\e[37m" if scrollbar_pos <= (i * 2) and (i * 2 + 1) < (scrollbar_pos + bar_height) - colored_content + color_seq + @full_block + colored_content + scrollbar_sgr + @full_block elsif scrollbar_pos <= (i * 2) and (i * 2) < (scrollbar_pos + bar_height) - colored_content + color_seq + @upper_half_block + colored_content + scrollbar_sgr + @upper_half_block elsif scrollbar_pos <= (i * 2 + 1) and (i * 2) < (scrollbar_pos + bar_height) - colored_content + color_seq + @lower_half_block + colored_content + scrollbar_sgr + @lower_half_block else - colored_content + color_seq + ' ' * @block_elem_width + colored_content + scrollbar_sgr + ' ' * @block_elem_width end else colored_content |