From 090e0be90193699a0dfd3b149a3b1ff6aee906d2 Mon Sep 17 00:00:00 2001 From: st0012 Date: Sat, 23 Jul 2022 12:26:42 +0100 Subject: [PATCH 1/2] REMOVE ME: use master reline for development --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 6f6d5419c..5ea5f838b 100644 --- a/Gemfile +++ b/Gemfile @@ -10,5 +10,5 @@ group :development do gem "rake" gem "stackprof" if is_unix && !is_truffleruby gem "test-unit" - gem "reline", github: "ruby/reline" if ENV["WITH_LATEST_RELINE"] == "true" + gem "reline", github: "ruby/reline" end From 81a358341b4da7f251581b1a554e85586946b09c Mon Sep 17 00:00:00 2001 From: st0012 Date: Sat, 23 Jul 2022 12:30:34 +0100 Subject: [PATCH 2/2] Support setting dialog theme and colors --- lib/irb/context.rb | 46 ++++++++++++++++++++++++++++++++++++++++++++++ lib/irb/init.rb | 1 + 2 files changed, 47 insertions(+) diff --git a/lib/irb/context.rb b/lib/irb/context.rb index b74cae122..ae8e6ae16 100644 --- a/lib/irb/context.rb +++ b/lib/irb/context.rb @@ -144,6 +144,36 @@ def initialize(irb, workspace = nil, input_method = nil) if @newline_before_multiline_output.nil? @newline_before_multiline_output = true end + + if @io.is_a?(ReidlineInputMethod) && Reline.respond_to?(:dialog_default_bg_color) + configure_dialog_colors + end + end + + def configure_dialog_colors + @use_bright_theme = IRB.conf[:USE_BRIGHT_THEME] + + if @use_bright_theme + @dialog_default_bg_color = :white + @dialog_default_fg_color = :black + @dialog_highlight_bg_color = :black + @dialog_highlight_fg_color = :white + else + @dialog_default_bg_color = :black + @dialog_default_fg_color = :white + @dialog_highlight_bg_color = :white + @dialog_highlight_fg_color = :black + end + + @dialog_default_bg_color = IRB.conf[:DIALOG_DEFAULT_BG_COLOR] if IRB.conf[:DIALOG_DEFAULT_BG_COLOR] + @dialog_default_fg_color = IRB.conf[:DIALOG_DEFAULT_FG_COLOR] if IRB.conf[:DIALOG_DEFAULT_FG_COLOR] + @dialog_highlight_bg_color = IRB.conf[:DIALOG_HIGHLIGHT_BG_COLOR] if IRB.conf[:DIALOG_HIGHLIGHT_BG_COLOR] + @dialog_highlight_bg_color = IRB.conf[:DIALOG_HIGHLIGHT_FG_COLOR] if IRB.conf[:DIALOG_HIGHLIGHT_FG_COLOR] + + Reline.dialog_default_bg_color = @dialog_default_bg_color if @dialog_default_bg_color + Reline.dialog_default_fg_color = @dialog_default_fg_color if @dialog_default_fg_color + Reline.dialog_highlight_bg_color = @dialog_highlight_bg_color if @dialog_highlight_bg_color + Reline.dialog_highlight_fg_color = @dialog_highlight_fg_color if @dialog_highlight_fg_color end # The top-level workspace, see WorkSpace#main @@ -179,6 +209,22 @@ def main # +input_method+ passed to Context.new attr_accessor :irb_path + # Use bright theme for autocompletion dialog. Default is `false` + attr_reader :use_bright_theme + + # Colors for the autocompletion dialog. They will override the colors set by the theme + # Available colors (symbol) are: + # - :black + # - :red + # - :green + # - :yellow + # - :blue + # - :magenta + # - :cyan + # - :white + attr_reader :dialog_default_bg_color, :dialog_default_fg_color, + :dialog_highlight_bg_color, :dialog_highlight_fg_color + # Whether multiline editor mode is enabled or not. # # A copy of the default IRB.conf[:USE_MULTILINE] diff --git a/lib/irb/init.rb b/lib/irb/init.rb index d9c4353f3..bd18d65af 100644 --- a/lib/irb/init.rb +++ b/lib/irb/init.rb @@ -158,6 +158,7 @@ def IRB.init_config(ap_path) @CONF[:LC_MESSAGES] = Locale.new @CONF[:AT_EXIT] = [] + @CONF[:USE_BRIGHT_THEME] = false end def IRB.set_measure_callback(type = nil, arg = nil, &block)