Module: Termline::Style

Defined in:
lib/termline/style.rb

Constant Summary collapse

ICONS =

Available icons

{
    warning: "",
    success: "",
    debug: "",
    error: "",
    info: "",
    star: "",
    add: "+",
    remove: "-"
}.freeze
COLORS =

standard color palette for texts

{ 
    skyblue: '96',
    default: '38', 
    yellow: '1;33',
    white: '1;37', 
    green: '32',  
    black: '30', 
    gray: '90',
    blue: '36', 
    red: '31'
}.freeze
BG_COLORS =

standard color palette for backgrounds

{ 
    default: '0', 
    yellow: '103', 
    white: '107', 
    green: '42', 
    black: '40', 
    blue: '44',
    red: '41'
}.freeze
WIDTH =

calculate the console width tputcols is not available on windows

begin
    term = ENV['TERM']
    term ? `tput cols`.to_i : 1
rescue
    1
end

Class Method Summary collapse

Class Method Details

.colorize(text, colour = :default, bg_colour = :default) ⇒ Object

Concat color to text



88
89
90
91
92
# File 'lib/termline/style.rb', line 88

def colorize(text, colour = :default, bg_colour = :default)
    colour_code = COLORS[colour]
    bg_colour_code = BG_COLORS[bg_colour]
    return "\e[#{bg_colour_code};#{colour_code}m#{text}\e[0m".squeeze(';')
end

.icon(icon) ⇒ Object



83
84
85
# File 'lib/termline/style.rb', line 83

def icon icon
    ICONS[icon]
end

.pretty(message, colour = :default, bg_colour = :default) ⇒ Object

Format text



95
96
97
98
99
100
101
102
103
104
# File 'lib/termline/style.rb', line 95

def pretty(message, colour = :default, bg_colour = :default)
    width = 1
        
    unless bg_colour == :default
        width = WIDTH - message.length - 4
        width = 1 if width.negative?
    end
        
    return colorize("#{ message } #{"\ " * width}", colour, bg_colour)
end