termclock 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/termclock +46 -4
- data/lib/termclock.rb +1 -1
- data/lib/termclock/parse_characters.rb +45 -10
- data/lib/termclock/{main.rb → start.rb} +14 -7
- data/lib/termclock/string.rb +17 -3
- data/lib/termclock/system_info.rb +17 -9
- data/lib/termclock/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a889b38c921c98e808156b9feeee5dccb8ad10952a17f2b591ed14b6297f2075
|
4
|
+
data.tar.gz: 2676b0ba7b8ad4d2b604282845d2fe4d7101eb5a0c39d076833195e6ada67bfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04e505fe18c33d49dcc050e3bf06a2ef2484c38b4b0b6b3d5f00ccb47a5551973641621411304342e3314b8255893db00aef62b775fecac001726347e80f5045
|
7
|
+
data.tar.gz: b7c740f14ee7df1ed1c4c4774f0696eb20c84850eec4b402a8fde75f6864bf6a068465a114680095dd5453fb00bcf33a08c4607a46efefa535dcb033cda8e556
|
data/exe/termclock
CHANGED
@@ -6,23 +6,54 @@ if ARGV.any? { |x| x[/\A\-(\-help|h)\z/] }
|
|
6
6
|
puts <<~EOF
|
7
7
|
TermClock: A clock that runs on the LinuxTerminal!
|
8
8
|
|
9
|
-
|
9
|
+
\e[1;4mArguments:\e[0m
|
10
|
+
|
11
|
+
1. Help and Version:\e[0m
|
10
12
|
--help|-h\t\t\tShows this help section
|
11
|
-
--
|
13
|
+
--version|-v\t\t\tShows termclock version
|
14
|
+
|
15
|
+
2. Style:\e[0m
|
16
|
+
--bold|-b\t\t\tMake texts bold
|
17
|
+
--italic|-i\t\t\tMake texts italic
|
12
18
|
--character=|char=\t\tDraws specified character
|
13
19
|
--clean\t\t\t\tJust run the clean bare clock
|
14
20
|
--colour=|-c=\t\t\tSpecify hex colour (4 colours)
|
15
21
|
\t\t\t\t[ with or without # ]
|
22
|
+
|
23
|
+
3. Information:\e[0m
|
16
24
|
--no-date|-nd\t\t\tShows no date
|
17
25
|
--no-message|-nm\t\tShows no messages
|
18
26
|
--no-sysinfo|-ni\t\tShows no system info
|
19
27
|
--refresh|r\t\t\tSpecify delay or refresh time
|
20
28
|
--text-colour|-tc\t\tSpecify text colour (2 colours)
|
29
|
+
|
30
|
+
4. Formats:\e[0m
|
31
|
+
--date-format=|-df=\t\tSpecify the date format
|
32
|
+
\t\t\t\t[ Run date --help for formats ]
|
33
|
+
--time-format=|-tf=\t\tSpecify the time format
|
34
|
+
\t\t\t\t[ Run date --help for formats ]
|
35
|
+
|
36
|
+
Supported characters are 0 - 9, a - z, /, \\, !, %, and |.
|
37
|
+
|
38
|
+
This is Termclock v#{Termclock::VERSION}
|
21
39
|
EOF
|
22
40
|
|
23
41
|
exit 0
|
24
42
|
end
|
25
43
|
|
44
|
+
if ARGV.any? { |x| x[/\A\-(-version|v)\z/] }
|
45
|
+
colour = [
|
46
|
+
[[255, 100, 100], [100, 100, 255]],
|
47
|
+
[[60, 230, 180], [100, 100, 255]],
|
48
|
+
[[255, 255, 0], [100, 100, 255]],
|
49
|
+
[[255, 80, 170], [255, 200, 0]],
|
50
|
+
].sample
|
51
|
+
|
52
|
+
colour.reverse! if rand < 0.5
|
53
|
+
puts "This is Termclock v#{Termclock::VERSION}".gradient(*colour)
|
54
|
+
exit 0
|
55
|
+
end
|
56
|
+
|
26
57
|
begin
|
27
58
|
print "\e[?25l"
|
28
59
|
|
@@ -49,10 +80,18 @@ begin
|
|
49
80
|
_refresh_time = ARGV.find { |x| x[/\A\-(\-refresh|r)=.*\z/] } &.split(?=) &.at(1)
|
50
81
|
refresh_time = _refresh_time ? _refresh_time.to_f : 0.1
|
51
82
|
|
83
|
+
_time_format = ARGV.find { |x| x[/\A\-(\-time\-format|tf)=.*\z/] } &.split(?=) &.at(1)
|
84
|
+
time_format = _time_format ? _time_format : "%H %M %S %2N"
|
85
|
+
|
86
|
+
_date_format = ARGV.find { |x| x[/\A\-(\-date\-format|df)=.*\z/] } &.split(?=) &.at(1)
|
87
|
+
date_format = _date_format ? _date_format : "'%a, %d %B %Y'"
|
88
|
+
|
52
89
|
text_colours = ARGV.find { |x| x[/\A\-(\-text\-colour|tc)=.*\z/] } &.split(?=) &.at(1) &.split(?,)
|
53
90
|
abort("Text colours need 2 colours. Example: -tc=55f,3ce3b5") if text_colours && text_colours.length != 2
|
54
91
|
|
55
|
-
bold = ARGV.any? { |x| x[/\A
|
92
|
+
bold = ARGV.any? { |x| x[/\A\-(\-bold|b)\z/] }
|
93
|
+
italic = ARGV.any? { |x| x[/\A\-(\-italic|i)\z/] }
|
94
|
+
|
56
95
|
no_print_info = ARGV.any? { |x| x[/\A\-(\-no\-sysinfo|ni)\z/] }
|
57
96
|
no_print_message = ARGV.any? { |x| x[/\A\-(\-no\-message|nm)\z/] }
|
58
97
|
no_print_date = ARGV.any? { |x| x[/\A\-(\-no\-date|nd)\z/] }
|
@@ -68,9 +107,12 @@ begin
|
|
68
107
|
*text_colours,
|
69
108
|
sleep: refresh_time,
|
70
109
|
bold: bold,
|
110
|
+
italic: italic,
|
71
111
|
print_info: !no_print_info,
|
72
112
|
print_message: !no_print_message,
|
73
|
-
print_date: !no_print_date
|
113
|
+
print_date: !no_print_date,
|
114
|
+
time_format: time_format,
|
115
|
+
date_format: date_format
|
74
116
|
)
|
75
117
|
rescue Interrupt, SignalException
|
76
118
|
print "\e[H\e[2J\e[3J"
|
data/lib/termclock.rb
CHANGED
@@ -12,6 +12,6 @@ end
|
|
12
12
|
require_relative "termclock/string"
|
13
13
|
require_relative "termclock/parse_characters"
|
14
14
|
require_relative "termclock/system_info"
|
15
|
-
require_relative "termclock/
|
15
|
+
require_relative "termclock/start"
|
16
16
|
require_relative "termclock/hex2rgb"
|
17
17
|
require_relative "termclock/version"
|
@@ -142,9 +142,9 @@ module Termclock
|
|
142
142
|
|
143
143
|
# I
|
144
144
|
````````
|
145
|
-
|
146
|
-
|
147
|
-
|
145
|
+
\s\s\s``
|
146
|
+
\s\s\s``
|
147
|
+
\s\s\s``
|
148
148
|
````````
|
149
149
|
|
150
150
|
# J
|
@@ -235,8 +235,8 @@ module Termclock
|
|
235
235
|
`` ``
|
236
236
|
`` ``
|
237
237
|
`` ``
|
238
|
-
|
239
|
-
|
238
|
+
\s`` ``\s
|
239
|
+
\s\s\s``
|
240
240
|
|
241
241
|
# W
|
242
242
|
`` ``
|
@@ -246,11 +246,11 @@ module Termclock
|
|
246
246
|
````````
|
247
247
|
|
248
248
|
# X
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
249
|
+
`` ``
|
250
|
+
\s`` ``
|
251
|
+
\s\s\s``
|
252
|
+
\s`` ``
|
253
|
+
`` ``
|
254
254
|
|
255
255
|
# Y
|
256
256
|
`` ``
|
@@ -265,6 +265,41 @@ module Termclock
|
|
265
265
|
``
|
266
266
|
``
|
267
267
|
````````
|
268
|
+
|
269
|
+
# /
|
270
|
+
\s\s\s\s\s``\s
|
271
|
+
\s\s\s\s``\s\s
|
272
|
+
\s\s\s``\s\s\s
|
273
|
+
\s\s``\s\s\s\s
|
274
|
+
\s``\s\s\s\s\s
|
275
|
+
|
276
|
+
# \\
|
277
|
+
\s``\s\s\s\s\s
|
278
|
+
\s\s``\s\s\s\s
|
279
|
+
\s\s\s``\s\s\s
|
280
|
+
\s\s\s\s``\s\s
|
281
|
+
\s\s\s\s\s``\s
|
282
|
+
|
283
|
+
# %
|
284
|
+
\s\s\s\s\s``\s
|
285
|
+
``\s\s``\s\s
|
286
|
+
\s\s\s``\s\s\s
|
287
|
+
\s\s``\s\s``
|
288
|
+
\s``\s\s\s\s\s
|
289
|
+
|
290
|
+
# |
|
291
|
+
\s\s\s``\s\s\s
|
292
|
+
\s\s\s``\s\s\s
|
293
|
+
\s\s\s``\s\s\s
|
294
|
+
\s\s\s``\s\s\s
|
295
|
+
\s\s\s``\s\s\s
|
296
|
+
|
297
|
+
# !
|
298
|
+
\s\s\s``\s\s\s
|
299
|
+
\s\s\s``\s\s\s
|
300
|
+
\s\s\s``\s\s\s
|
301
|
+
\s\s\s\s\s\s\s\s
|
302
|
+
\s\s\s``\s\s\s
|
268
303
|
EOF
|
269
304
|
|
270
305
|
class << self
|
@@ -3,8 +3,11 @@ module Termclock
|
|
3
3
|
textcolour1 = nil, textcolour2 = nil,
|
4
4
|
sleep: 0.1,
|
5
5
|
bold: false,
|
6
|
+
italic: false,
|
6
7
|
print_info: true, print_message: true,
|
7
|
-
print_date: true
|
8
|
+
print_date: true,
|
9
|
+
time_format: "%H %M %S %2N",
|
10
|
+
date_format: '%a, %d %B %Y'
|
8
11
|
)
|
9
12
|
|
10
13
|
generate = proc do |start, stop, n = 5|
|
@@ -112,24 +115,28 @@ module Termclock
|
|
112
115
|
end
|
113
116
|
end
|
114
117
|
|
115
|
-
message_final = message.rjust(message_align).+(_caret).gradient(
|
118
|
+
message_final = message.rjust(message_align).+(_caret).gradient(
|
119
|
+
tc1, tc2, exclude_spaces: true, bold: bold, italic: italic
|
120
|
+
)
|
116
121
|
end
|
117
122
|
|
118
123
|
if print_info
|
119
|
-
info = system_info(width
|
124
|
+
info = system_info(width).gradient(
|
125
|
+
tc1, tc2, bold: bold, italic: italic
|
126
|
+
)
|
120
127
|
end
|
121
128
|
|
122
129
|
if print_date
|
123
|
-
date = time_now.strftime(
|
124
|
-
.gradient(tc1, tc2, bold: bold)
|
130
|
+
date = time_now.strftime(date_format).center(width)
|
131
|
+
.gradient(tc1, tc2, bold: bold, italic: italic)
|
125
132
|
end
|
126
133
|
|
127
|
-
time = time_now.strftime(
|
134
|
+
time = time_now.strftime(time_format).split.join(splitter)
|
128
135
|
art = Termclock::ParseCharacters.display(time).lines
|
129
136
|
|
130
137
|
art_aligned = art.each_with_index do |x, i|
|
131
138
|
chomped = x.chomp(''.freeze).+(NEWLINE)
|
132
|
-
gr = chomped.gradient(*colours[i], bold: bold)
|
139
|
+
gr = chomped.gradient(*colours[i], bold: bold, italic: italic)
|
133
140
|
x.replace(SPACE.*(width./(2.0).-(chomped.length / 2.0).abs.to_i + 1) + gr)
|
134
141
|
end.join
|
135
142
|
|
data/lib/termclock/string.rb
CHANGED
@@ -3,7 +3,12 @@ class String
|
|
3
3
|
SPACE = ?\s.freeze
|
4
4
|
TAB = ?\t.freeze
|
5
5
|
|
6
|
-
def gradient(*all_rgbs,
|
6
|
+
def gradient(*all_rgbs,
|
7
|
+
bg: false,
|
8
|
+
exclude_spaces: false,
|
9
|
+
bold: false, italic: false, blink: false
|
10
|
+
)
|
11
|
+
|
7
12
|
temp = ''
|
8
13
|
|
9
14
|
r, g, b = all_rgbs[0]
|
@@ -12,7 +17,18 @@ class String
|
|
12
17
|
|
13
18
|
init = bg ? 48 : 38
|
14
19
|
|
20
|
+
style = nil
|
21
|
+
if bold || italic
|
22
|
+
style = "\e["
|
23
|
+
style << '1;'.freeze if bold
|
24
|
+
style << '3;'.freeze if italic
|
25
|
+
style.chop!
|
26
|
+
style << 'm'.freeze
|
27
|
+
end
|
28
|
+
|
15
29
|
each_line do |c|
|
30
|
+
temp << style if style
|
31
|
+
|
16
32
|
_r, _g, _b = r, g, b
|
17
33
|
chomped = !!c.chomp!(''.freeze)
|
18
34
|
|
@@ -49,8 +65,6 @@ class String
|
|
49
65
|
_g = _g.send(g_op, g_val * -1) if g_op
|
50
66
|
_b = _b.send(b_op, b_val * -1) if b_op
|
51
67
|
|
52
|
-
temp << "\e[1m" if bold
|
53
|
-
|
54
68
|
i = -1
|
55
69
|
while (i += 1) < len
|
56
70
|
_c = c[i]
|
@@ -2,11 +2,11 @@ module Termclock
|
|
2
2
|
@@cpu_usage = 0
|
3
3
|
@@cpu_usage_t = Thread.new { }.join
|
4
4
|
|
5
|
-
@@current_net_usage =
|
5
|
+
@@current_net_usage = "\u{1F4CA} Curr. DL/UL:"
|
6
6
|
@@current_net_usage_t = Thread.new { }.join
|
7
7
|
|
8
8
|
class << self
|
9
|
-
def system_info(width
|
9
|
+
def system_info(width)
|
10
10
|
unless @@cpu_usage_t.alive?
|
11
11
|
@@cpu_usage_t = Thread.new { @@cpu_usage = LS::CPU.usage(0.25) }
|
12
12
|
end
|
@@ -57,17 +57,25 @@ module Termclock
|
|
57
57
|
" / #{LS::PrettifyBytes.convert_short_binary(_m[:total].to_i)}"\
|
58
58
|
" (#{_m[:used].to_i*(100).fdiv(_m[:total].to_i).round(2)}%)"
|
59
59
|
|
60
|
-
|
60
|
+
pt = LS::Process.types.values
|
61
|
+
|
62
|
+
process = "\u{1F9EE} Process: T:#{sprintf "%4s", LS::Process.count}|"\
|
63
|
+
"R:#{sprintf "%3s", pt.count(:running)}|"\
|
64
|
+
"S:#{sprintf "%3s", pt.count(:sleeping)}|"\
|
65
|
+
"I:#{sprintf "%3s", pt.count(:idle)}"
|
66
|
+
|
67
|
+
os = "\u{1F427} Distrib: #{LS::OS.distribution} #{LS::OS.machine} (#{LS::OS.version})"
|
61
68
|
|
62
69
|
max_l = [hostname, process, ip, battery, @@current_net_usage, net_usage].map(&:length).max + 4
|
63
70
|
|
64
|
-
<<~
|
71
|
+
<<~STR
|
65
72
|
\s#{user}#{SPACE.*(width.-(user.length + max_l).abs)}#{hostname}
|
66
|
-
\s#{
|
67
|
-
\s#{
|
68
|
-
\s#{
|
69
|
-
\s#{
|
70
|
-
|
73
|
+
\s#{os}#{SPACE.*(width.-(os.length + max_l).abs)}#{battery}
|
74
|
+
\s#{cpu}#{SPACE.*(width.-(cpu.length + max_l).abs)}#{ip}
|
75
|
+
\s#{memory}#{SPACE.*(width.-(memory.length + max_l).abs)}#{@@current_net_usage}
|
76
|
+
\s#{swap}#{SPACE.*(width.-(swap.length + max_l).abs)}#{net_usage}
|
77
|
+
\s#{fs}#{SPACE.*(width.-(fs.length + max_l).abs)}#{process}
|
78
|
+
STR
|
71
79
|
end
|
72
80
|
end
|
73
81
|
end
|
data/lib/termclock/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: termclock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sourav Goswami
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: linux_stat
|
@@ -35,8 +35,8 @@ files:
|
|
35
35
|
- exe/termclock
|
36
36
|
- lib/termclock.rb
|
37
37
|
- lib/termclock/hex2rgb.rb
|
38
|
-
- lib/termclock/main.rb
|
39
38
|
- lib/termclock/parse_characters.rb
|
39
|
+
- lib/termclock/start.rb
|
40
40
|
- lib/termclock/string.rb
|
41
41
|
- lib/termclock/system_info.rb
|
42
42
|
- lib/termclock/version.rb
|