Module: Libconsole::Lang::JS
- Extended by:
- Color
- Includes:
- Color
- Included in:
- JS, MyClass
- Defined in:
- lib/libconsole/lang/js.rb
Overview
Constant Summary
Constants included
from Color
Color::Color, Color::Escape, Color::Format, Color::Range
Instance Method Summary
collapse
Methods included from Color
_no_empty
Instance Method Details
#assert(assertion = false, *args) ⇒ Object
66
67
68
69
|
# File 'lib/libconsole/lang/js.rb', line 66
def assert(assertion = false, *args)
args.unshift("!= Assertion failed:")
pre_puts red(_color_space(args)) unless assertion
end
|
#clear ⇒ Object
71
72
73
74
|
# File 'lib/libconsole/lang/js.rb', line 71
def clear
!Gem.win_platform? ? (system "clear") : (system "cls")
pre_puts italic("Console was cleared")
end
|
#count(label = "default") ⇒ Object
76
77
78
79
80
|
# File 'lib/libconsole/lang/js.rb', line 76
def count(label = "default")
@count_state[label.to_sym] = 0 unless @count_state[label.to_sym]
@count_state[label.to_sym] += 1
pre_puts "#{label}: #{@count_state[label.to_sym]}"
end
|
#count_reset(label = "default") ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'lib/libconsole/lang/js.rb', line 82
def count_reset(label = "default")
unless @count_state[label.to_sym]
pre_puts "Count for '#{label}' does not exist"
return
end
@count_state[label.to_sym] = 0
pre_puts "#{label}: #{@count_state[label.to_sym]}"
end
|
#debug(*argv) ⇒ Object
62
63
64
|
# File 'lib/libconsole/lang/js.rb', line 62
def debug(*argv)
pre_puts bgred(_color_space(argv)) if @debug
end
|
#default ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/libconsole/lang/js.rb', line 12
def default
@debug = false
@count_state = {}
@time_start_state = {}
@indet = ""
@indet_symbol = " "
@indet_size = 4
@indet_count = 0
@group_tier = 0
@group_symbol = blue("|")
end
|
#dir(*argv) ⇒ Object
91
92
93
|
# File 'lib/libconsole/lang/js.rb', line 91
def dir(*argv)
pp(argv)
end
|
#dirxml(*argv) ⇒ Object
95
96
97
|
# File 'lib/libconsole/lang/js.rb', line 95
def dirxml(*argv)
pp(argv)
end
|
#error(*argv) ⇒ Object
57
58
59
60
|
# File 'lib/libconsole/lang/js.rb', line 57
def error(*argv)
argv.unshift("!")
pre_puts red(_color_space(argv))
end
|
#group(label = "console.group") ⇒ Object
99
100
101
102
103
104
|
# File 'lib/libconsole/lang/js.rb', line 99
def group(label = "console.group")
@group_tier += 1
pre_puts bold(label)
@indet_count += @indet_size
@indet = @indet_symbol * @indet_count
end
|
#group_collapsed(label = "console.group") ⇒ Object
106
107
108
109
110
111
|
# File 'lib/libconsole/lang/js.rb', line 106
def group_collapsed(label = "console.group")
@group_tier += 1
pre_puts bold(label)
@indet_count += @indet_size
@indet = @indet_symbol * @indet_count
end
|
#group_end ⇒ Object
113
114
115
116
117
118
119
|
# File 'lib/libconsole/lang/js.rb', line 113
def group_end
@indet_count -= @indet_size
@indet_count = 0 if @indet_count.negative?
@indet = @indet_symbol * @indet_count
@group_tier -= 1
@group_tier = 0 if @group_tier.negative?
end
|
#info(*argv) ⇒ Object
47
48
49
50
|
# File 'lib/libconsole/lang/js.rb', line 47
def info(*argv)
argv.unshift("~")
pre_puts blue(_color_space(argv))
end
|
#log(*argv) ⇒ Object
43
44
45
|
# File 'lib/libconsole/lang/js.rb', line 43
def log(*argv)
pre_puts _color_space(argv)
end
|
#table(*msg) ⇒ Object
121
122
123
|
# File 'lib/libconsole/lang/js.rb', line 121
def table(*msg)
pre_puts msg.join(" ")
end
|
#time(label = "default") ⇒ Object
125
126
127
128
129
130
131
132
|
# File 'lib/libconsole/lang/js.rb', line 125
def time(label = "default")
if @time_start_state[label.to_sym]
pre_puts yellow("Timer '#{label}' already exists")
else
@time_start_state[label.to_sym] = Time.now
end
end
|
#time_end(label = "default") ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/libconsole/lang/js.rb', line 134
def time_end(label = "default")
unless @time_start_state[label.to_sym]
pre_puts "Timer '#{label}' does not exist"
return
end
start = @time_start_state[label.to_sym]
finish = Time.now
range_ms = (finish.tv_sec - start.tv_sec) * 1000 + (finish.tv_nsec - start.tv_nsec) * 1e-6
range_fmt = format("%.6f", range_ms)
pre_puts "#{label}: #{range_fmt} ms - timer ended"
@time_start_state[label.to_sym] = nil
end
|
#time_log(label = "default") ⇒ Object
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/libconsole/lang/js.rb', line 147
def time_log(label = "default")
unless @time_start_state[label.to_sym]
pre_puts "Timer '#{label}' does not exist"
return
end
start = @time_start_state[label.to_sym]
finish = Time.now
range_ms = (finish.tv_sec - start.tv_sec) * 1000 + (finish.tv_nsec - start.tv_nsec) * 1e-6
range_fmt = format("%.6f", range_ms)
pre_puts "#{label}: #{range_fmt} ms"
end
|
#trace(*argv) ⇒ Object
159
160
161
162
163
164
165
|
# File 'lib/libconsole/lang/js.rb', line 159
def trace(*argv)
if argv.empty?
pre_puts "console.trace"
else
pre_puts argv.join(" ")
end
end
|
#warn(*argv) ⇒ Object
52
53
54
55
|
# File 'lib/libconsole/lang/js.rb', line 52
def warn(*argv)
argv.unshift("?")
pre_puts yellow(_color_space(argv))
end
|