termclock 0.4.0 → 0.5.0
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/exe/termclock +25 -14
- data/lib/termclock.rb +2 -0
- data/lib/termclock/start.rb +30 -31
- data/lib/termclock/system_info.rb +53 -27
- 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: 7bdab290cda29c688c44fb92516f6b5438d5d64dd9ad240cd2c33f648fbb6ea6
|
4
|
+
data.tar.gz: 0137ffaf7141499d18134b9b2d9334b4e37675f401e4b01d01ff0bfc55d8e509
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd583ba7e1a2896ed7dbf4be664f4cecf5dcc1c136ceca207da1e38978db16c0b884684d02d3577da7af73a7e20a3ee1ad5e6448af5668823c66571cf8fe85b9
|
7
|
+
data.tar.gz: 5ee71483b7c1d0e70c5c87e8f4913b7fc0d7786c2f5a3f2d5b8617b8eff79a53ef5d183db8210556835d76367836b2c9c94a50e571b0b29e2399604cef2357ca
|
data/exe/termclock
CHANGED
@@ -14,11 +14,12 @@ def version(logo_colour)
|
|
14
14
|
_v[vl_2..-1].gradient(logo_colour[1], logo_colour[2], underline: true, bold: true)
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
unless STDOUT.tty?
|
18
|
+
IO.undef_method(:winsize)
|
19
|
+
IO.define_method(:winsize) { [100, 100] }
|
20
|
+
end
|
21
|
+
|
22
|
+
LOGO_COLOUR = %w(ff0 f55 55f).map(&Termclock.method(:hex2rgb))
|
22
23
|
|
23
24
|
if ARGV.any? { |x| x[/\A\-(\-help|h)\z/] }
|
24
25
|
puts <<~EOF
|
@@ -36,36 +37,42 @@ if ARGV.any? { |x| x[/\A\-(\-help|h)\z/] }
|
|
36
37
|
--character=|char=\t\tDraws specified character
|
37
38
|
--clean\t\t\t\tJust run the clean bare clock
|
38
39
|
--colour=|-c=\t\t\tSpecify hex colour (4 colours)
|
39
|
-
|
40
|
-
|
41
|
-
\
|
40
|
+
--text-colour=|-tc=\t\tSpecify text colour (2 colours)
|
41
|
+
|
42
|
+
\u2B22 \e[3mColours has to be hex, 3 or 6 characters with or
|
43
|
+
without the leading # in front\e[0m
|
42
44
|
|
43
45
|
\e[1m3. Information:\e[0m
|
44
46
|
--no-date|-nd\t\t\tShows no date
|
45
47
|
--no-message|-nm\t\tShows no messages
|
46
48
|
--no-sysinfo|-ni\t\tShows no system info
|
47
|
-
--refresh
|
49
|
+
--refresh=|r=\t\t\tSpecify delay or refresh time
|
48
50
|
--no-logo|-nl\t\t\tDon't show the logo at the bottom
|
49
51
|
|
50
|
-
\e[1m4.
|
52
|
+
\e[1m4. Antiflicker:\e[0m
|
53
|
+
--antiflicker|-af\t\tDon't flicker terminal
|
54
|
+
|
55
|
+
\u2B22 \e[3mIf refresh time is low or terminal is slow, use this option\e[0m
|
56
|
+
|
57
|
+
\e[1m5. Formats:\e[0m
|
51
58
|
--date-format=|-df=\t\tSpecify the date format
|
52
59
|
--time-format=|-tf=\t\tSpecify the time format
|
53
60
|
|
54
61
|
Usually the format looks like this:
|
55
62
|
%H:%M:%S:%2N or %d %B, %Y
|
56
63
|
|
57
|
-
\e[3mRun `date --help` to know more formats\e[0m
|
64
|
+
\u2B22 \e[3mRun `date --help` to know more formats\e[0m
|
58
65
|
|
59
66
|
Supported characters are 0 - 9, a - z, /, \\, !, %, and |.
|
60
67
|
|
61
|
-
#{version(
|
68
|
+
#{version(LOGO_COLOUR)}
|
62
69
|
EOF
|
63
70
|
|
64
71
|
exit 0
|
65
72
|
end
|
66
73
|
|
67
74
|
if ARGV.any? { |x| x[/\A\-(-version|v)\z/] }
|
68
|
-
puts version(
|
75
|
+
puts version(LOGO_COLOUR)
|
69
76
|
exit 0
|
70
77
|
end
|
71
78
|
|
@@ -106,6 +113,7 @@ begin
|
|
106
113
|
|
107
114
|
bold = ARGV.any? { |x| x[/\A\-(\-bold|b)\z/] }
|
108
115
|
italic = ARGV.any? { |x| x[/\A\-(\-italic|i)\z/] }
|
116
|
+
anti_flicker = ARGV.any? { |x| x[/\A\-(\-antiflicker|af)\z/] }
|
109
117
|
|
110
118
|
no_print_info = ARGV.any? { |x| x[/\A\-(\-no\-sysinfo|ni)\z/] }
|
111
119
|
no_logo = ARGV.any? { |x| x[/\A\-(\-no\-logo|nl)\z/] }
|
@@ -137,10 +145,13 @@ begin
|
|
137
145
|
no_logo: no_logo,
|
138
146
|
time_format: time_format,
|
139
147
|
date_format: date_format,
|
140
|
-
logo_colour:
|
148
|
+
logo_colour: LOGO_COLOUR,
|
149
|
+
anti_flicker: anti_flicker
|
141
150
|
)
|
142
151
|
rescue Interrupt, SignalException
|
143
152
|
print "\e[H\e[2J\e[3J"
|
153
|
+
# rescue Errno::ENOTTY
|
154
|
+
# abort "This should be run on a TTY! Also please don't pipe or redirect the output!"
|
144
155
|
ensure
|
145
156
|
print "\e[?25h"
|
146
157
|
end
|
data/lib/termclock.rb
CHANGED
data/lib/termclock/start.rb
CHANGED
@@ -9,9 +9,12 @@ module Termclock
|
|
9
9
|
time_format: "%H %M %S %2N",
|
10
10
|
date_format: '%a, %d %B %Y',
|
11
11
|
no_logo: false,
|
12
|
+
anti_flicker: false,
|
12
13
|
logo_colour: [Termclock.hex2rgb('ff0'), Termclock.hex2rgb('f55'), Termclock.hex2rgb('55f')]
|
13
14
|
)
|
14
15
|
|
16
|
+
clear_character = anti_flicker ? ANTIFLICKER : CLEAR
|
17
|
+
|
15
18
|
generate = proc do |start, stop, n = 5|
|
16
19
|
r_op = r_val = nil
|
17
20
|
ary = []
|
@@ -31,8 +34,7 @@ module Termclock
|
|
31
34
|
ary
|
32
35
|
end
|
33
36
|
|
34
|
-
gc_compact, gc_compacted = GC.respond_to?(:compact), Time.now.to_i +
|
35
|
-
print CLEAR
|
37
|
+
gc_compact, gc_compacted = GC.respond_to?(:compact), Time.now.to_i + GC_COMPACT_TIME
|
36
38
|
|
37
39
|
r1, g1, b1 = *colour1
|
38
40
|
r2, g2, b2 = *colour2
|
@@ -58,19 +60,11 @@ module Termclock
|
|
58
60
|
tc1 = textcolour1 ? hex2rgb(textcolour1) : hex2rgb('5555ff')
|
59
61
|
tc2 = textcolour2 ? hex2rgb(textcolour2) : hex2rgb('3ce3b5')
|
60
62
|
|
61
|
-
cpu_usage = 0
|
62
|
-
cpu_usage_t = Thread.new { }
|
63
|
-
|
64
|
-
current_net_usage = ''
|
65
|
-
current_net_usage_t = Thread.new { }
|
66
|
-
|
67
|
-
message_time = Time.now.to_i - 5
|
68
63
|
message_counter = -1
|
69
64
|
message = ''
|
70
65
|
message_final = ''
|
71
66
|
message_align = 0
|
72
67
|
message_temp = ''
|
73
|
-
point_five_tick = 0
|
74
68
|
|
75
69
|
date, info = '', ''
|
76
70
|
|
@@ -114,22 +108,25 @@ module Termclock
|
|
114
108
|
chop_message = 0
|
115
109
|
deviation = 0
|
116
110
|
|
111
|
+
time_seperators = [?:, ?$]
|
112
|
+
time_seperator = time_seperators[0]
|
113
|
+
point_five_tick = -0.5
|
114
|
+
|
115
|
+
height, width = *STDOUT.winsize
|
116
|
+
height2, width2 = *STDOUT.winsize
|
117
|
+
|
118
|
+
print CLEAR
|
119
|
+
|
117
120
|
while true
|
118
121
|
monotonic_time_1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
119
122
|
time_now = Time.now
|
120
123
|
height, width = *STDOUT.winsize
|
121
124
|
|
122
|
-
if time_now.to_f
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
end
|
128
|
-
else
|
129
|
-
unless point_five_tick == 0
|
130
|
-
point_five_tick = 0
|
131
|
-
splitter = ?$.freeze
|
132
|
-
end
|
125
|
+
if time_now.to_f > point_five_tick
|
126
|
+
point_five_tick = time_now.to_f + 0.5
|
127
|
+
time_seperators.rotate!
|
128
|
+
clock_emoji.rotate!
|
129
|
+
time_seperator = time_seperators[0]
|
133
130
|
end
|
134
131
|
|
135
132
|
unless no_logo
|
@@ -167,18 +164,14 @@ module Termclock
|
|
167
164
|
)
|
168
165
|
end
|
169
166
|
|
170
|
-
if print_info
|
171
|
-
info = system_info(width).gradient(
|
172
|
-
tc1, tc2, bold: bold, italic: italic
|
173
|
-
)
|
174
|
-
end
|
167
|
+
info = system_info(width, tc1, tc2, bold, italic) if print_info
|
175
168
|
|
176
169
|
if print_date
|
177
170
|
date = time_now.strftime(date_format).center(width)
|
178
171
|
.gradient(tc1, tc2, bold: bold, italic: italic, exclude_spaces: true)
|
179
172
|
end
|
180
173
|
|
181
|
-
time = time_now.strftime(time_format).split.join(
|
174
|
+
time = time_now.strftime(time_format).split.join(time_seperator)
|
182
175
|
art = Termclock::ParseCharacters.display(time).lines
|
183
176
|
|
184
177
|
art_aligned = art.each_with_index do |x, i|
|
@@ -192,21 +185,27 @@ module Termclock
|
|
192
185
|
end.join
|
193
186
|
|
194
187
|
vertical_gap = "\e[#{height./(2.0).-(art.length / 2.0).to_i + 1}H"
|
188
|
+
final_output = "#{info}#{vertical_gap}#{art_aligned}\n#{date}\n\n\e[K#{message_final}#{term_clock_v}"
|
189
|
+
|
190
|
+
if anti_flicker && (height != height2 || width != width2)
|
191
|
+
height2, width2 = *STDOUT.winsize
|
192
|
+
print CLEAR
|
193
|
+
end
|
195
194
|
|
196
|
-
print "#{
|
195
|
+
print "#{clear_character}#{final_output}"
|
197
196
|
|
198
197
|
if gc_compact && time_now.to_i > gc_compacted
|
199
198
|
GC.compact
|
200
|
-
gc_compacted = time_now.to_i +
|
199
|
+
gc_compacted = time_now.to_i + GC_COMPACT_TIME
|
201
200
|
end
|
202
201
|
|
203
202
|
monotonic_time_2 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
204
203
|
time_diff = monotonic_time_2 - monotonic_time_1
|
205
|
-
sleep_time = refresh.-(time_diff +
|
204
|
+
sleep_time = refresh.-(time_diff + deviation)
|
206
205
|
sleep_time = 0 if sleep_time < 0
|
207
206
|
|
208
|
-
deviation = Process.clock_gettime(Process::CLOCK_MONOTONIC) - monotonic_time_2
|
209
207
|
sleep(sleep_time)
|
208
|
+
deviation = Process.clock_gettime(Process::CLOCK_MONOTONIC).-(monotonic_time_2 + sleep_time + EPSILON)
|
210
209
|
end
|
211
210
|
end
|
212
211
|
end
|
@@ -6,7 +6,7 @@ module Termclock
|
|
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, tc1, tc2, bold, italic)
|
10
10
|
unless @@cpu_usage_t.alive?
|
11
11
|
@@cpu_usage_t = Thread.new {
|
12
12
|
_cpu_usage = LS::CPU.usage(0.25)
|
@@ -20,14 +20,14 @@ module Termclock
|
|
20
20
|
@@current_net_usage_t = Thread.new do
|
21
21
|
_m = LS::Net.current_usage(0.25)
|
22
22
|
|
23
|
-
_dl = LS::PrettifyBytes.convert_short_decimal(_m[:received]
|
24
|
-
_ul = LS::PrettifyBytes.convert_short_decimal(_m[:transmitted]
|
23
|
+
_dl = LS::PrettifyBytes.convert_short_decimal(_m[:received])
|
24
|
+
_ul = LS::PrettifyBytes.convert_short_decimal(_m[:transmitted])
|
25
25
|
|
26
|
-
@@current_net_usage = "\u{1F4CA} Curr. DL/UL: #{
|
26
|
+
@@current_net_usage = "\u{1F4CA} Curr. DL/UL: #{"%-9s" % _dl} | #{ "%9s" % _ul}"
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
cpu = "\u{1F9E0} CPU: #{
|
30
|
+
cpu = "\u{1F9E0} CPU: #{"%6s" % @@cpu_usage}% (#{LS::CPU.count_online}/#{LS::CPU.count})"
|
31
31
|
|
32
32
|
battery = if LS::Battery.present?
|
33
33
|
stat = LS::Battery.stat
|
@@ -48,45 +48,44 @@ module Termclock
|
|
48
48
|
_m = LS::Net.total_bytes
|
49
49
|
ip = "\u{1F30F} IP Addr: #{LS::Net.ipv4_private}"
|
50
50
|
|
51
|
-
net_usage = "\u{1F4C8} Totl. DL/UL: #{
|
52
|
-
" | #{
|
51
|
+
net_usage = "\u{1F4C8} Totl. DL/UL: #{"%-9s" % LS::PrettifyBytes.convert_short_decimal(_m[:received])}"\
|
52
|
+
" | #{"%9s" % LS::PrettifyBytes.convert_short_decimal(_m[:transmitted])}"
|
53
53
|
|
54
54
|
_m = LS::Memory.stat
|
55
55
|
_m.default = 0
|
56
56
|
|
57
57
|
memory = "\u{1F3B0} Mem: #{LS::PrettifyBytes.convert_short_decimal(_m[:used] * 1000)}"\
|
58
58
|
" / #{LS::PrettifyBytes.convert_short_decimal(_m[:total] * 1000)}"\
|
59
|
-
" (#{_m[:percent_used]}%)"
|
59
|
+
" (#{"%.2f" % _m[:percent_used]}%)"
|
60
60
|
|
61
61
|
_m = LS::Swap.stat
|
62
62
|
_m.default = 0
|
63
63
|
|
64
64
|
swap = "\u{1F300} Swap: #{LS::PrettifyBytes.convert_short_decimal(_m[:used] * 1000)}"\
|
65
65
|
" / #{LS::PrettifyBytes.convert_short_decimal(_m[:total] * 1000)}"\
|
66
|
-
" (#{_m[:percent_used]}%)"
|
66
|
+
" (#{"%.2f" % _m[:percent_used]}%)"
|
67
67
|
|
68
68
|
_m = LS::Filesystem.stat('/')
|
69
69
|
_m.default = 0
|
70
70
|
|
71
71
|
fs = "\u{1F4BD} FS: #{LS::PrettifyBytes.convert_short_decimal(_m[:used])}"\
|
72
72
|
" / #{LS::PrettifyBytes.convert_short_decimal(_m[:total])}"\
|
73
|
-
" (#{_m[:used].*(100).fdiv(_m[:total]).round(2)}%)"
|
73
|
+
" (#{"%.2f" % _m[:used].*(100).fdiv(_m[:total]).round(2)}%)"
|
74
74
|
|
75
75
|
pt = LS::Process.types.values
|
76
76
|
|
77
|
-
process = "\u{1F9EE} Process: T:#{
|
78
|
-
"R:#{
|
79
|
-
"S:#{
|
80
|
-
"I:#{
|
77
|
+
process = "\u{1F9EE} Process: T:#{"%4s" % pt.length}|"\
|
78
|
+
"R:#{"%3s" % pt.count(:running)}|"\
|
79
|
+
"S:#{"%3s" % pt.count(:sleeping)}|"\
|
80
|
+
"I:#{"%3s" % pt.count(:idle)}"
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
" (#{_os_v})"
|
82
|
+
@@os_v ||= unless LS::OS.version.empty?
|
83
|
+
" (#{LS::OS.version})"
|
85
84
|
else
|
86
85
|
EMPTY
|
87
86
|
end
|
88
87
|
|
89
|
-
os
|
88
|
+
@@os ||= "\u{1F427} Distrib: #{LS::OS.distribution} #{LS::OS.machine}#{@@os_v}"
|
90
89
|
|
91
90
|
_uptime = LS::OS.uptime
|
92
91
|
_second = _uptime[:second]
|
@@ -99,28 +98,55 @@ module Termclock
|
|
99
98
|
|
100
99
|
uptime = "\u{1F3A1} Uptime: #{hour}:#{minute}:#{second}:#{ms} (#{LS::OS.uptime_i}s)"
|
101
100
|
|
102
|
-
_loadavg = LS::Sysinfo.loads.map! { |x|
|
101
|
+
_loadavg = LS::Sysinfo.loads.map! { |x| "%.2f" % x }
|
103
102
|
loadavg = "\u{1F9FA} LoadAvg: 1m #{_loadavg[0]}|5m #{_loadavg[1]}|15m #{_loadavg[2]}"
|
104
103
|
|
105
|
-
all_info = [
|
104
|
+
all_info = []
|
105
|
+
max_l = 0
|
106
|
+
i = -1
|
107
|
+
|
108
|
+
[
|
106
109
|
user, hostname,
|
107
|
-
os, battery,
|
110
|
+
@@os, battery,
|
108
111
|
cpu, ip,
|
109
112
|
memory, @@current_net_usage,
|
110
113
|
swap, net_usage,
|
111
114
|
fs, process,
|
112
115
|
uptime, loadavg
|
113
|
-
].
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
116
|
+
].each { |x|
|
117
|
+
unless x.empty?
|
118
|
+
all_info << x
|
119
|
+
i += 1
|
120
|
+
|
121
|
+
if i.odd?
|
122
|
+
_x_len = x.length
|
123
|
+
max_l = _x_len if max_l < _x_len
|
124
|
+
end
|
125
|
+
end
|
118
126
|
}
|
119
127
|
|
120
128
|
max_l += 4
|
121
129
|
|
122
130
|
all_info.each_slice(2).map { |x, y|
|
123
|
-
|
131
|
+
_diff = width.-(x.length + max_l)
|
132
|
+
_diff = 0 if _diff < 1
|
133
|
+
y_to_s = y.to_s
|
134
|
+
|
135
|
+
padding = "#{SPACE * _diff}"
|
136
|
+
str = SPACE + x + padding + y_to_s
|
137
|
+
|
138
|
+
grads = SPACE + x.gradient(tc1, tc2, bold: bold, italic: italic) +
|
139
|
+
padding +
|
140
|
+
y_to_s.gradient(tc1, tc2, bold: bold, italic: italic)
|
141
|
+
|
142
|
+
len = str.chars.map { |x|
|
143
|
+
_x = x.bytesize./(2)
|
144
|
+
_x == 0 ? 1 : _x
|
145
|
+
}.sum
|
146
|
+
|
147
|
+
w = width - 2
|
148
|
+
|
149
|
+
len < w ? grads.+(SPACE.*(w - len)) : grads
|
124
150
|
}.join(NEWLINE)
|
125
151
|
end
|
126
152
|
end
|
data/lib/termclock/version.rb
CHANGED