Class: Seashell

Inherits:
Object
  • Object
show all
Defined in:
lib/seashell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSeashell

Returns a new instance of Seashell.



4
5
6
7
# File 'lib/seashell.rb', line 4

def initialize
    @debug = false
    @indent = 0
end

Instance Attribute Details

#debug(s) ⇒ Object



45
46
47
# File 'lib/seashell.rb', line 45

def debug(s)
    puts _level("debug", _indent + s) unless !@debug
end

Instance Method Details

#_blue(s) ⇒ Object



81
# File 'lib/seashell.rb', line 81

def _blue(s); _colorize(34, s); end

#_colorize(c, s) ⇒ Object



73
74
75
# File 'lib/seashell.rb', line 73

def _colorize(c, s)
    "\e[#{c}m#{s}\e[0m"
end

#_cyan(s) ⇒ Object



79
# File 'lib/seashell.rb', line 79

def _cyan(s); _colorize(36, s); end

#_green(s) ⇒ Object



77
# File 'lib/seashell.rb', line 77

def _green(s); _colorize(32, s); end

#_indentObject



9
10
11
# File 'lib/seashell.rb', line 9

def _indent
    "    " * @indent
end

#_level(l, s) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/seashell.rb', line 21

def _level(l, s)
    l.upcase!

    case l
    when "ACTION"
        l = _yellow(l)
    when "INFO"
        l = _pink(l)
    when "DEBUG"
        l = _cyan(l)
    end

    !@debug ? s : "#{l} #{s}"
end

#_pink(s) ⇒ Object



82
# File 'lib/seashell.rb', line 82

def _pink(s); _colorize(35, s); end

#_red(s) ⇒ Object



78
# File 'lib/seashell.rb', line 78

def _red(s); _colorize(31, s); end

#_white(s) ⇒ Object



83
# File 'lib/seashell.rb', line 83

def _white(s); _colorize(37, s); end

#_yellow(s) ⇒ Object



80
# File 'lib/seashell.rb', line 80

def _yellow(s); _colorize(33, s); end

#action(s) ⇒ Object



36
37
38
39
# File 'lib/seashell.rb', line 36

def action(s)
    print _level("action", _indent + s)
    $stdout.flush
end

#doneObject



58
59
60
61
# File 'lib/seashell.rb', line 58

def done
    print " [" + _green("DONE") + "]\n"
    $stdout.flush
end

#errorObject



68
69
70
71
# File 'lib/seashell.rb', line 68

def error
    print " [" + _red("ERROR") + "]\n"
    $stdout.flush
end

#failedObject



63
64
65
66
# File 'lib/seashell.rb', line 63

def failed
    print " [" + _red("FAILED") + "]\n"
    $stdout.flush
end

#indentObject



13
14
15
# File 'lib/seashell.rb', line 13

def indent
    @indent = @indent + 1
end

#msg(s) ⇒ Object



41
42
43
# File 'lib/seashell.rb', line 41

def msg(s)
    puts _level("info", _indent + s)
end

#okObject



53
54
55
56
# File 'lib/seashell.rb', line 53

def ok
    print " [" + _green("OK") + "]\n"
    $stdout.flush
end

#tickObject



49
50
51
# File 'lib/seashell.rb', line 49

def tick
    putc "."
end

#unindentObject



17
18
19
# File 'lib/seashell.rb', line 17

def unindent
    @indent = (@indent - 1) unless @indent == 0
end