Top Level Namespace

Defined Under Namespace

Modules: BasicLogging, Console, File_Checking Classes: Adder, ArgParser, BusyIndicator, Event, String, Timequiz, UserInput

Constant Summary collapse

VERSION =

/***************************************************************************

*   
'0.2'
SUMMARY =
'Nicer console output.'
AUTHOR =
'Michael Uplawski'
AUTHOR_MAIL =
'<[email protected]>'
YEARS =
2017 - 2025
CLICKED =

EVENTS

'clicked'
ACTIVATE =
'activate'
ENTER =
'enter-notify-event'
LEAVE =
'leave'
TOGGLED =
'toggled'
COLORS =

Functions to apply colors to terminal output. This is stolen from the Internet and I have lost track of my own additions and modifications.

{:default => 9, :black => 0, :red => 1, :green => 2, :yellow => 3, :blue => 4, :purple => 5, :cyan => 6, :white => 7 }
BG =
4
FG =
3
REGULAR =
0
BOLD =
1
UNDERLINE =
4
5
SWAP =
7
NEUTRAL =
0
STYLES =
{:regular => REGULAR, :bold => BOLD, :underline => UNDERLINE, :blink => BLINK, :swap => SWAP, :neutral => NEUTRAL}

Instance Method Summary collapse

Instance Method Details

#black_on_white(text) ⇒ Object



61
# File 'lib/color_output.rb', line 61

def black_on_white(text); colorize(colorize(text, "\033[30m"), "\033[47m");end

#blue(text) ⇒ Object



58
# File 'lib/color_output.rb', line 58

def blue(text); colorize(text, "\033[34m"); end

#bold(text) ⇒ Object



64
# File 'lib/color_output.rb', line 64

def bold(text); style(text, "\033[01m");end

#colored_output(output_text, fg_color = :default, bg_color = :default, style = :regular, mode = :neutral) ⇒ Object

a function which allows to manipulate every known aspect of the ansi-output.



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

def colored_output(output_text, fg_color = :default, bg_color = :default, style = :regular , mode = :neutral )
  "\033[%i;%i;%i%i;%i%im%s\033[0m" %[STYLES[mode.to_sym], STYLES[style.to_sym], FG, COLORS[fg_color.to_sym], BG, COLORS[bg_color.to_sym], output_text]
end

#colorize(text, color_code) ⇒ Object

Colorizes the given text. Color-code is either an escape-sequence or one of the symbols representing color-names in the COLORS hash.



36
37
38
39
40
41
42
# File 'lib/color_output.rb', line 36

def colorize(text, color_code)
  if (COLORS.keys.include?(color_code) )
    "\033[3#{COLORS[color_code]}m#{text}\033[0m"
  else
    "#{color_code}#{text}\033[0m"
  end
end

#cyan(text) ⇒ Object



57
# File 'lib/color_output.rb', line 57

def cyan(text); colorize(text, "\033[36m"); end

#green(text) ⇒ Object



54
# File 'lib/color_output.rb', line 54

def green(text); colorize(text, "\033[32m"); end

#purple(text) ⇒ Object



56
# File 'lib/color_output.rb', line 56

def purple(text); colorize(text, "\033[35m"); end

#red(text) ⇒ Object

convenience functions



53
# File 'lib/color_output.rb', line 53

def red(text); colorize(text, "\033[31m"); end

#style(text, style_code) ⇒ Object



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

def style(text, style_code)
  "#{style_code}#{text}\033[0m"
end

#underline(text) ⇒ Object



65
# File 'lib/color_output.rb', line 65

def underline(text); style(text, "\033[04m");end

#white(text) ⇒ Object



59
# File 'lib/color_output.rb', line 59

def white(text); colorize(text, "\033[37m"); end

#white_on_black(text) ⇒ Object



62
# File 'lib/color_output.rb', line 62

def white_on_black(text); colorize(colorize(text, "\033[37m"), "\033[40m");end

#yellow(text) ⇒ Object



55
# File 'lib/color_output.rb', line 55

def yellow(text); colorize(text, "\033[33m"); end