module SuperDiff::Csi
Attributes
color_enabled[W]
Public Class Methods
already_colorized?(text)
click to toggle source
# File lib/super_diff/csi.rb, line 39 def self.already_colorized?(text) text.match?(/\e\[\d+m/) end
color_enabled?()
click to toggle source
# File lib/super_diff/csi.rb, line 23 def self.color_enabled? @color_enabled end
colorize(*args, **opts, &block)
click to toggle source
# File lib/super_diff/csi.rb, line 27 def self.colorize(*args, **opts, &block) if color_enabled? ColorizedDocument.new(*args, **opts, &block) else UncolorizedDocument.new(*args, **opts, &block) end end
decolorize(text)
click to toggle source
# File lib/super_diff/csi.rb, line 35 def self.decolorize(text) text.gsub(/\e\[\d+(?:;\d+)*m(.+?)\e\[0m/, '\1') end
inspect_colors_in(text)
click to toggle source
# File lib/super_diff/csi.rb, line 43 def self.inspect_colors_in(text) [FourBitColor, EightBitColor, TwentyFourBitColor]. reduce(text) do |str, klass| klass.sub_colorized_areas_in(str) do |area, color| color_block = colorize("◼︎", color.to_foreground) layer_indicator = if color.foreground? "(fg)" else "(bg)" end "#{color_block} #{layer_indicator} ❮#{area}❯" end end end
reset_sequence()
click to toggle source
# File lib/super_diff/csi.rb, line 19 def self.reset_sequence ResetSequence.new end