aboutsummaryrefslogtreecommitdiffstats
path: root/lib/reline.rb
diff options
context:
space:
mode:
authorst0012 <stan001212@gmail.com>2022-06-28 14:39:56 +0100
committergit <svn-admin@ruby-lang.org>2022-07-16 02:30:23 +0900
commit36ca0e58b600f3338ad4880d77c8c7fbc8f51460 (patch)
tree31bc41b1c4b4526f10c72cec587d5e66a6d945da /lib/reline.rb
parent280b805d040fa537d5a459b40d4bfa6d49700905 (diff)
downloadruby-36ca0e58b600f3338ad4880d77c8c7fbc8f51460.tar.gz
[ruby/reline] Use color name instead of code (integer) in dialog color APIs
As pointed out in the [comment](https://github.com/ruby/reline/pull/413#issuecomment-1168033973), the code is actually a control sequence and not only for colors. To make the dialog color APIs safer to use, we should restrict its usages and extract away the bg/fg concept from the input. So in this commit, I made these changes: 1. The dialog_*_bg/fg_color APIs only takes and returns color names (symbol): - :black - :red - :green - :yellow - :blue - :magenta - :cyan - :white 2. Add additional dialog_*_bg/fg_color_sequence APIs to access the raw code. https://github.com/ruby/reline/commit/b32a977766
Diffstat (limited to 'lib/reline.rb')
-rw-r--r--lib/reline.rb45
1 files changed, 25 insertions, 20 deletions
diff --git a/lib/reline.rb b/lib/reline.rb
index 21e2dbf095..9de04a95b3 100644
--- a/lib/reline.rb
+++ b/lib/reline.rb
@@ -46,6 +46,21 @@ module Reline
keyword_init: true
)
+ DIALOG_COLOR_APIS = [
+ :dialog_default_bg_color,
+ :dialog_default_bg_color_sequence,
+ :dialog_default_bg_color=,
+ :dialog_default_fg_color,
+ :dialog_default_fg_color_sequence,
+ :dialog_default_fg_color=,
+ :dialog_pointer_bg_color,
+ :dialog_pointer_bg_color_sequence,
+ :dialog_pointer_bg_color=,
+ :dialog_pointer_fg_color,
+ :dialog_pointer_fg_color_sequence,
+ :dialog_pointer_fg_color=
+ ]
+
class Core
ATTR_READER_NAMES = %i(
completion_append_character
@@ -73,14 +88,7 @@ module Reline
def_delegators :config,
:autocompletion,
:autocompletion=,
- :dialog_default_bg_color,
- :dialog_default_bg_color=,
- :dialog_default_fg_color,
- :dialog_default_fg_color=,
- :dialog_pointer_bg_color,
- :dialog_pointer_bg_color=,
- :dialog_pointer_fg_color,
- :dialog_pointer_fg_color=
+ *DIALOG_COLOR_APIS
def initialize
self.output = STDOUT
@@ -264,10 +272,10 @@ module Reline
contents: result,
scrollbar: true,
height: 15,
- bg_color: config.dialog_default_bg_color,
- pointer_bg_color: config.dialog_pointer_bg_color,
- fg_color: config.dialog_default_fg_color,
- pointer_fg_color: config.dialog_pointer_fg_color
+ bg_color: config.dialog_default_bg_color_sequence,
+ pointer_bg_color: config.dialog_pointer_bg_color_sequence,
+ fg_color: config.dialog_default_fg_color_sequence,
+ pointer_fg_color: config.dialog_pointer_fg_color_sequence
)
}
Reline::DEFAULT_DIALOG_CONTEXT = Array.new
@@ -553,10 +561,7 @@ module Reline
def_single_delegators :core, :add_dialog_proc
def_single_delegators :core, :dialog_proc
def_single_delegators :core, :autocompletion, :autocompletion=
- def_single_delegators :core, :dialog_default_bg_color, :dialog_default_bg_color=
- def_single_delegators :core, :dialog_pointer_bg_color, :dialog_pointer_bg_color=
- def_single_delegators :core, :dialog_default_fg_color, :dialog_default_fg_color=
- def_single_delegators :core, :dialog_pointer_fg_color, :dialog_pointer_fg_color=
+ def_single_delegators :core, *DIALOG_COLOR_APIS
def_single_delegators :core, :readmultiline
def_instance_delegators self, :readmultiline
@@ -579,10 +584,10 @@ module Reline
core.filename_quote_characters = ""
core.special_prefixes = ""
core.add_dialog_proc(:autocomplete, Reline::DEFAULT_DIALOG_PROC_AUTOCOMPLETE, Reline::DEFAULT_DIALOG_CONTEXT)
- core.dialog_default_bg_color = 46 # Cyan
- core.dialog_default_fg_color = 37 # White
- core.dialog_pointer_bg_color = 45 # Magenta
- core.dialog_pointer_fg_color = 37 # White
+ core.dialog_default_bg_color = :cyan
+ core.dialog_default_fg_color = :white
+ core.dialog_pointer_bg_color = :magenta
+ core.dialog_pointer_fg_color = :white
}
end