Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commands should respect USE_COLORIZE config #362

Merged
merged 3 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/irb/cmd/ls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module IRB
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 : []
Expand Down Expand Up @@ -45,7 +45,8 @@ def class_method_map(classes)
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
Expand All @@ -56,7 +57,7 @@ def dump(name, strs)
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
Expand Down
3 changes: 2 additions & 1 deletion lib/irb/cmd/nop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ def self.execute(conf, *opts, &block)

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
Expand Down
4 changes: 2 additions & 2 deletions lib/irb/cmd/show_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def show_source(source)
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
Expand Down Expand Up @@ -78,7 +78,7 @@ def find_end(file, first_line)
end

def bold(str)
Color.colorize(str, [:BOLD])
Color.colorize(str, [:BOLD], colorable: colorable)
end

Source = Struct.new(
Expand Down