libconsole 0.2.4 → 0.3.0
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/lib/libconsole/lang/js.rb +15 -15
- data/lib/libconsole/lang/js_test.rb +3 -1
- data/lib/libconsole/linux/raw.rb +136 -0
- data/lib/libconsole/linux/raw_test.rb +99 -0
- data/lib/libconsole/version.rb +1 -1
- data/lib/libconsole.rb +5 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf63cde4bc1e976d28f254c98725fba0806407e9edffdbb3412f765050794de4
|
4
|
+
data.tar.gz: 35ede5f6aedf9ef6bca5eeab18f80590599b2a21ca8242ef39282ab26cbb8fc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3810e38bed70d7de401d265207a68ac852fd4c7730af6fafe5d635c531d76514e18e0e67527e6d022a1d86535a50a0efeccc07e7e52ba1d96d1f05045daf473
|
7
|
+
data.tar.gz: 00ef216807f2429735cbbdac5e24cec81d7986a28e48ab809367e12ac14c294b002a3a5019778dbe5077070ccaae031ec206f8cecb3c0dda8ae7bda292bb78c0
|
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,34 +123,34 @@ 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
139
|
now = Time.now
|
140
|
-
range = now - @time_start_state[
|
141
|
-
range_ms = (range.to_f * 1000)
|
140
|
+
range = now - @time_start_state[label.to_sym]
|
141
|
+
range_ms = format("%.6f", range.to_f * 1000)
|
142
142
|
pre_puts "#{label}: #{range_ms} ms - timer ended"
|
143
|
-
@time_start_state[
|
143
|
+
@time_start_state[label.to_sym] = nil
|
144
144
|
end
|
145
145
|
|
146
146
|
def time_log(label = "default")
|
147
|
-
unless @time_start_state[
|
147
|
+
unless @time_start_state[label.to_sym]
|
148
148
|
pre_puts "Timer '#{label}' does not exist"
|
149
149
|
return
|
150
150
|
end
|
151
151
|
now = Time.now
|
152
|
-
range = now - @time_start_state[
|
153
|
-
range_ms = (range.to_f * 1000)
|
152
|
+
range = now - @time_start_state[label.to_sym]
|
153
|
+
range_ms = format("%.6f", range.to_f * 1000)
|
154
154
|
pre_puts "#{label}: #{range_ms} ms"
|
155
155
|
end
|
156
156
|
|
@@ -100,12 +100,14 @@ console.table(comp)
|
|
100
100
|
|
101
101
|
console.time_end("time")
|
102
102
|
console.time("time")
|
103
|
-
|
103
|
+
console.time
|
104
104
|
30.times do
|
105
105
|
sleep 0.001
|
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,136 @@
|
|
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
|
+
now = Time.now
|
112
|
+
range = now - @time_start_state[label.to_sym]
|
113
|
+
pre_puts [label, "timer ended", argv], range.to_f
|
114
|
+
@time_start_state[label.to_sym] = nil
|
115
|
+
end
|
116
|
+
|
117
|
+
def time_log(*argv)
|
118
|
+
label = argv.empty? ? "default" : argv.shift
|
119
|
+
unless @time_start_state[label.to_sym]
|
120
|
+
pre_puts "Timer '#{label}' does not exist", "warn"
|
121
|
+
return
|
122
|
+
end
|
123
|
+
now = Time.now
|
124
|
+
range = now - @time_start_state[label.to_sym]
|
125
|
+
pre_puts [label, argv], range.to_f
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
def _prefix(pre, args)
|
131
|
+
args unless pre
|
132
|
+
%(#{pre}#{args})
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
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
|
+
20.times do
|
89
|
+
linux.time_log("time", arr)
|
90
|
+
# fork { linux.count }
|
91
|
+
sleep 0.01
|
92
|
+
arr.push("a")
|
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,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libconsole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- initdc
|
@@ -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
|