Module: GitJump::Colors

Defined in:
lib/git_jump/colors.rb

Overview

Lightweight color module using ANSI escape codes Inspired by dotsync’s approach - no external dependencies

Constant Summary collapse

GREEN =

ANSI color codes (256-color palette) Use e[38;5;NNNm for foreground colors Use e[1m for bold Use e[0m to reset

34
RED =
196
YELLOW =
220
BLUE =
39
CYAN =
51
DIM =
242

Class Method Summary collapse

Class Method Details

.blue(text, bold: false) ⇒ Object



40
41
42
# File 'lib/git_jump/colors.rb', line 40

def blue(text, bold: false)
  colorize(text, color: BLUE, bold: bold)
end

.bold(text) ⇒ Object



52
53
54
# File 'lib/git_jump/colors.rb', line 52

def bold(text)
  "\e[1m#{text}\e[0m"
end

.colorize(text, color:, bold: false) ⇒ Object



21
22
23
24
25
26
# File 'lib/git_jump/colors.rb', line 21

def colorize(text, color:, bold: false)
  codes = []
  codes << "\e[38;5;#{color}m" if color
  codes << "\e[1m" if bold
  "#{codes.join}#{text}\e[0m"
end

.cyan(text, bold: false) ⇒ Object



44
45
46
# File 'lib/git_jump/colors.rb', line 44

def cyan(text, bold: false)
  colorize(text, color: CYAN, bold: bold)
end

.dim(text) ⇒ Object



48
49
50
# File 'lib/git_jump/colors.rb', line 48

def dim(text)
  colorize(text, color: DIM, bold: false)
end

.green(text, bold: false) ⇒ Object



28
29
30
# File 'lib/git_jump/colors.rb', line 28

def green(text, bold: false)
  colorize(text, color: GREEN, bold: bold)
end

.red(text, bold: false) ⇒ Object



32
33
34
# File 'lib/git_jump/colors.rb', line 32

def red(text, bold: false)
  colorize(text, color: RED, bold: bold)
end

.yellow(text, bold: false) ⇒ Object



36
37
38
# File 'lib/git_jump/colors.rb', line 36

def yellow(text, bold: false)
  colorize(text, color: YELLOW, bold: bold)
end