Module: Canon::DiffFormatter::DiffDetailFormatterHelpers::ColorHelper

Defined in:
lib/canon/diff_formatter/diff_detail_formatter/color_helper.rb

Overview

Color helper for diff formatting

Provides consistent colorization for diff output.

Class Method Summary collapse

Class Method Details

.colorize(text, color, use_color, bold: false) ⇒ String

Colorize text with optional bold formatting

Parameters:

  • text (String)

    Text to colorize

  • color (Symbol)

    Color name

  • use_color (Boolean)

    Whether to use colors

  • bold (Boolean) (defaults to: false)

    Whether to make text bold

Returns:

  • (String)

    Colorized text (or plain text if use_color is false)



19
20
21
22
23
24
25
# File 'lib/canon/diff_formatter/diff_detail_formatter/color_helper.rb', line 19

def self.colorize(text, color, use_color, bold: false)
  return text unless use_color

  presenter = Rainbow(text).send(color)
  presenter = presenter.bright if bold
  presenter.to_s
end