libconsole 0.2.4 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/libconsole/lang/js.rb +21 -19
- data/lib/libconsole/lang/js_test.rb +5 -3
- data/lib/libconsole/linux/raw.rb +138 -0
- data/lib/libconsole/linux/raw_test.rb +99 -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: 8b15a342a1353468f85eb9fd89ff7e0393c7c19f71590210fdc8337bcaca9273
|
4
|
+
data.tar.gz: 19006150fef4ea6da45e44802b189e63eece3a5ca355f49a78f75db20914e3e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b95d57cb1d7c960ea78ea79586f36dfb4530aa042af2a6f3b6a443d6efabaf29deec973b26add3444b86e6598ce506c76e618214103cdd8b56330b7b0c7c197
|
7
|
+
data.tar.gz: 7f926879dc1798b3fadc39d8806179ba507d3d1c9d63bfd4e82ac74422675d3d02fe64e53e2eb116c00864dea978d879984886950859fb688e041cf09958b21c
|
data/Gemfile.lock
CHANGED
data/lib/libconsole/lang/js.rb
CHANGED
@@ -74,18 +74,18 @@ module Libconsole
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def count(label = "default")
|
77
|
-
@count_state[
|
78
|
-
@count_state[
|
79
|
-
pre_puts "#{label}: #{@count_state[
|
77
|
+
@count_state[label.to_sym] = 0 unless @count_state[label.to_sym]
|
78
|
+
@count_state[label.to_sym] += 1
|
79
|
+
pre_puts "#{label}: #{@count_state[label.to_sym]}"
|
80
80
|
end
|
81
81
|
|
82
82
|
def count_reset(label = "default")
|
83
|
-
unless @count_state[
|
83
|
+
unless @count_state[label.to_sym]
|
84
84
|
pre_puts "Count for '#{label}' does not exist"
|
85
85
|
return
|
86
86
|
end
|
87
|
-
@count_state[
|
88
|
-
pre_puts "#{label}: #{@count_state[
|
87
|
+
@count_state[label.to_sym] = 0
|
88
|
+
pre_puts "#{label}: #{@count_state[label.to_sym]}"
|
89
89
|
end
|
90
90
|
|
91
91
|
def dir(*argv)
|
@@ -123,35 +123,37 @@ module Libconsole
|
|
123
123
|
end
|
124
124
|
|
125
125
|
def time(label = "default")
|
126
|
-
if @time_start_state[
|
126
|
+
if @time_start_state[label.to_sym]
|
127
127
|
pre_puts yellow("Timer '#{label}' already exists")
|
128
128
|
else
|
129
129
|
# https://docs.ruby-lang.org/en/master/Time.html#method-i-tv_usec
|
130
|
-
@time_start_state[
|
130
|
+
@time_start_state[label.to_sym] = Time.now
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
134
|
def time_end(label = "default")
|
135
|
-
unless @time_start_state[
|
135
|
+
unless @time_start_state[label.to_sym]
|
136
136
|
pre_puts "Timer '#{label}' does not exist"
|
137
137
|
return
|
138
138
|
end
|
139
|
-
|
140
|
-
|
141
|
-
range_ms = (
|
142
|
-
|
143
|
-
|
139
|
+
start = @time_start_state[label.to_sym]
|
140
|
+
finish = Time.now
|
141
|
+
range_ms = (finish.tv_sec - start.tv_sec) * 1000 + (finish.tv_nsec - start.tv_nsec) * 1e-6
|
142
|
+
range_fmt = format("%.6f", range_ms)
|
143
|
+
pre_puts "#{label}: #{range_fmt} ms - timer ended"
|
144
|
+
@time_start_state[label.to_sym] = nil
|
144
145
|
end
|
145
146
|
|
146
147
|
def time_log(label = "default")
|
147
|
-
unless @time_start_state[
|
148
|
+
unless @time_start_state[label.to_sym]
|
148
149
|
pre_puts "Timer '#{label}' does not exist"
|
149
150
|
return
|
150
151
|
end
|
151
|
-
|
152
|
-
|
153
|
-
range_ms = (
|
154
|
-
|
152
|
+
start = @time_start_state[label.to_sym]
|
153
|
+
finish = Time.now
|
154
|
+
range_ms = (finish.tv_sec - start.tv_sec) * 1000 + (finish.tv_nsec - start.tv_nsec) * 1e-6
|
155
|
+
range_fmt = format("%.6f", range_ms)
|
156
|
+
pre_puts "#{label}: #{range_fmt} ms"
|
155
157
|
end
|
156
158
|
|
157
159
|
def trace(*argv)
|
@@ -100,12 +100,14 @@ console.table(comp)
|
|
100
100
|
|
101
101
|
console.time_end("time")
|
102
102
|
console.time("time")
|
103
|
-
|
104
|
-
|
105
|
-
sleep
|
103
|
+
console.time
|
104
|
+
61.times do
|
105
|
+
sleep 1
|
106
106
|
console.time_log("time")
|
107
107
|
end
|
108
|
+
console.time_log
|
108
109
|
console.time_end("time")
|
110
|
+
console.time_log
|
109
111
|
console.time_log("time")
|
110
112
|
console.time_log("time")
|
111
113
|
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Libconsole
|
4
|
+
module Linux
|
5
|
+
module Raw
|
6
|
+
def default
|
7
|
+
@debug = false
|
8
|
+
@count_state = {}
|
9
|
+
@time_start_state = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def pre_puts(argv, level = nil)
|
13
|
+
pre = if level.instance_of?(String)
|
14
|
+
"[#{level.center(6)}] "
|
15
|
+
elsif level.instance_of?(0.1.class)
|
16
|
+
# https://docs.ruby-lang.org/en/master/format_specifications_rdoc.html
|
17
|
+
time = format("%.6f", level)
|
18
|
+
t_size = time.size
|
19
|
+
size = t_size > 12 ? t_size : 12
|
20
|
+
"[#{time.rjust(size)}] "
|
21
|
+
end
|
22
|
+
str = argv.instance_of?(Array) ? argv.join(": ") : argv
|
23
|
+
puts _prefix(pre, str)
|
24
|
+
end
|
25
|
+
private :pre_puts
|
26
|
+
|
27
|
+
# dmesg -h
|
28
|
+
#
|
29
|
+
# Supported log levels (priorities):
|
30
|
+
# emerg - system is unusable
|
31
|
+
# alert - action must be taken immediately
|
32
|
+
# crit - critical conditions
|
33
|
+
# err - error conditions
|
34
|
+
# warn - warning conditions
|
35
|
+
# notice - normal but significant condition
|
36
|
+
# info - informational
|
37
|
+
# debug - debug-level messages
|
38
|
+
def info(*argv)
|
39
|
+
pre_puts argv, "info"
|
40
|
+
end
|
41
|
+
|
42
|
+
def notice(*argv)
|
43
|
+
pre_puts argv, "noti"
|
44
|
+
end
|
45
|
+
|
46
|
+
def warn(*argv)
|
47
|
+
pre_puts argv, "warn"
|
48
|
+
end
|
49
|
+
|
50
|
+
def err(*argv)
|
51
|
+
pre_puts argv, "erro"
|
52
|
+
end
|
53
|
+
|
54
|
+
def crit(*argv)
|
55
|
+
pre_puts argv, "crit"
|
56
|
+
end
|
57
|
+
|
58
|
+
def alert(*argv)
|
59
|
+
pre_puts argv, "aler"
|
60
|
+
end
|
61
|
+
|
62
|
+
def emerg(*argv)
|
63
|
+
pre_puts argv, "emer"
|
64
|
+
end
|
65
|
+
|
66
|
+
def debug(*argv)
|
67
|
+
pre_puts argv, "debu" if @debug
|
68
|
+
end
|
69
|
+
|
70
|
+
def assert(assertion = false, *args)
|
71
|
+
pre_puts args, "asse" unless assertion
|
72
|
+
end
|
73
|
+
|
74
|
+
def clear
|
75
|
+
!Gem.win_platform? ? (system "clear") : (system "cls")
|
76
|
+
end
|
77
|
+
|
78
|
+
def count(*argv)
|
79
|
+
label = argv.empty? ? "default" : argv.shift
|
80
|
+
@count_state[label.to_sym] = 0 unless @count_state[label.to_sym]
|
81
|
+
@count_state[label.to_sym] += 1
|
82
|
+
pre_puts [label, @count_state[label.to_sym], argv], "coun"
|
83
|
+
end
|
84
|
+
|
85
|
+
def count_reset(*argv)
|
86
|
+
label = argv.empty? ? "default" : argv.shift
|
87
|
+
unless @count_state[label.to_sym]
|
88
|
+
pre_puts "Count for '#{label}' does not exist", "warn"
|
89
|
+
return
|
90
|
+
end
|
91
|
+
@count_state[label.to_sym] = 0
|
92
|
+
pre_puts [label, @count_state[label.to_sym], argv], "coun"
|
93
|
+
end
|
94
|
+
|
95
|
+
def time(*argv)
|
96
|
+
label = argv.empty? ? "default" : argv.shift
|
97
|
+
if @time_start_state[label.to_sym]
|
98
|
+
pre_puts "Timer '#{label}' already exists", "warn"
|
99
|
+
else
|
100
|
+
@time_start_state[label.to_sym] = Time.now
|
101
|
+
pre_puts [label, argv], 0.0
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def time_end(*argv)
|
106
|
+
label = argv.empty? ? "default" : argv.shift
|
107
|
+
unless @time_start_state[label.to_sym]
|
108
|
+
pre_puts "Timer '#{label}' does not exist", "warn"
|
109
|
+
return
|
110
|
+
end
|
111
|
+
start = @time_start_state[label.to_sym]
|
112
|
+
finish = Time.now
|
113
|
+
range = (finish.tv_sec - start.tv_sec) + (finish.tv_nsec - start.tv_nsec) * 1e-9
|
114
|
+
pre_puts [label, "timer ended", argv], range
|
115
|
+
@time_start_state[label.to_sym] = nil
|
116
|
+
end
|
117
|
+
|
118
|
+
def time_log(*argv)
|
119
|
+
label = argv.empty? ? "default" : argv.shift
|
120
|
+
unless @time_start_state[label.to_sym]
|
121
|
+
pre_puts "Timer '#{label}' does not exist", "warn"
|
122
|
+
return
|
123
|
+
end
|
124
|
+
start = @time_start_state[label.to_sym]
|
125
|
+
finish = Time.now
|
126
|
+
range = (finish.tv_sec - start.tv_sec) + (finish.tv_nsec - start.tv_nsec) * 1e-9
|
127
|
+
pre_puts [label, argv], range
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
def _prefix(pre, args)
|
133
|
+
args unless pre
|
134
|
+
%(#{pre}#{args})
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "raw"
|
4
|
+
|
5
|
+
class MyClass
|
6
|
+
include Libconsole::Linux::Raw
|
7
|
+
end
|
8
|
+
|
9
|
+
linux = MyClass.new
|
10
|
+
linux.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
|
+
linux.info("log")
|
45
|
+
linux.info("log")
|
46
|
+
linux.clear
|
47
|
+
|
48
|
+
linux.info("log")
|
49
|
+
|
50
|
+
linux.info
|
51
|
+
linux.info(true)
|
52
|
+
linux.info(false)
|
53
|
+
linux.info(1)
|
54
|
+
linux.info(1.1)
|
55
|
+
linux.info(nil)
|
56
|
+
linux.info("hello", "world")
|
57
|
+
linux.info("hello", ["world"], "!")
|
58
|
+
|
59
|
+
linux.info("info")
|
60
|
+
linux.warn("warn")
|
61
|
+
linux.err("err")
|
62
|
+
linux.notice("notice")
|
63
|
+
linux.crit("crit")
|
64
|
+
linux.alert("alert")
|
65
|
+
linux.emerg("emerg")
|
66
|
+
|
67
|
+
linux.assert(false, "assert")
|
68
|
+
linux.assert(true, "assert")
|
69
|
+
|
70
|
+
linux.count_reset("count")
|
71
|
+
linux.count
|
72
|
+
|
73
|
+
3.times do
|
74
|
+
linux.count("count")
|
75
|
+
end
|
76
|
+
linux.count_reset("count")
|
77
|
+
linux.count("count", "bb", "cc")
|
78
|
+
|
79
|
+
linux.time_end("time")
|
80
|
+
linux.time("time")
|
81
|
+
|
82
|
+
linux.count_reset
|
83
|
+
linux.time
|
84
|
+
linux.time_log
|
85
|
+
|
86
|
+
arr = []
|
87
|
+
|
88
|
+
61.times do
|
89
|
+
linux.time_log("time", arr)
|
90
|
+
# fork { linux.count }
|
91
|
+
sleep 1
|
92
|
+
arr.push("a") if arr.size < 10
|
93
|
+
# Process.wait
|
94
|
+
end
|
95
|
+
|
96
|
+
linux.time_end("time")
|
97
|
+
linux.time_log
|
98
|
+
linux.time_log("time")
|
99
|
+
linux.time_log
|
data/lib/libconsole/version.rb
CHANGED
data/lib/libconsole.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require_relative "libconsole/version"
|
4
4
|
require_relative "libconsole/ci/github"
|
5
5
|
require_relative "libconsole/lang/js"
|
6
|
+
require_relative "libconsole/linux/raw"
|
6
7
|
|
7
8
|
module Libconsole
|
8
9
|
class Error < StandardError; end
|
@@ -15,4 +16,8 @@ module Libconsole
|
|
15
16
|
class JS
|
16
17
|
extend Libconsole::Lang::JS
|
17
18
|
end
|
19
|
+
|
20
|
+
class Raw
|
21
|
+
extend Libconsole::Linux::Raw
|
22
|
+
end
|
18
23
|
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.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- initdc
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Console inspired from JavaScript, Github Actions, Linux...
|
14
14
|
email:
|
@@ -30,6 +30,8 @@ files:
|
|
30
30
|
- lib/libconsole/color.rb
|
31
31
|
- lib/libconsole/lang/js.rb
|
32
32
|
- lib/libconsole/lang/js_test.rb
|
33
|
+
- lib/libconsole/linux/raw.rb
|
34
|
+
- lib/libconsole/linux/raw_test.rb
|
33
35
|
- lib/libconsole/version.rb
|
34
36
|
- libconsole.gemspec
|
35
37
|
- sig/libconsole.rbs
|