[前][次][番号順一覧][スレッド一覧]

ruby-changes:72259

From: Stan <ko1@a...>
Date: Mon, 20 Jun 2022 22:27:44 +0900 (JST)
Subject: [ruby-changes:72259] 2d4a41df6b (master): [ruby/irb] Commands should respect `USE_COLORIZE` config (https://github.com/ruby/irb/pull/362)

https://git.ruby-lang.org/ruby.git/commit/?id=2d4a41df6b

From 2d4a41df6bef7a67784c680550591d5b883853fe Mon Sep 17 00:00:00 2001
From: Stan Lo <stan001212@g...>
Date: Mon, 20 Jun 2022 14:27:12 +0100
Subject: [ruby/irb] Commands should respect `USE_COLORIZE` config
 (https://github.com/ruby/irb/pull/362)

https://github.com/ruby/irb/commit/534688dfc4
---
 lib/irb/cmd/ls.rb          | 7 ++++---
 lib/irb/cmd/nop.rb         | 3 ++-
 lib/irb/cmd/show_source.rb | 4 ++--
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/lib/irb/cmd/ls.rb b/lib/irb/cmd/ls.rb
index f4a7348bd1..6a30a28ea0 100644
--- a/lib/irb/cmd/ls.rb
+++ b/lib/irb/cmd/ls.rb
@@ -10,7 +10,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/cmd/ls.rb#L10
   module ExtendCommand
     class Ls < Nop
       def execute(*arg, grep: nil)
-        o = Output.new(grep: grep)
+        o = Output.new(grep: grep, colorable: colorable)
 
         obj    = arg.empty? ? irb_context.workspace.main : arg.first
         locals = arg.empty? ? irb_context.workspace.binding.local_variables : []
@@ -45,7 +45,8 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/cmd/ls.rb#L45
       class Output
         MARGIN = "  "
 
-        def initialize(grep: nil)
+        def initialize(grep: nil, colorable: true)
+          @colorable = colorable
           @grep = grep
           @line_width = screen_width - MARGIN.length # right padding
         end
@@ -56,7 +57,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/cmd/ls.rb#L57
           return if strs.empty?
 
           # Attempt a single line
-          print "#{Color.colorize(name, [:BOLD, :BLUE])}: "
+          print "#{Color.colorize(name, [:BOLD, :BLUE], colorable: @colorable)}: "
           if fits_on_line?(strs, cols: strs.size, offset: "#{name}: ".length)
             puts strs.join(MARGIN)
             return
diff --git a/lib/irb/cmd/nop.rb b/lib/irb/cmd/nop.rb
index 881a736722..17ff2f9b7e 100644
--- a/lib/irb/cmd/nop.rb
+++ b/lib/irb/cmd/nop.rb
@@ -29,9 +29,10 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/cmd/nop.rb#L29
 
       def initialize(conf)
         @irb_context = conf
+        @colorable = Color.colorable? && conf.use_colorize
       end
 
-      attr_reader :irb_context
+      attr_reader :irb_context, :colorable
 
       def irb
         @irb_context.irb
diff --git a/lib/irb/cmd/show_source.rb b/lib/irb/cmd/show_source.rb
index f8a17822df..7e790c3c93 100644
--- a/lib/irb/cmd/show_source.rb
+++ b/lib/irb/cmd/show_source.rb
@@ -30,7 +30,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/cmd/show_source.rb#L30
         puts
         puts "#{bold("From")}: #{source.file}:#{source.first_line}"
         puts
-        code = IRB::Color.colorize_code(File.read(source.file))
+        code = IRB::Color.colorize_code(File.read(source.file), colorable: colorable)
         puts code.lines[(source.first_line - 1)...source.last_line].join
         puts
       end
@@ -78,7 +78,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/cmd/show_source.rb#L78
       end
 
       def bold(str)
-        Color.colorize(str, [:BOLD])
+        Color.colorize(str, [:BOLD], colorable: colorable)
       end
 
       Source = Struct.new(
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]