Top Level Namespace

Defined Under Namespace

Modules: Logging, Rearranging, Translating Classes: Adder, ArgParser, SprichWoerter, TClass

Constant Summary collapse

VERSION =

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

*   
1.6
SUMMARY =
"Adding proverbs works again, now intaractively. Values are no longer given on the command-line, but asked, one by one, from the user."
COLORS =

functions to apply colors to terminal output

{: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(text) ⇒ Object



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

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

#black_on_white(text) ⇒ Object



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

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

#blue(text) ⇒ Object



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

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

#bold(text) ⇒ Object



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

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

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



26
27
28
# File 'lib/color_output.rb', line 26

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



18
19
20
# File 'lib/color_output.rb', line 18

def colorize(text, color_code)
    "#{color_code}#{text}\033[0m"
end

#cyan(text) ⇒ Object



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

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

#green(text) ⇒ Object



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

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

#purple(text) ⇒ Object



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

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

#red(text) ⇒ Object



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

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

#style(text, style_code) ⇒ Object



22
23
24
# File 'lib/color_output.rb', line 22

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

#underline(text) ⇒ Object



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

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

#wait_for_userObject

The totally mystic and heard-about-so-long, fantastic and marvelous… Non-blocking User-Input. I have seen this somewhere and am explicitely thankful to someone to have written something about it.



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/user_input.rb', line 34

def wait_for_user()
  char = nil
  STDIN.raw do 
    STDIN.noecho do
      until (STDIN.ready?)
        sleep(0.1)
      end
      char = (STDIN.read_nonblock(1).ord rescue nil)
    end
  end
  return char
end

#white(text) ⇒ Object



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

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

#white_on_black(text) ⇒ Object



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

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

#yellow(text) ⇒ Object



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

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