termclock 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/termclock +47 -3
- data/lib/termclock.rb +1 -5
- data/lib/termclock/main.rb +59 -73
- data/lib/termclock/parse_characters.rb +145 -131
- data/lib/termclock/string.rb +3 -1
- data/lib/termclock/system_info.rb +73 -0
- data/lib/termclock/version.rb +1 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 173194900216341c3b17b0628a2e559c48bc1ae0f96fb72fd9c6d0f7be8e72d7
|
4
|
+
data.tar.gz: 62e24514caac359c68865c147bf95cd21bb5993b81c4793d52ed1270f125812f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41b1e7640c8874a8c12448d248d76a5f27e75b920704281e5ec4ef82399e049118b7ef6c44389460de20c6096f331e863cbf6666661f126e63eb1ced9208ac78
|
7
|
+
data.tar.gz: 90aa2e9ee036d1e02a2eb5dc98fed454663f053d906a7b45c7e8f0f30be95f0e80be73c2985abeeb2ad6f299e5f4479222ba16ac97a3a418127ee5551d7c3132
|
data/exe/termclock
CHANGED
@@ -1,7 +1,26 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'termclock'
|
3
|
+
$-v = nil
|
3
4
|
|
4
|
-
|
5
|
+
if ARGV.any? { |x| x[/\A\-(\-help|h)\z/] }
|
6
|
+
puts <<~EOF
|
7
|
+
TermClock: A clock that runs on the LinuxTerminal!
|
8
|
+
|
9
|
+
Arguments:
|
10
|
+
--help|-h\t\t\tShows this help section
|
11
|
+
--character=|char=\t\tDraws specified character
|
12
|
+
--clean\t\t\t\tJust run the clean bare clock
|
13
|
+
--colour=|-c=\t\t\tSpecify hex colour (4 colours)
|
14
|
+
\t\t\t\t[ with or without # ]
|
15
|
+
--no-date|-nd\t\t\tShows no date
|
16
|
+
--no-message|-nm\t\tShows no messages
|
17
|
+
--no-sysinfo|-ni\t\tShows no system info
|
18
|
+
--refresh|r\t\t\tSpecify delay or refresh time
|
19
|
+
--text-colour|-tc\t\tSpecify text colour (2 colours)
|
20
|
+
EOF
|
21
|
+
|
22
|
+
exit 0
|
23
|
+
end
|
5
24
|
|
6
25
|
begin
|
7
26
|
print "\e[?25l"
|
@@ -24,9 +43,34 @@ begin
|
|
24
43
|
}
|
25
44
|
|
26
45
|
chars = ARGV.find { |x| x[/\A\-(\-character|char)=.*\z/] } &.split(?=) &.at(1)
|
27
|
-
Termclock::ParseCharacters.transform_characters!(chars
|
46
|
+
Termclock::ParseCharacters.transform_characters!(*chars) if chars
|
47
|
+
|
48
|
+
_refresh_time = ARGV.find { |x| x[/\A\-(\-refresh|r)=.*\z/] } &.split(?=) &.at(1)
|
49
|
+
refresh_time = _refresh_time ? _refresh_time.to_f : 0.1
|
50
|
+
|
51
|
+
text_colours = ARGV.find { |x| x[/\A\-(\-text\-colour|tc)=.*\z/] } &.split(?=) &.at(1) &.split(?,)
|
52
|
+
abort("Text colours need 2 colours. Example: -tc=55f,3ce3b5") if text_colours && text_colours.length != 2
|
53
|
+
|
54
|
+
bold = ARGV.any? { |x| x[/\A\-\-bold\z/] }
|
55
|
+
no_print_info = ARGV.any? { |x| x[/\A\-(\-no\-sysinfo|ni)\z/] }
|
56
|
+
no_print_message = ARGV.any? { |x| x[/\A\-(\-no\-message|nm)\z/] }
|
57
|
+
no_print_date = ARGV.any? { |x| x[/\A\-(\-no\-date|nd)\z/] }
|
58
|
+
|
59
|
+
clean = ARGV.any? { |x| x[/\A\-(\-clean)\z/] }
|
60
|
+
|
61
|
+
if clean
|
62
|
+
no_print_info = no_print_message = no_print_date = true
|
63
|
+
end
|
28
64
|
|
29
|
-
Termclock.
|
65
|
+
Termclock.start(
|
66
|
+
*colours,
|
67
|
+
*text_colours,
|
68
|
+
sleep: refresh_time,
|
69
|
+
bold: bold,
|
70
|
+
print_info: !no_print_info,
|
71
|
+
print_message: !no_print_message,
|
72
|
+
print_date: !no_print_date
|
73
|
+
)
|
30
74
|
rescue Interrupt, SignalException
|
31
75
|
print "\e[H\e[2J\e[3J"
|
32
76
|
ensure
|
data/lib/termclock.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
COLOURTERM = ENV.key?('COLORTERM')
|
3
|
-
CLEAR = COLOURTERM ? "\e[H\e[2J\e[3J" : "\e[H"
|
4
|
-
$-n, $-s = ?\n, ?\s
|
5
|
-
|
6
1
|
require 'linux_stat'
|
7
2
|
require 'io/console'
|
8
3
|
require_relative "termclock/string"
|
9
4
|
require_relative "termclock/parse_characters"
|
5
|
+
require_relative "termclock/system_info"
|
10
6
|
require_relative "termclock/main"
|
11
7
|
require_relative "termclock/hex2rgb"
|
12
8
|
require_relative "termclock/version"
|
data/lib/termclock/main.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
module Termclock
|
2
|
-
|
2
|
+
COLOURTERM = ENV.key?('COLORTERM')
|
3
|
+
CLEAR = COLOURTERM ? "\e[H\e[2J\e[3J" : "\e[H"
|
4
|
+
|
5
|
+
def self.start(colour1, colour2, colour3, colour4, textcolour1 = nil,
|
6
|
+
textcolour2 = nil, sleep: 0.1, bold: false,
|
7
|
+
print_info: true, print_message: true,
|
8
|
+
print_date: true
|
9
|
+
)
|
10
|
+
|
3
11
|
newline = ?\n.freeze
|
4
12
|
space = ?\s.freeze
|
5
13
|
|
@@ -44,50 +52,47 @@ module Termclock
|
|
44
52
|
colours = [rs1, gs1, bs1].transpose.zip([rs2, gs2, bs2].transpose)
|
45
53
|
colours.unshift(colours[0])
|
46
54
|
colours.push(colours[-1])
|
55
|
+
|
56
|
+
# Text colours
|
57
|
+
tc1 = textcolour1 ? hex2rgb(textcolour1) : hex2rgb('5555ff')
|
58
|
+
tc2 = textcolour2 ? hex2rgb(textcolour2) : hex2rgb('3ce3b5')
|
59
|
+
|
47
60
|
cpu_usage = 0
|
48
61
|
cpu_usage_t = Thread.new { }
|
62
|
+
|
63
|
+
current_net_usage = ''
|
64
|
+
current_net_usage_t = Thread.new { }
|
65
|
+
|
49
66
|
message_time = Time.now.to_i - 5
|
67
|
+
message_counter = -1
|
50
68
|
message = ''
|
69
|
+
message_final = ''
|
51
70
|
message_temp = ''
|
52
71
|
caret = "\u2588"
|
53
72
|
|
73
|
+
date, info = '', ''
|
74
|
+
|
54
75
|
get_message = proc {
|
55
76
|
case Time.now.hour
|
56
|
-
when
|
77
|
+
when 5...12
|
57
78
|
"\u{1F304} Good Morning..."
|
58
79
|
when 12...16
|
59
80
|
"\u26C5 Good Afternoon..."
|
60
|
-
when 16...
|
61
|
-
"\u{
|
62
|
-
when
|
81
|
+
when 16...18
|
82
|
+
"\u{1F307} Good Evening..."
|
83
|
+
when 18...20
|
84
|
+
"\u{1F31F} Good Evening..."
|
85
|
+
when 20...24
|
63
86
|
"\u{1F303} Good Night..."
|
64
87
|
else
|
65
|
-
"\u{
|
88
|
+
"\u{2728} Good Night..."
|
66
89
|
end
|
67
90
|
}
|
68
91
|
|
69
|
-
i = -1
|
70
|
-
|
71
92
|
while true
|
72
|
-
i += 1
|
73
93
|
time_now = Time.now
|
74
94
|
height, width = *STDOUT.winsize
|
75
95
|
|
76
|
-
message_align = width - i % width + message.length / 2 - 4
|
77
|
-
|
78
|
-
if (width - i % width <= message.length)
|
79
|
-
message.replace(message[1..-1])
|
80
|
-
message_align = width - i % width + 4
|
81
|
-
else
|
82
|
-
message.clear if width - i % width == width
|
83
|
-
message_temp = get_message.call
|
84
|
-
|
85
|
-
if message_temp != message
|
86
|
-
message << message_temp[message.length..message.length + 1]
|
87
|
-
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
96
|
if time_now.to_f./(0.5).to_i.even?
|
92
97
|
splitter = ?:.freeze
|
93
98
|
_caret = caret
|
@@ -96,64 +101,45 @@ module Termclock
|
|
96
101
|
_caret = ''
|
97
102
|
end
|
98
103
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
104
|
+
if print_message
|
105
|
+
message_counter += 1
|
106
|
+
message_align = width - message_counter % width + message.length / 2 - 4
|
107
|
+
if (width - message_counter % width <= message.length)
|
108
|
+
message.replace(message[1..-1])
|
109
|
+
message_align = width - message_counter % width + 4
|
110
|
+
else
|
111
|
+
message.clear if width - message_counter % width == width
|
112
|
+
message_temp = get_message.call
|
113
|
+
|
114
|
+
if message_temp != message
|
115
|
+
message << message_temp[message.length..message.length + 1]
|
116
|
+
end
|
117
|
+
end
|
109
118
|
|
110
|
-
|
111
|
-
cpu_usage_t = Thread.new { cpu_usage = LS::CPU.usage(0.25) }
|
119
|
+
message_final = message.rjust(message_align).+(_caret).gradient(tc1, tc2, exclude_spaces: true, bold: bold)
|
112
120
|
end
|
113
121
|
|
114
|
-
|
115
|
-
|
116
|
-
battery = if LS::Battery.present?
|
117
|
-
stat = LS::Battery.stat
|
118
|
-
emoji = LS::Battery.charging? ? "\u{1F4A1}" : "\u{1F50B}"
|
119
|
-
"#{emoji} Battery: #{stat[:charge].to_i}% (#{stat[:status]})"
|
120
|
-
else
|
121
|
-
''.freeze
|
122
|
+
if print_info
|
123
|
+
info = system_info(width, tc1, tc2, bold)
|
122
124
|
end
|
123
125
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
_m = LS::Memory.stat
|
130
|
-
memory = "\u{1F3B0} Mem: #{LS::PrettifyBytes.convert_short_binary(_m[:used].to_i * 1024)}"\
|
131
|
-
" / #{LS::PrettifyBytes.convert_short_binary(_m[:total].to_i * 1024)}"\
|
132
|
-
" (#{_m[:percent_used]}%)"
|
133
|
-
|
134
|
-
_m = LS::Swap.stat
|
135
|
-
swap = "\u{1F300} Swap: #{LS::PrettifyBytes.convert_short_binary(_m[:used].to_i * 1024)}"\
|
136
|
-
" / #{LS::PrettifyBytes.convert_short_binary(_m[:total].to_i * 1024)}"\
|
137
|
-
" (#{_m[:percent_used]}%)"
|
138
|
-
|
139
|
-
_m = LS::Filesystem.stat
|
140
|
-
fs = "\u{1F4BD} FS: #{LS::PrettifyBytes.convert_short_binary(_m[:used].to_i)}"\
|
141
|
-
" / #{LS::PrettifyBytes.convert_short_binary(_m[:total].to_i)}"\
|
142
|
-
" (#{_m[:used].*(100).fdiv(_m[:total]).round(2)}%)"
|
126
|
+
if print_date
|
127
|
+
date = time_now.strftime('%a, %d %B %Y').center(width)
|
128
|
+
.gradient(tc1, tc2, bold: bold)
|
129
|
+
end
|
143
130
|
|
144
|
-
|
131
|
+
time = time_now.strftime('%H %M %S %2N').split.join(splitter)
|
132
|
+
art = Termclock::ParseCharacters.display(time).lines
|
145
133
|
|
146
|
-
|
134
|
+
art_aligned = art.each_with_index do |x, i|
|
135
|
+
chomped = x.chomp(''.freeze).+(newline)
|
136
|
+
gr = chomped.gradient(*colours[i], bold: bold)
|
137
|
+
x.replace(space.*(width./(2.0).-(chomped.length / 2.0).abs.to_i + 1) + gr)
|
138
|
+
end.join
|
147
139
|
|
148
|
-
|
149
|
-
\s#{cpu}#{?\s.*(width.-(cpu.length + max_l + 4).abs)}#{battery}
|
150
|
-
\s#{memory}#{?\s.*(width.-(memory.length + max_l + 4).abs)}#{ip}
|
151
|
-
\s#{swap}#{?\s.*(width.-(swap.length + max_l + 4).abs)}#{net_usage}
|
152
|
-
\s#{fs}#{?\s.*(width.-(fs.length + max_l + 4).abs)}#{process}
|
153
|
-
EOF
|
140
|
+
vertical_gap = "\e[#{height./(2.0).-(art.length / 2.0).to_i + 1}H"
|
154
141
|
|
155
|
-
print "#{CLEAR}#{info}#{
|
156
|
-
"#{message.rjust(message_align).+(_caret).gradient(*colours[1], exclude_spaces: true)}"
|
142
|
+
print "#{CLEAR}#{info}#{vertical_gap}#{art_aligned}\n#{date}\n\n#{message_final}"
|
157
143
|
|
158
144
|
if gc_compact && time_now.to_i > gc_compacted
|
159
145
|
GC.compact
|
@@ -3,81 +3,81 @@ module Termclock
|
|
3
3
|
NEWLINE = ?\n.freeze
|
4
4
|
CHARACTERS = <<~EOF.freeze
|
5
5
|
# 0
|
6
|
-
|
7
|
-
``
|
8
|
-
``
|
9
|
-
``
|
10
|
-
|
6
|
+
````````
|
7
|
+
`` ``
|
8
|
+
`` ``
|
9
|
+
`` ``
|
10
|
+
````````
|
11
11
|
|
12
12
|
# 1
|
13
13
|
``
|
14
|
-
|
14
|
+
`````
|
15
15
|
``
|
16
16
|
``
|
17
|
-
|
17
|
+
````````
|
18
18
|
|
19
19
|
# 2
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
````````
|
21
|
+
``
|
22
|
+
````````
|
23
23
|
``
|
24
|
-
|
24
|
+
````````
|
25
25
|
|
26
26
|
# 3
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
````````
|
28
|
+
``
|
29
|
+
````````
|
30
|
+
``
|
31
|
+
````````
|
32
32
|
|
33
33
|
# 4
|
34
|
-
``
|
35
|
-
``
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
`` ``
|
35
|
+
`` ``
|
36
|
+
````````
|
37
|
+
``
|
38
|
+
``
|
39
39
|
|
40
40
|
# 5
|
41
|
-
|
41
|
+
````````
|
42
42
|
``
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
````````
|
44
|
+
``
|
45
|
+
````````
|
46
46
|
|
47
47
|
# 6
|
48
|
-
|
48
|
+
````````
|
49
49
|
``
|
50
|
-
|
51
|
-
``
|
52
|
-
|
50
|
+
````````
|
51
|
+
`` ``
|
52
|
+
````````
|
53
53
|
|
54
54
|
# 7
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
````````
|
56
|
+
``
|
57
|
+
``
|
58
|
+
``
|
59
|
+
``
|
60
60
|
|
61
61
|
# 8
|
62
|
-
|
63
|
-
``
|
64
|
-
|
65
|
-
``
|
66
|
-
|
62
|
+
````````
|
63
|
+
`` ``
|
64
|
+
````````
|
65
|
+
`` ``
|
66
|
+
````````
|
67
67
|
|
68
68
|
# 9
|
69
|
-
|
70
|
-
``
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
````````
|
70
|
+
`` ``
|
71
|
+
````````
|
72
|
+
``
|
73
|
+
````````
|
74
74
|
|
75
75
|
# :
|
76
|
-
|
77
|
-
|
76
|
+
\u2B29\u2B29
|
77
|
+
\u2B29\u2B29
|
78
78
|
|
79
|
-
|
80
|
-
|
79
|
+
\u2B29\u2B29
|
80
|
+
\u2B29\u2B29
|
81
81
|
|
82
82
|
# $
|
83
83
|
\s\s
|
@@ -86,88 +86,88 @@ module Termclock
|
|
86
86
|
\s\s
|
87
87
|
\s\s
|
88
88
|
# A
|
89
|
-
|
90
|
-
``
|
91
|
-
|
92
|
-
``
|
93
|
-
``
|
89
|
+
````````
|
90
|
+
`` ``
|
91
|
+
````````
|
92
|
+
`` ``
|
93
|
+
`` ``
|
94
94
|
|
95
95
|
# B
|
96
|
-
|
97
|
-
``
|
98
|
-
|
99
|
-
``
|
100
|
-
|
96
|
+
````````
|
97
|
+
`` ``
|
98
|
+
````````
|
99
|
+
`` ``
|
100
|
+
````````
|
101
101
|
|
102
102
|
# C
|
103
|
-
|
103
|
+
````````
|
104
104
|
``
|
105
105
|
``
|
106
106
|
``
|
107
|
-
|
107
|
+
````````
|
108
108
|
|
109
109
|
# D
|
110
|
-
|
111
|
-
``
|
112
|
-
``
|
113
|
-
``
|
114
|
-
|
110
|
+
````````
|
111
|
+
`` ``
|
112
|
+
`` ``
|
113
|
+
`` ``
|
114
|
+
````````
|
115
115
|
|
116
116
|
# E
|
117
|
-
|
117
|
+
````````
|
118
118
|
``
|
119
|
-
|
119
|
+
````````
|
120
120
|
``
|
121
|
-
|
121
|
+
````````
|
122
122
|
|
123
123
|
# F
|
124
|
-
|
124
|
+
````````
|
125
125
|
``
|
126
|
-
|
126
|
+
````````
|
127
127
|
``
|
128
128
|
``
|
129
129
|
|
130
130
|
# G
|
131
|
-
|
131
|
+
````````
|
132
132
|
``
|
133
133
|
``
|
134
|
-
``
|
134
|
+
`` ````
|
135
135
|
````````
|
136
136
|
|
137
137
|
# H
|
138
|
-
``
|
139
|
-
``
|
140
|
-
|
141
|
-
``
|
142
|
-
``
|
138
|
+
`` ``
|
139
|
+
`` ``
|
140
|
+
````````
|
141
|
+
`` ``
|
142
|
+
`` ``
|
143
143
|
|
144
144
|
# I
|
145
|
-
|
145
|
+
````````
|
146
146
|
`
|
147
147
|
`
|
148
148
|
`
|
149
|
-
|
149
|
+
````````
|
150
150
|
|
151
151
|
# J
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
``
|
156
|
-
|
152
|
+
````````
|
153
|
+
``
|
154
|
+
``
|
155
|
+
`` ``
|
156
|
+
```````
|
157
157
|
|
158
158
|
# K
|
159
|
-
``
|
160
|
-
``
|
161
|
-
|
162
|
-
``
|
163
|
-
``
|
159
|
+
`` ``
|
160
|
+
`` ``
|
161
|
+
`````
|
162
|
+
`` ``
|
163
|
+
`` ``
|
164
164
|
|
165
165
|
# L
|
166
166
|
``
|
167
167
|
``
|
168
168
|
``
|
169
169
|
``
|
170
|
-
|
170
|
+
````````
|
171
171
|
|
172
172
|
# M
|
173
173
|
``` ```
|
@@ -177,11 +177,11 @@ module Termclock
|
|
177
177
|
`` ``
|
178
178
|
|
179
179
|
# N
|
180
|
-
````
|
181
|
-
``
|
182
|
-
``
|
183
|
-
``
|
184
|
-
``
|
180
|
+
```` ``
|
181
|
+
`` `` ``
|
182
|
+
`` `` ``
|
183
|
+
`` `` ``
|
184
|
+
`` ````
|
185
185
|
|
186
186
|
# O
|
187
187
|
````````
|
@@ -198,25 +198,25 @@ module Termclock
|
|
198
198
|
``
|
199
199
|
|
200
200
|
# Q
|
201
|
-
|
202
|
-
``
|
203
|
-
|
204
|
-
|
205
|
-
|
201
|
+
````````
|
202
|
+
`` ``
|
203
|
+
````````
|
204
|
+
``
|
205
|
+
``
|
206
206
|
|
207
207
|
# R
|
208
|
-
|
208
|
+
````````
|
209
|
+
`` ``
|
210
|
+
````````
|
211
|
+
`````
|
209
212
|
`` ``
|
210
|
-
```````
|
211
|
-
````
|
212
|
-
`` ``
|
213
213
|
|
214
214
|
# S
|
215
|
-
|
215
|
+
````````
|
216
216
|
``
|
217
|
-
|
218
|
-
|
219
|
-
|
217
|
+
````````
|
218
|
+
``
|
219
|
+
````````
|
220
220
|
|
221
221
|
# T
|
222
222
|
````````
|
@@ -226,32 +226,32 @@ module Termclock
|
|
226
226
|
``
|
227
227
|
|
228
228
|
# U
|
229
|
-
``
|
230
|
-
``
|
231
|
-
``
|
232
|
-
``
|
233
|
-
|
229
|
+
`` ``
|
230
|
+
`` ``
|
231
|
+
`` ``
|
232
|
+
`` ``
|
233
|
+
````````
|
234
234
|
|
235
235
|
# V
|
236
|
-
``
|
237
|
-
``
|
238
|
-
``
|
236
|
+
`` ``
|
237
|
+
`` ``
|
238
|
+
`` ``
|
239
239
|
`` ``
|
240
240
|
`
|
241
241
|
|
242
242
|
# W
|
243
|
-
``
|
244
|
-
``
|
245
|
-
``
|
246
|
-
``
|
247
|
-
|
243
|
+
`` ``
|
244
|
+
`` ``
|
245
|
+
`` ``
|
246
|
+
`` ` ``
|
247
|
+
````````
|
248
248
|
|
249
249
|
# X
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
250
|
+
` `
|
251
|
+
` `
|
252
|
+
`
|
253
|
+
` `
|
254
|
+
` `
|
255
255
|
|
256
256
|
# Y
|
257
257
|
`` ``
|
@@ -283,24 +283,38 @@ module Termclock
|
|
283
283
|
end.freeze
|
284
284
|
|
285
285
|
def transform_characters!(arg)
|
286
|
+
@@transformed ||= nil
|
287
|
+
fail RuntimeError, 'Characters already transformed!' if @@transformed
|
288
|
+
@@transformed ||= true
|
289
|
+
|
286
290
|
@@characters.values.each { |x|
|
287
291
|
stripped = x.strip[0]
|
288
|
-
|
292
|
+
chars = arg.chars.rotate(-1)
|
293
|
+
|
294
|
+
if stripped
|
295
|
+
replace_with = x.chars.map { |y|
|
296
|
+
chars = arg.chars.rotate(-1) if y == ?\n
|
297
|
+
next(y) if y != stripped
|
298
|
+
chars.rotate!(1)[0]
|
299
|
+
}.join
|
300
|
+
|
301
|
+
x.replace(replace_with)
|
302
|
+
end
|
289
303
|
}
|
290
304
|
end
|
291
305
|
|
292
306
|
def display(c)
|
293
|
-
j = [
|
307
|
+
j = []
|
294
308
|
|
295
|
-
c.upcase.
|
296
|
-
@@characters.fetch(x, x).split(
|
309
|
+
c.upcase.each_char { |x|
|
310
|
+
@@characters.fetch(x, x).split(NEWLINE)
|
297
311
|
.each_with_index { |z, i|
|
298
312
|
_j = j[i]
|
299
313
|
_j && _j << z || j[i] = z
|
300
314
|
}
|
301
315
|
}
|
302
316
|
|
303
|
-
j.join(
|
317
|
+
j.join(NEWLINE)
|
304
318
|
end
|
305
319
|
end
|
306
320
|
end
|
data/lib/termclock/string.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class String
|
2
|
-
def gradient(*all_rgbs, bg: false, exclude_spaces: false)
|
2
|
+
def gradient(*all_rgbs, bg: false, exclude_spaces: false, bold: false)
|
3
3
|
temp = ''
|
4
4
|
|
5
5
|
r, g, b = all_rgbs[0]
|
@@ -45,6 +45,8 @@ class String
|
|
45
45
|
_g = _g.send(g_op, g_val * -1) if g_op
|
46
46
|
_b = _b.send(b_op, b_val * -1) if b_op
|
47
47
|
|
48
|
+
temp << "\e[1m" if bold
|
49
|
+
|
48
50
|
i = -1
|
49
51
|
while (i += 1) < len
|
50
52
|
_c = c[i]
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Termclock
|
2
|
+
@@cpu_usage = 0
|
3
|
+
@@cpu_usage_t = Thread.new { }
|
4
|
+
|
5
|
+
@@current_net_usage = ''
|
6
|
+
@@current_net_usage_t = Thread.new { }
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def system_info(width, tc1, tc2, bold)
|
10
|
+
unless @@cpu_usage_t.alive?
|
11
|
+
@@cpu_usage_t = Thread.new { @@cpu_usage = LS::CPU.usage(0.25) }
|
12
|
+
end
|
13
|
+
|
14
|
+
unless @@current_net_usage_t.alive?
|
15
|
+
@@current_net_usage_t = Thread.new do
|
16
|
+
_m = LS::Net.current_usage(0.25)
|
17
|
+
|
18
|
+
_dl = LS::PrettifyBytes.convert_short_binary(_m[:received], precision: 0)
|
19
|
+
_ul = LS::PrettifyBytes.convert_short_binary(_m[:transmitted], precision: 0)
|
20
|
+
|
21
|
+
@@current_net_usage = "\u{1F4CA} Curr. DL/UL: #{sprintf "%-7s", _dl} | #{sprintf "%7s", _ul}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
cpu = "\u{1F9E0} CPU: #{sprintf "%5s", @@cpu_usage}% (#{LS::CPU.count_online} / #{LS::CPU.count})"
|
26
|
+
|
27
|
+
battery = if LS::Battery.present?
|
28
|
+
stat = LS::Battery.stat
|
29
|
+
emoji = LS::Battery.charging? ? "\u{1F4A1}" : "\u{1F50B}"
|
30
|
+
plug = LS::Battery.charging? ? "\u{1F50C} " : ''.freeze
|
31
|
+
"#{emoji} Battery: #{stat[:charge].to_i}% (#{plug}#{stat[:status]})"
|
32
|
+
else
|
33
|
+
''.freeze
|
34
|
+
end
|
35
|
+
|
36
|
+
user = "\u{1F481} User: #{LS::User.get_current_user.capitalize}"
|
37
|
+
hostname = "\u{1F4BB} Hostname: #{LS::OS.hostname}"
|
38
|
+
|
39
|
+
_m = LS::Net.total_bytes
|
40
|
+
ip = "\u{1F30F} IP Addr: #{LS::Net.ipv4_private}"
|
41
|
+
|
42
|
+
net_usage = "\u{1F4C8} Totl. DL/UL: #{sprintf "%-7s", LS::PrettifyBytes.convert_short_binary(_m[:received], precision: 0)}"\
|
43
|
+
" | #{sprintf "%7s", LS::PrettifyBytes.convert_short_binary(_m[:transmitted], precision: 0)}"
|
44
|
+
|
45
|
+
_m = LS::Memory.stat
|
46
|
+
memory = "\u{1F3B0} Mem: #{LS::PrettifyBytes.convert_short_binary(_m[:used].to_i * 1024)}"\
|
47
|
+
" / #{LS::PrettifyBytes.convert_short_binary(_m[:total].to_i * 1024)}"\
|
48
|
+
" (#{_m[:percent_used].to_i}%)"
|
49
|
+
|
50
|
+
_m = LS::Swap.stat
|
51
|
+
swap = "\u{1F300} Swap: #{LS::PrettifyBytes.convert_short_binary(_m[:used].to_i * 1024)}"\
|
52
|
+
" / #{LS::PrettifyBytes.convert_short_binary(_m[:total].to_i * 1024)}"\
|
53
|
+
" (#{_m[:percent_used].to_i}%)"
|
54
|
+
|
55
|
+
_m = LS::Filesystem.stat
|
56
|
+
fs = "\u{1F4BD} FS: #{LS::PrettifyBytes.convert_short_binary(_m[:used].to_i)}"\
|
57
|
+
" / #{LS::PrettifyBytes.convert_short_binary(_m[:total].to_i)}"\
|
58
|
+
" (#{_m[:used].to_i*(100).fdiv(_m[:total].to_i).round(2)}%)"
|
59
|
+
|
60
|
+
process = "\u{1F9EE} Process: #{LS::Process.count}"
|
61
|
+
|
62
|
+
max_l = [hostname, process, ip, battery, @@current_net_usage, net_usage].map(&:length).max + 4
|
63
|
+
|
64
|
+
<<~EOF.gradient(tc1, tc2, exclude_spaces: true, bold: bold)
|
65
|
+
\s#{user}#{?\s.*(width.-(user.length + max_l).abs)}#{hostname}
|
66
|
+
\s#{cpu}#{?\s.*(width.-(cpu.length + max_l).abs)}#{battery}
|
67
|
+
\s#{memory}#{?\s.*(width.-(memory.length + max_l).abs)}#{ip}
|
68
|
+
\s#{swap}#{?\s.*(width.-(swap.length + max_l).abs)}#{@@current_net_usage}
|
69
|
+
\s#{fs}#{?\s.*(width.-(fs.length + max_l).abs)}#{net_usage}
|
70
|
+
EOF
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/termclock/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: termclock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
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-
|
12
|
-
dependencies:
|
11
|
+
date: 2021-01-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: linux_stat
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.3.1
|
13
27
|
description: A clock for Linux VTE
|
14
28
|
email:
|
15
29
|
- souravgoswami@protonmail.com
|
@@ -24,6 +38,7 @@ files:
|
|
24
38
|
- lib/termclock/main.rb
|
25
39
|
- lib/termclock/parse_characters.rb
|
26
40
|
- lib/termclock/string.rb
|
41
|
+
- lib/termclock/system_info.rb
|
27
42
|
- lib/termclock/version.rb
|
28
43
|
homepage: https://github.com/souravgoswami/termclock
|
29
44
|
licenses:
|