Class: AngryMob::UI
Constant Summary collapse
- CLEAR =
Embed in a String to clear all previous ANSI sequences.
"\e[0m"
- BOLD =
The start of an ANSI bold sequence.
"\e[1m"
- BLACK =
Set the terminal’s foreground ANSI color to black.
"\e[30m"
- RED =
Set the terminal’s foreground ANSI color to red.
"\e[31m"
- GREEN =
Set the terminal’s foreground ANSI color to green.
"\e[32m"
- YELLOW =
Set the terminal’s foreground ANSI color to yellow.
"\e[33m"
- BLUE =
Set the terminal’s foreground ANSI color to blue.
"\e[34m"
- MAGENTA =
Set the terminal’s foreground ANSI color to magenta.
"\e[35m"
- CYAN =
Set the terminal’s foreground ANSI color to cyan.
"\e[36m"
- WHITE =
Set the terminal’s foreground ANSI color to white.
"\e[37m"
- GRAY =
"#{BOLD}#{BLACK}"
- BRIGHT_WHITE =
"#{BOLD}#{WHITE}"
- ON_BLACK =
Set the terminal’s background ANSI color to black.
"\e[40m"
- ON_RED =
Set the terminal’s background ANSI color to red.
"\e[41m"
- ON_GREEN =
Set the terminal’s background ANSI color to green.
"\e[42m"
- ON_YELLOW =
Set the terminal’s background ANSI color to yellow.
"\e[43m"
- ON_BLUE =
Set the terminal’s background ANSI color to blue.
"\e[44m"
- ON_MAGENTA =
Set the terminal’s background ANSI color to magenta.
"\e[45m"
- ON_CYAN =
Set the terminal’s background ANSI color to cyan.
"\e[46m"
- ON_WHITE =
Set the terminal’s background ANSI color to white.
"\e[47m"
Instance Attribute Summary collapse
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Class Method Summary collapse
Instance Method Summary collapse
- #benchmark? ⇒ Boolean
- #colourise(string, colour, bold = false) ⇒ Object
-
#current ⇒ Object
def self.stack; @stack ||= [] end def stack; self.class.stack end.
- #debug(message) ⇒ Object
- #debug? ⇒ Boolean
- #error(message) ⇒ Object (also: #bad)
- #exception!(ex) ⇒ Object
- #good(message) ⇒ Object
- #indent ⇒ Object
- #info(message) ⇒ Object
-
#initialize(options = {}, min_level = 0, stack = []) ⇒ UI
constructor
A new instance of UI.
- #isay(message, colour = nil, force_new_line = (message.to_s !~ /( |\t)$/)) ⇒ Object
- #log(message) ⇒ Object
- #newline ⇒ Object
- #ok!(message = nil) ⇒ Object (also: #changed!)
- #outdent ⇒ Object
- #point(message) ⇒ Object
- #push(message, opts = {}, &block) ⇒ Object
- #recolourize(colour) ⇒ Object
- #say(message = "", colour = nil, force_new_line = (message.to_s !~ /( |\t)$/)) ⇒ Object
- #silence(&block) ⇒ Object
- #skipped!(message) ⇒ Object
- #spaces ⇒ Object
- #start!(banner) ⇒ Object
- #task(message) ⇒ Object
- #warn(message) ⇒ Object
Constructor Details
Instance Attribute Details
#level ⇒ Object (readonly)
Returns the value of attribute level.
47 48 49 |
# File 'lib/angry_mob/ui.rb', line 47 def level @level end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
47 48 49 |
# File 'lib/angry_mob/ui.rb', line 47 def @message end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
47 48 49 |
# File 'lib/angry_mob/ui.rb', line 47 def result @result end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
47 48 49 |
# File 'lib/angry_mob/ui.rb', line 47 def stack @stack end |
Class Method Details
.silence(&block) ⇒ Object
107 108 109 110 111 112 |
# File 'lib/angry_mob/ui.rb', line 107 def self.silence(&block) old_silence,@silence = @silence,true yield ensure @silence = old_silence end |
.silence? ⇒ Boolean
113 114 115 |
# File 'lib/angry_mob/ui.rb', line 113 def self.silence? @silence end |
Instance Method Details
#benchmark? ⇒ Boolean
156 157 158 |
# File 'lib/angry_mob/ui.rb', line 156 def benchmark? @benchmark ||= !(FalseClass === @options[:benchmark]) end |
#colourise(string, colour, bold = false) ⇒ Object
62 63 64 65 66 |
# File 'lib/angry_mob/ui.rb', line 62 def colourise(string, colour, bold=false) color = self.class.const_get(colour.to_s.upcase) if colour.is_a?(Symbol) bold = bold ? BOLD : "" "#{bold}#{color}#{string}#{CLEAR}" end |
#current ⇒ Object
def self.stack; @stack ||= [] end def stack; self.class.stack end
58 59 60 |
# File 'lib/angry_mob/ui.rb', line 58 def current stack.last || self end |
#debug(message) ⇒ Object
152 153 154 |
# File 'lib/angry_mob/ui.rb', line 152 def debug() say spaces+, :gray if debug? end |
#debug? ⇒ Boolean
149 150 151 |
# File 'lib/angry_mob/ui.rb', line 149 def debug? @debug ||= !(FalseClass === @options[:debug]) end |
#error(message) ⇒ Object Also known as: bad
144 145 146 |
# File 'lib/angry_mob/ui.rb', line 144 def error() say spaces+, :red end |
#exception!(ex) ⇒ Object
222 223 224 225 226 227 228 229 |
# File 'lib/angry_mob/ui.rb', line 222 def exception!(ex) msg = "[#{ex.class}] - #{ex.}" say spaces+msg, :red # backtrace @result = ex @message = msg end |
#good(message) ⇒ Object
127 128 129 |
# File 'lib/angry_mob/ui.rb', line 127 def good() say spaces+, :green end |
#indent ⇒ Object
98 99 100 |
# File 'lib/angry_mob/ui.rb', line 98 def indent @level += 1 end |
#info(message) ⇒ Object
123 124 125 |
# File 'lib/angry_mob/ui.rb', line 123 def info() say spaces+, :bright_white end |
#isay(message, colour = nil, force_new_line = (message.to_s !~ /( |\t)$/)) ⇒ Object
86 87 88 |
# File 'lib/angry_mob/ui.rb', line 86 def isay(, colour=nil, force_new_line=(.to_s !~ /( |\t)$/)) say spaces+, colour, force_new_line end |
#log(message) ⇒ Object
136 137 138 |
# File 'lib/angry_mob/ui.rb', line 136 def log() say spaces+indent_string(, @level+1), :white end |
#newline ⇒ Object
90 91 92 |
# File 'lib/angry_mob/ui.rb', line 90 def newline $stdout.puts "\n" unless self.class.silence? end |
#ok!(message = nil) ⇒ Object Also known as: changed!
231 232 233 234 |
# File 'lib/angry_mob/ui.rb', line 231 def ok!(=nil) @result = :ok @message = end |
#outdent ⇒ Object
102 103 104 105 |
# File 'lib/angry_mob/ui.rb', line 102 def outdent @level -= 1 @level = @min_level if @level < @min_level end |
#point(message) ⇒ Object
140 141 142 |
# File 'lib/angry_mob/ui.rb', line 140 def point() say spaces+"● #{}", :blue end |
#push(message, opts = {}, &block) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/angry_mob/ui.rb', line 164 def push(,opts={},&block) start_time = Time.now start! subui = self.class.new(@options, @level+1,stack) stack.push subui begin yield rescue Object if opts[:bubble] raise $! else subui.exception!($!) end end ensure stack.pop say spaces+'}', :yellow, false colour = nil case subui.result when :ok colour = :green say " ✓ #{}", :green, false say " (#{subui.})", :green, false if subui. when :skip colour = :blue say " ● #{}", :blue, false say " (#{subui.})", :blue, false if subui. when Exception colour = :red say " ☠ #{}", :red, false say " (#{subui.})", :red, false if subui. newline raise subui.result else colour = :gray say " #{}", :gray, false end say(" (#{Time.now-start_time}s)", colour, false) if benchmark? newline newline end |
#recolourize(colour) ⇒ Object
68 69 70 |
# File 'lib/angry_mob/ui.rb', line 68 def recolourize(colour) $stdout.print("\e[s\e[1G#{RED}\e[u") end |
#say(message = "", colour = nil, force_new_line = (message.to_s !~ /( |\t)$/)) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/angry_mob/ui.rb', line 72 def say(="", colour=nil, force_new_line=(.to_s !~ /( |\t)$/)) return if self.class.silence? = .to_s = colourise(, colour) if colour if force_new_line $stdout.puts() else $stdout.print() $stdout.flush end end |
#silence(&block) ⇒ Object
116 117 118 |
# File 'lib/angry_mob/ui.rb', line 116 def silence(&block) self.class.silence(&block) end |
#skipped!(message) ⇒ Object
237 238 239 240 |
# File 'lib/angry_mob/ui.rb', line 237 def skipped!() @result = :skip @message = end |
#spaces ⇒ Object
94 95 96 |
# File 'lib/angry_mob/ui.rb', line 94 def spaces " " * @level end |
#start!(banner) ⇒ Object
216 217 218 219 220 |
# File 'lib/angry_mob/ui.rb', line 216 def start!() say spaces+">> ", :blue say , :white, false say " {", :yellow end |
#task(message) ⇒ Object
131 132 133 134 |
# File 'lib/angry_mob/ui.rb', line 131 def task() isay ">> ", :blue say end |
#warn(message) ⇒ Object
160 161 162 |
# File 'lib/angry_mob/ui.rb', line 160 def warn() say spaces+, :yellow end |