termclock 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/termclock +1 -0
- data/lib/termclock.rb +9 -0
- data/lib/termclock/main.rb +7 -11
- data/lib/termclock/parse_characters.rb +1 -2
- data/lib/termclock/string.rb +6 -2
- data/lib/termclock/system_info.rb +7 -7
- data/lib/termclock/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0916f4a4beb06eae575611343e1235e5fa9a0585116fd9694622d1a5e9867938'
|
4
|
+
data.tar.gz: 53f9236790df604fe8eb5f0c1a4d0cb5ed0179c6aed3c04da4ae8b26398269ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f85098f0082eca3776b0349b65a34323491c8372cf2b426c91bedde2d5031be210da5fe49d36f773a95afdc9fc6907bbcc9b7e1e3d5e863624106d8e4112ac8f
|
7
|
+
data.tar.gz: a116f54e530fdfcecfc7f415812aa107bddd7e98409090acbd2f039aefccf0db937f47a8f441d5fa35b1fbe75974ff8795745d3a63da28187c85f275090fb24e
|
data/exe/termclock
CHANGED
@@ -8,6 +8,7 @@ if ARGV.any? { |x| x[/\A\-(\-help|h)\z/] }
|
|
8
8
|
|
9
9
|
Arguments:
|
10
10
|
--help|-h\t\t\tShows this help section
|
11
|
+
--bold\t\t\t\tMake texts bold
|
11
12
|
--character=|char=\t\tDraws specified character
|
12
13
|
--clean\t\t\t\tJust run the clean bare clock
|
13
14
|
--colour=|-c=\t\t\tSpecify hex colour (4 colours)
|
data/lib/termclock.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
require 'linux_stat'
|
2
2
|
require 'io/console'
|
3
|
+
|
4
|
+
module Termclock
|
5
|
+
COLOURTERM = ENV.key?('COLORTERM')
|
6
|
+
CLEAR = COLOURTERM ? "\e[H\e[2J\e[3J" : "\e[H"
|
7
|
+
NEWLINE = ?\n.freeze
|
8
|
+
SPACE = ?\s.freeze
|
9
|
+
TAB = ?\t.freeze
|
10
|
+
end
|
11
|
+
|
3
12
|
require_relative "termclock/string"
|
4
13
|
require_relative "termclock/parse_characters"
|
5
14
|
require_relative "termclock/system_info"
|
data/lib/termclock/main.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
module Termclock
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
textcolour2 = nil, sleep: 0.1, bold: false,
|
2
|
+
def self.start(colour1, colour2, colour3, colour4,
|
3
|
+
textcolour1 = nil, textcolour2 = nil,
|
4
|
+
sleep: 0.1,
|
5
|
+
bold: false,
|
7
6
|
print_info: true, print_message: true,
|
8
7
|
print_date: true
|
9
|
-
|
10
|
-
|
11
|
-
newline = ?\n.freeze
|
12
|
-
space = ?\s.freeze
|
8
|
+
)
|
13
9
|
|
14
10
|
generate = proc do |start, stop, n = 5|
|
15
11
|
r_op = r_val = nil
|
@@ -132,9 +128,9 @@ module Termclock
|
|
132
128
|
art = Termclock::ParseCharacters.display(time).lines
|
133
129
|
|
134
130
|
art_aligned = art.each_with_index do |x, i|
|
135
|
-
chomped = x.chomp(''.freeze).+(
|
131
|
+
chomped = x.chomp(''.freeze).+(NEWLINE)
|
136
132
|
gr = chomped.gradient(*colours[i], bold: bold)
|
137
|
-
x.replace(
|
133
|
+
x.replace(SPACE.*(width./(2.0).-(chomped.length / 2.0).abs.to_i + 1) + gr)
|
138
134
|
end.join
|
139
135
|
|
140
136
|
vertical_gap = "\e[#{height./(2.0).-(art.length / 2.0).to_i + 1}H"
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Termclock
|
2
2
|
module ParseCharacters
|
3
|
-
NEWLINE = ?\n.freeze
|
4
3
|
CHARACTERS = <<~EOF.freeze
|
5
4
|
# 0
|
6
5
|
````````
|
@@ -293,7 +292,7 @@ module Termclock
|
|
293
292
|
|
294
293
|
if stripped
|
295
294
|
replace_with = x.chars.map { |y|
|
296
|
-
chars = arg.chars.rotate(-1) if y ==
|
295
|
+
chars = arg.chars.rotate(-1) if y == NEWLINE
|
297
296
|
next(y) if y != stripped
|
298
297
|
chars.rotate!(1)[0]
|
299
298
|
}.join
|
data/lib/termclock/string.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
class String
|
2
|
+
NEWLINE = ?\n.freeze
|
3
|
+
SPACE = ?\s.freeze
|
4
|
+
TAB = ?\t.freeze
|
5
|
+
|
2
6
|
def gradient(*all_rgbs, bg: false, exclude_spaces: false, bold: false)
|
3
7
|
temp = ''
|
4
8
|
|
@@ -51,7 +55,7 @@ class String
|
|
51
55
|
while (i += 1) < len
|
52
56
|
_c = c[i]
|
53
57
|
|
54
|
-
if !exclude_spaces || (exclude_spaces && !(_c ==
|
58
|
+
if !exclude_spaces || (exclude_spaces && !(_c == SPACE || _c == TAB))
|
55
59
|
_r = _r.send(r_op, r_val) if r_op
|
56
60
|
_g = _g.send(g_op, g_val) if g_op
|
57
61
|
_b = _b.send(b_op, b_val) if b_op
|
@@ -72,7 +76,7 @@ class String
|
|
72
76
|
ret = if !c.empty?
|
73
77
|
chomped ? "\e[0m\n".freeze : "\e[0m".freeze
|
74
78
|
elsif chomped
|
75
|
-
|
79
|
+
NEWLINE
|
76
80
|
end
|
77
81
|
|
78
82
|
temp << ret
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Termclock
|
2
2
|
@@cpu_usage = 0
|
3
|
-
@@cpu_usage_t = Thread.new { }
|
3
|
+
@@cpu_usage_t = Thread.new { }.join
|
4
4
|
|
5
5
|
@@current_net_usage = ''
|
6
|
-
@@current_net_usage_t = Thread.new { }
|
6
|
+
@@current_net_usage_t = Thread.new { }.join
|
7
7
|
|
8
8
|
class << self
|
9
9
|
def system_info(width, tc1, tc2, bold)
|
@@ -62,11 +62,11 @@ module Termclock
|
|
62
62
|
max_l = [hostname, process, ip, battery, @@current_net_usage, net_usage].map(&:length).max + 4
|
63
63
|
|
64
64
|
<<~EOF.gradient(tc1, tc2, exclude_spaces: true, bold: bold)
|
65
|
-
\s#{user}#{
|
66
|
-
\s#{cpu}#{
|
67
|
-
\s#{memory}#{
|
68
|
-
\s#{swap}#{
|
69
|
-
\s#{fs}#{
|
65
|
+
\s#{user}#{SPACE.*(width.-(user.length + max_l).abs)}#{hostname}
|
66
|
+
\s#{cpu}#{SPACE.*(width.-(cpu.length + max_l).abs)}#{battery}
|
67
|
+
\s#{memory}#{SPACE.*(width.-(memory.length + max_l).abs)}#{ip}
|
68
|
+
\s#{swap}#{SPACE.*(width.-(swap.length + max_l).abs)}#{@@current_net_usage}
|
69
|
+
\s#{fs}#{SPACE.*(width.-(fs.length + max_l).abs)}#{net_usage}
|
70
70
|
EOF
|
71
71
|
end
|
72
72
|
end
|
data/lib/termclock/version.rb
CHANGED