summaryrefslogtreecommitdiff
path: root/lib/reline
diff options
context:
space:
mode:
authorpocari <caffelattenonsugar@gmail.com>2022-06-27 22:28:34 +0900
committergit <svn-admin@ruby-lang.org>2022-06-27 22:28:49 +0900
commit8c6c3e30f3a86ba0b697a0d99efe8ff4585c4a42 (patch)
tree2073fde89b3c57858cb5909b2e036bebd18ca5ea /lib/reline
parentb6b9a6190def53aa53ac816a51034fa1c96ed70b (diff)
[ruby/reline] Enable to change the background color of dialogs. (https://github.com/ruby/reline/pull/413)
https://github.com/ruby/reline/commit/bd49537964
Diffstat (limited to 'lib/reline')
-rw-r--r--lib/reline/config.rb28
-rw-r--r--lib/reline/line_editor.rb12
2 files changed, 25 insertions, 15 deletions
diff --git a/lib/reline/config.rb b/lib/reline/config.rb
index 1bb12a2506..b1cb7645ea 100644
--- a/lib/reline/config.rb
+++ b/lib/reline/config.rb
@@ -45,6 +45,14 @@ class Reline::Config
attr_accessor v
end
+ attr_accessor(
+ :autocompletion,
+ :dialog_default_bg_color,
+ :dialog_default_fg_color,
+ :dialog_pointer_bg_color,
+ :dialog_pointer_fg_color,
+ )
+
def initialize
@additional_key_bindings = {} # from inputrc
@additional_key_bindings[:emacs] = {}
@@ -69,6 +77,10 @@ class Reline::Config
@test_mode = false
@autocompletion = false
@convert_meta = true if seven_bit_encoding?(Reline::IOGate.encoding)
+ @dialog_default_bg_color = nil
+ @dialog_pointer_bg_color = nil
+ @dialog_default_fg_color = nil
+ @dialog_pointer_fg_color = nil
end
def reset
@@ -94,14 +106,6 @@ class Reline::Config
(val.respond_to?(:any?) ? val : [val]).any?(@editing_mode_label)
end
- def autocompletion=(val)
- @autocompletion = val
- end
-
- def autocompletion
- @autocompletion
- end
-
def keymap
@key_actors[@keymap_label]
end
@@ -334,6 +338,14 @@ class Reline::Config
@vi_ins_mode_string = retrieve_string(value)
when 'emacs-mode-string'
@emacs_mode_string = retrieve_string(value)
+ when 'dialog-default-bg-color'
+ @dialog_default_bg_color = value.to_i
+ when 'dialog-pointer-bg-color'
+ @dialog_pointer_bg_color = value.to_i
+ when 'dialog-default-fg-color'
+ @dialog_default_fg_color = value.to_i
+ when 'dialog-pointer-fg-color'
+ @dialog_pointer_fg_color = value.to_i
when *VARIABLE_NAMES then
variable_name = :"@#{name.tr(?-, ?_)}"
instance_variable_set(variable_name, value.nil? || value == '1' || value == 'on')
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 135432a5d1..8d0719ef7c 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -743,17 +743,15 @@ class Reline::LineEditor
Reline::IOGate.move_cursor_column(dialog.column)
dialog.contents.each_with_index do |item, i|
if i == pointer
- bg_color = '45'
+ fg_color = dialog_render_info.pointer_fg_color
+ bg_color = dialog_render_info.pointer_bg_color
else
- if dialog_render_info.bg_color
- bg_color = dialog_render_info.bg_color
- else
- bg_color = '46'
- end
+ 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 = padding_space_with_escape_sequences(Reline::Unicode.take_range(item, 0, str_width), str_width)
- @output.write "\e[#{bg_color}m#{str}"
+ @output.write "\e[#{bg_color}m\e[#{fg_color}m#{str}"
if dialog.scrollbar_pos and (dialog.scrollbar_pos != old_dialog.scrollbar_pos or dialog.column != old_dialog.column)
@output.write "\e[37m"
if dialog.scrollbar_pos <= (i * 2) and (i * 2 + 1) < (dialog.scrollbar_pos + bar_height)