libconsole 0.1.0 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/libconsole/color.rb +89 -0
- data/lib/libconsole/lang/js.rb +186 -0
- data/lib/libconsole/lang/js_test.rb +120 -0
- data/lib/libconsole/version.rb +1 -1
- data/lib/libconsole.rb +5 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b57fcb9a44aa6ded5ca692a45d68fa78afec780ed387715c673706218ad882e
|
4
|
+
data.tar.gz: d43f17324b759841d480d2ab4b0d0613f504e3bb807a831d118f6e3d8ce78d75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36ef088bc55a5641315e5accae6ed53ddfd6102490644b6e3631a45b97bab0c82d91c95e4a357e1b8b7fe149609e25a1d31810a4626ea469fef7d84a2ce1b485
|
7
|
+
data.tar.gz: a7ecdd87df13d969837bfb3ab5ed5573a9452d212dfe939c7905e3d120a3d4d4896ff93ff5b5d764a0225899ac45bab442bf6cda6e85cdf33ba689d605fca549
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -19,15 +19,15 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
19
19
|
```ruby
|
20
20
|
require "libconsole"
|
21
21
|
|
22
|
-
class MyClass
|
22
|
+
class MyClass < Libconsole::CI::Github::Attr
|
23
23
|
extend Libconsole::CI::Github
|
24
|
-
include Libconsole::CI::Github::Attr
|
25
24
|
end
|
26
25
|
|
27
26
|
MyClass.info("info")
|
28
27
|
|
29
28
|
m = MyClass.new
|
30
29
|
m.add_path("/usr/bin")
|
30
|
+
m.export_variable("CC", "gcc")
|
31
31
|
```
|
32
32
|
|
33
33
|
## Development
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Libconsole
|
4
|
+
module Color
|
5
|
+
# https://dev.to/truemark/11-most-asked-questions-about-rubocop-38al
|
6
|
+
|
7
|
+
# rubocop:disable Layout/HashAlignment
|
8
|
+
|
9
|
+
# https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
|
10
|
+
Escape = {
|
11
|
+
uni: "\u001b",
|
12
|
+
oct: "\033",
|
13
|
+
hex: "\x1B",
|
14
|
+
lang: "\e"
|
15
|
+
}
|
16
|
+
|
17
|
+
# https://gist.github.com/iamnewton/8754917
|
18
|
+
Format = {
|
19
|
+
reset: [0, "E"], bold: [1, "B"],
|
20
|
+
dim: [2, "D"], italic: [3, "I"],
|
21
|
+
underline: [4, "U"], blink: [5, "N"],
|
22
|
+
fastblink: [6, "F"], reverse: [7, "V"],
|
23
|
+
hide: [8, "H"], strike: [9, "S"]
|
24
|
+
}
|
25
|
+
|
26
|
+
# https://ss64.com/nt/syntax-ansi.html
|
27
|
+
Color = {
|
28
|
+
black: [0, "K"], red: [1, "R"],
|
29
|
+
green: [2, "G"], yellow: [3, "Y"],
|
30
|
+
blue: [4, "L"], magenta: [5, "M"],
|
31
|
+
cyan: [6, "C"], white: [7, "W"]
|
32
|
+
}
|
33
|
+
|
34
|
+
Range = {
|
35
|
+
"" => 30,
|
36
|
+
"bg" => 40,
|
37
|
+
"light" => 90,
|
38
|
+
"bglight" => 100
|
39
|
+
}
|
40
|
+
|
41
|
+
def _no_empty(argv)
|
42
|
+
argv.any? ? argv : nil
|
43
|
+
end
|
44
|
+
|
45
|
+
Escape.each do |std, pre|
|
46
|
+
Format.each do |name, pair|
|
47
|
+
code = pair[0]
|
48
|
+
alias_name = pair[1]
|
49
|
+
|
50
|
+
fn_name = "#{std}_#{name}"
|
51
|
+
define_method(fn_name) do |any = nil|
|
52
|
+
if any
|
53
|
+
"#{pre}[#{code}m#{any}#{pre}[0m"
|
54
|
+
else
|
55
|
+
"#{pre}[#{code}m"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
alias_method alias_name, fn_name
|
60
|
+
alias_method name, fn_name if std == :oct
|
61
|
+
end
|
62
|
+
|
63
|
+
Range.each do |n_pre, c_base|
|
64
|
+
Color.each do |n_base, pair|
|
65
|
+
c_add = pair[0]
|
66
|
+
alias_name = pair[1]
|
67
|
+
|
68
|
+
name = "#{n_pre}#{n_base}"
|
69
|
+
code = c_base + c_add
|
70
|
+
fn_name = "#{std}_#{name}"
|
71
|
+
define_method(fn_name) do |any = nil|
|
72
|
+
if any
|
73
|
+
"#{pre}[#{code}m#{any}#{pre}[0m"
|
74
|
+
else
|
75
|
+
"#{pre}[#{code}m"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
alias_method alias_name, fn_name if n_pre == ""
|
80
|
+
alias_method "G#{alias_name}", fn_name if n_pre == "bg"
|
81
|
+
alias_method "L#{alias_name}", fn_name if n_pre == "light"
|
82
|
+
alias_method "GL#{alias_name}", fn_name if n_pre == "bglight"
|
83
|
+
|
84
|
+
alias_method name, fn_name if std == :oct
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/lib/libconsole/lang/js.rb
CHANGED
@@ -1,9 +1,195 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "../color"
|
4
|
+
|
3
5
|
module Libconsole
|
4
6
|
module Lang
|
5
7
|
# https://developer.mozilla.org/en-US/docs/Web/API/console
|
6
8
|
module JS
|
9
|
+
extend Libconsole::Color
|
10
|
+
include Libconsole::Color
|
11
|
+
|
12
|
+
def default
|
13
|
+
@debug = false
|
14
|
+
|
15
|
+
@count_state = {}
|
16
|
+
@time_start_state = {}
|
17
|
+
|
18
|
+
@indet = ""
|
19
|
+
@indet_symbol = " "
|
20
|
+
@indet_size = 4
|
21
|
+
@indet_count = 0
|
22
|
+
|
23
|
+
@group_tier = 0
|
24
|
+
@group_symbol = blue("|")
|
25
|
+
end
|
26
|
+
|
27
|
+
def group_inner
|
28
|
+
@group_tier.positive?
|
29
|
+
end
|
30
|
+
private :group_inner
|
31
|
+
|
32
|
+
def pre_puts(argv)
|
33
|
+
pre = if group_inner
|
34
|
+
@indet + @group_symbol
|
35
|
+
else
|
36
|
+
@indet
|
37
|
+
end
|
38
|
+
puts _prefix(pre, argv)
|
39
|
+
end
|
40
|
+
private :pre_puts
|
41
|
+
|
42
|
+
# logging
|
43
|
+
def log(*argv)
|
44
|
+
pre_puts _color_space(argv)
|
45
|
+
end
|
46
|
+
|
47
|
+
def info(*argv)
|
48
|
+
argv.unshift("~")
|
49
|
+
pre_puts blue(_color_space(argv))
|
50
|
+
end
|
51
|
+
|
52
|
+
def warn(*argv)
|
53
|
+
argv.unshift("?")
|
54
|
+
pre_puts yellow(_color_space(argv))
|
55
|
+
end
|
56
|
+
|
57
|
+
def error(*argv)
|
58
|
+
argv.unshift("!")
|
59
|
+
pre_puts red(_color_space(argv))
|
60
|
+
end
|
61
|
+
|
62
|
+
def debug(*argv)
|
63
|
+
pre_puts bgred(_color_space(argv)) if @debug
|
64
|
+
end
|
65
|
+
|
66
|
+
def assert(assertion = false, *args)
|
67
|
+
args.unshift("!= Assertion failed:")
|
68
|
+
pre_puts red(_color_space(args)) unless assertion
|
69
|
+
end
|
70
|
+
|
71
|
+
def clear
|
72
|
+
!Gem.win_platform? ? (system "clear") : (system "cls")
|
73
|
+
pre_puts italic("Console was cleared")
|
74
|
+
end
|
75
|
+
|
76
|
+
def count(label = "default")
|
77
|
+
@count_state[:label] = 0 unless @count_state[:label]
|
78
|
+
@count_state[:label] += 1
|
79
|
+
pre_puts "#{label}: #{@count_state[:label]}"
|
80
|
+
end
|
81
|
+
|
82
|
+
def count_reset(label = "default")
|
83
|
+
unless @count_state[:label]
|
84
|
+
pre_puts "Count for '#{label}' does not exist"
|
85
|
+
return
|
86
|
+
end
|
87
|
+
@count_state[:label] = 0
|
88
|
+
pre_puts "#{label}: #{@count_state[:label]}"
|
89
|
+
end
|
90
|
+
|
91
|
+
def dir(*argv)
|
92
|
+
pp(argv)
|
93
|
+
end
|
94
|
+
|
95
|
+
def dirxml(*argv)
|
96
|
+
pp(argv)
|
97
|
+
end
|
98
|
+
|
99
|
+
def group(label = "console.group")
|
100
|
+
@group_tier += 1
|
101
|
+
pre_puts bold(label)
|
102
|
+
@indet_count += @indet_size
|
103
|
+
@indet = @indet_symbol * @indet_count
|
104
|
+
end
|
105
|
+
|
106
|
+
def group_collapsed(label = "console.group")
|
107
|
+
@group_tier += 1
|
108
|
+
pre_puts bold(label)
|
109
|
+
@indet_count += @indet_size
|
110
|
+
@indet = @indet_symbol * @indet_count
|
111
|
+
end
|
112
|
+
|
113
|
+
def group_end
|
114
|
+
@indet_count -= @indet_size
|
115
|
+
@indet_count = 0 if @indet_count.negative?
|
116
|
+
@indet = @indet_symbol * @indet_count
|
117
|
+
@group_tier -= 1
|
118
|
+
@group_tier = 0 if @group_tier.negative?
|
119
|
+
end
|
120
|
+
|
121
|
+
def table(*msg)
|
122
|
+
pre_puts msg.join(" ")
|
123
|
+
end
|
124
|
+
|
125
|
+
def time(label = "default")
|
126
|
+
if @time_start_state[:label]
|
127
|
+
pre_puts yellow("Timer '#{label}' already exists")
|
128
|
+
else
|
129
|
+
# https://docs.ruby-lang.org/en/master/Time.html#method-i-tv_usec
|
130
|
+
@time_start_state[:label] = Time.now
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def time_end(label = "default")
|
135
|
+
unless @time_start_state[:label]
|
136
|
+
pre_puts "Timer '#{label}' does not exist"
|
137
|
+
return
|
138
|
+
end
|
139
|
+
now = Time.now
|
140
|
+
range = now - @time_start_state[:label]
|
141
|
+
range_ms = (range.to_f * 1000).truncate(6)
|
142
|
+
pre_puts "#{label}: #{range_ms} ms - timer ended"
|
143
|
+
@time_start_state[:label] = nil
|
144
|
+
end
|
145
|
+
|
146
|
+
def time_log(label = "default")
|
147
|
+
unless @time_start_state[:label]
|
148
|
+
pre_puts "Timer '#{label}' does not exist"
|
149
|
+
return
|
150
|
+
end
|
151
|
+
now = Time.now
|
152
|
+
range = now - @time_start_state[:label]
|
153
|
+
range_ms = (range.to_f * 1000).truncate(6)
|
154
|
+
pre_puts "#{label}: #{range_ms} ms"
|
155
|
+
end
|
156
|
+
|
157
|
+
def trace(*argv)
|
158
|
+
if argv.empty?
|
159
|
+
pre_puts "console.trace"
|
160
|
+
else
|
161
|
+
pre_puts argv.join(" ")
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
private
|
166
|
+
|
167
|
+
def _color_space(argv)
|
168
|
+
arr = []
|
169
|
+
argv.each do |arg|
|
170
|
+
if arg.instance_of?(String)
|
171
|
+
arr.push arg
|
172
|
+
elsif arg.instance_of?(TrueClass)
|
173
|
+
arr.push bgblue(arg)
|
174
|
+
elsif arg.instance_of?(FalseClass)
|
175
|
+
arr.push bgblue("false")
|
176
|
+
elsif arg.instance_of?(Integer)
|
177
|
+
arr.push bgcyan(arg)
|
178
|
+
elsif arg.instance_of?(Float)
|
179
|
+
arr.push bgmagenta(arg)
|
180
|
+
elsif arg.nil?
|
181
|
+
arr.push bgwhite("nil")
|
182
|
+
else
|
183
|
+
arr.push cyan(arg)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
arr.join(" ")
|
187
|
+
end
|
188
|
+
|
189
|
+
def _prefix(pre, args)
|
190
|
+
args unless pre
|
191
|
+
%(#{pre}#{args})
|
192
|
+
end
|
7
193
|
end
|
8
194
|
end
|
9
195
|
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "js"
|
4
|
+
|
5
|
+
class MyClass
|
6
|
+
include Libconsole::Lang::JS
|
7
|
+
end
|
8
|
+
|
9
|
+
console = MyClass.new
|
10
|
+
console.default
|
11
|
+
|
12
|
+
url = {
|
13
|
+
host: "localhost",
|
14
|
+
path: "/"
|
15
|
+
}
|
16
|
+
|
17
|
+
arr = %w[apples oranges bananas]
|
18
|
+
|
19
|
+
href = {
|
20
|
+
url: url,
|
21
|
+
query: "l=ruby"
|
22
|
+
}
|
23
|
+
|
24
|
+
comp = {
|
25
|
+
query: "l=ruby",
|
26
|
+
url: url,
|
27
|
+
arr: arr
|
28
|
+
}
|
29
|
+
|
30
|
+
xml = `
|
31
|
+
<table id="producttable">
|
32
|
+
<thead>
|
33
|
+
<tr>
|
34
|
+
<td>UPC_Code</td>
|
35
|
+
<td>Product_Name</td>
|
36
|
+
</tr>
|
37
|
+
</thead>
|
38
|
+
<tbody>
|
39
|
+
<!-- existing data could optionally be included here -->
|
40
|
+
</tbody>
|
41
|
+
</table>
|
42
|
+
`
|
43
|
+
|
44
|
+
console.log("log")
|
45
|
+
console.log("log")
|
46
|
+
console.clear
|
47
|
+
|
48
|
+
console.log("log")
|
49
|
+
|
50
|
+
console.log
|
51
|
+
console.log(true)
|
52
|
+
console.log(false)
|
53
|
+
console.log(1)
|
54
|
+
console.log(1.1)
|
55
|
+
console.log(nil)
|
56
|
+
console.log("hello", "world")
|
57
|
+
console.log("hello", ["world"], "!")
|
58
|
+
|
59
|
+
console.info("info")
|
60
|
+
console.warn("warn")
|
61
|
+
console.error("error")
|
62
|
+
console.debug("debug")
|
63
|
+
|
64
|
+
console.assert(false, "assert")
|
65
|
+
console.assert(true, "assert")
|
66
|
+
|
67
|
+
console.count_reset("count")
|
68
|
+
|
69
|
+
3.times do
|
70
|
+
console.count("count")
|
71
|
+
end
|
72
|
+
console.count_reset("count")
|
73
|
+
console.count("count")
|
74
|
+
|
75
|
+
console.dir(href)
|
76
|
+
console.log(url)
|
77
|
+
|
78
|
+
console.dirxml(comp)
|
79
|
+
|
80
|
+
console.group
|
81
|
+
console.group("label")
|
82
|
+
console.log("a")
|
83
|
+
console.group_collapsed("label")
|
84
|
+
console.log("a")
|
85
|
+
console.log("a")
|
86
|
+
console.group_end
|
87
|
+
console.group_end
|
88
|
+
# console.group_end
|
89
|
+
|
90
|
+
puts console.red
|
91
|
+
|
92
|
+
puts "is red?"
|
93
|
+
|
94
|
+
console.table(arr)
|
95
|
+
console.info(arr)
|
96
|
+
|
97
|
+
console.table(url)
|
98
|
+
console.table(href)
|
99
|
+
console.table(comp)
|
100
|
+
|
101
|
+
console.time_end("time")
|
102
|
+
console.time("time")
|
103
|
+
|
104
|
+
30.times do
|
105
|
+
sleep 0.001
|
106
|
+
console.time_log("time")
|
107
|
+
end
|
108
|
+
console.time_end("time")
|
109
|
+
console.time_log("time")
|
110
|
+
console.time_log("time")
|
111
|
+
|
112
|
+
def foo(c)
|
113
|
+
c.trace("foo")
|
114
|
+
def bar(c)
|
115
|
+
c.trace
|
116
|
+
end
|
117
|
+
bar(c)
|
118
|
+
end
|
119
|
+
|
120
|
+
foo(console)
|
data/lib/libconsole/version.rb
CHANGED
data/lib/libconsole.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative "libconsole/version"
|
4
4
|
require_relative "libconsole/ci/github"
|
5
|
+
require_relative "libconsole/lang/js"
|
5
6
|
|
6
7
|
module Libconsole
|
7
8
|
class Error < StandardError; end
|
@@ -10,4 +11,8 @@ module Libconsole
|
|
10
11
|
class Github
|
11
12
|
extend Libconsole::CI::Github
|
12
13
|
end
|
14
|
+
|
15
|
+
class JS
|
16
|
+
extend Libconsole::Lang::JS
|
17
|
+
end
|
13
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libconsole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- initdc
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Console inspired from JavaScript, Github Actions, Linux...
|
14
14
|
email:
|
@@ -27,7 +27,9 @@ files:
|
|
27
27
|
- Rakefile
|
28
28
|
- lib/libconsole.rb
|
29
29
|
- lib/libconsole/ci/github.rb
|
30
|
+
- lib/libconsole/color.rb
|
30
31
|
- lib/libconsole/lang/js.rb
|
32
|
+
- lib/libconsole/lang/js_test.rb
|
31
33
|
- lib/libconsole/version.rb
|
32
34
|
- libconsole.gemspec
|
33
35
|
- sig/libconsole.rbs
|