termclock 0.1.5 → 0.4.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 +74 -6
- data/lib/termclock.rb +12 -2
- data/lib/termclock/hex2rgb.rb +1 -1
- data/lib/termclock/parse_characters.rb +184 -150
- data/lib/termclock/start.rb +212 -0
- data/lib/termclock/string.rb +26 -6
- data/lib/termclock/system_info.rb +90 -36
- data/lib/termclock/version.rb +1 -1
- metadata +5 -5
- data/lib/termclock/main.rb +0 -152
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97954b7ee94050e29c1d43619a147275d89a731d8e317e84af0afa59e6958961
|
4
|
+
data.tar.gz: f5b29cef16329eb7db1442a0073b32cdaef8563fa21abc9dca4d36de28925441
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e707c28bb571a7f6fe4655d0b9f24217361b64ff2489ee0f23d1475ecda543d85186bd6b8b476ae7247d088428baa2f424b4d0fafa507d1057bced4f626e708d
|
7
|
+
data.tar.gz: bdb1086fbb90979c98084f0fdcd8c4a0cbdf4ff689dd623d39c61079166a29525e2c07881b080838c3b0535a1c98c8db966f987253a6e9e14837f0700120c274
|
data/exe/termclock
CHANGED
@@ -1,27 +1,74 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'termclock'
|
3
3
|
$-v = nil
|
4
|
+
STDOUT.sync = true
|
5
|
+
|
6
|
+
def version(logo_colour)
|
7
|
+
emoji = ?🕐.ord.-(1).chr('utf-8')
|
8
|
+
Time.now.strftime('%I').to_i.times { emoji.next! }
|
9
|
+
|
10
|
+
_v = "#{emoji} This is Termclock v#{Termclock::VERSION}"
|
11
|
+
vl_2 = _v.length / 2
|
12
|
+
|
13
|
+
_v[0...vl_2].gradient(logo_colour[0], logo_colour[1], underline: true, bold: true) <<
|
14
|
+
_v[vl_2..-1].gradient(logo_colour[1], logo_colour[2], underline: true, bold: true)
|
15
|
+
end
|
16
|
+
|
17
|
+
logo_colour = [
|
18
|
+
%w(ff0 f55 55f),
|
19
|
+
%w(fa0 f5a 55f),
|
20
|
+
%w(3eb 55f 55f),
|
21
|
+
].sample.map(&Termclock.method(:hex2rgb))
|
4
22
|
|
5
23
|
if ARGV.any? { |x| x[/\A\-(\-help|h)\z/] }
|
6
24
|
puts <<~EOF
|
7
25
|
TermClock: A clock that runs on the LinuxTerminal!
|
8
26
|
|
9
|
-
|
27
|
+
\e[1;4mArguments:\e[0m
|
28
|
+
|
29
|
+
\e[1m1. Help and Version:\e[0m
|
10
30
|
--help|-h\t\t\tShows this help section
|
31
|
+
--version|-v\t\t\tShows termclock version
|
32
|
+
|
33
|
+
\e[1m2. Style:\e[0m
|
34
|
+
--bold|-b\t\t\tMake texts bold
|
35
|
+
--italic|-i\t\t\tMake texts italic
|
11
36
|
--character=|char=\t\tDraws specified character
|
12
37
|
--clean\t\t\t\tJust run the clean bare clock
|
13
38
|
--colour=|-c=\t\t\tSpecify hex colour (4 colours)
|
14
39
|
\t\t\t\t[ with or without # ]
|
40
|
+
--text-colour|-tc\t\tSpecify text colour (2 colours)
|
41
|
+
\t\t\t\t[ with or without # ]
|
42
|
+
|
43
|
+
\e[1m3. Information:\e[0m
|
15
44
|
--no-date|-nd\t\t\tShows no date
|
16
45
|
--no-message|-nm\t\tShows no messages
|
17
46
|
--no-sysinfo|-ni\t\tShows no system info
|
18
47
|
--refresh|r\t\t\tSpecify delay or refresh time
|
19
|
-
--
|
48
|
+
--no-logo|-nl\t\t\tDon't show the logo at the bottom
|
49
|
+
|
50
|
+
\e[1m4. Formats:\e[0m
|
51
|
+
--date-format=|-df=\t\tSpecify the date format
|
52
|
+
--time-format=|-tf=\t\tSpecify the time format
|
53
|
+
|
54
|
+
Usually the format looks like this:
|
55
|
+
%H:%M:%S:%2N or %d %B, %Y
|
56
|
+
|
57
|
+
\e[3mRun `date --help` to know more formats\e[0m
|
58
|
+
|
59
|
+
Supported characters are 0 - 9, a - z, /, \\, !, %, and |.
|
60
|
+
|
61
|
+
#{version(logo_colour)}
|
20
62
|
EOF
|
21
63
|
|
22
64
|
exit 0
|
23
65
|
end
|
24
66
|
|
67
|
+
if ARGV.any? { |x| x[/\A\-(-version|v)\z/] }
|
68
|
+
puts version(logo_colour)
|
69
|
+
exit 0
|
70
|
+
end
|
71
|
+
|
25
72
|
begin
|
26
73
|
print "\e[?25l"
|
27
74
|
|
@@ -48,28 +95,49 @@ begin
|
|
48
95
|
_refresh_time = ARGV.find { |x| x[/\A\-(\-refresh|r)=.*\z/] } &.split(?=) &.at(1)
|
49
96
|
refresh_time = _refresh_time ? _refresh_time.to_f : 0.1
|
50
97
|
|
98
|
+
_time_format = ARGV.find { |x| x[/\A\-(\-time\-format|tf)=.*\z/] } &.split(?=) &.at(1)
|
99
|
+
time_format = _time_format ? _time_format : "%H %M %S %2N"
|
100
|
+
|
101
|
+
_date_format = ARGV.find { |x| x[/\A\-(\-date\-format|df)=.*\z/] } &.split(?=) &.at(1)
|
102
|
+
date_format = _date_format ? _date_format : "%a, %d %B %Y"
|
103
|
+
|
51
104
|
text_colours = ARGV.find { |x| x[/\A\-(\-text\-colour|tc)=.*\z/] } &.split(?=) &.at(1) &.split(?,)
|
52
105
|
abort("Text colours need 2 colours. Example: -tc=55f,3ce3b5") if text_colours && text_colours.length != 2
|
53
106
|
|
54
|
-
bold = ARGV.any? { |x| x[/\A
|
107
|
+
bold = ARGV.any? { |x| x[/\A\-(\-bold|b)\z/] }
|
108
|
+
italic = ARGV.any? { |x| x[/\A\-(\-italic|i)\z/] }
|
109
|
+
|
55
110
|
no_print_info = ARGV.any? { |x| x[/\A\-(\-no\-sysinfo|ni)\z/] }
|
111
|
+
no_logo = ARGV.any? { |x| x[/\A\-(\-no\-logo|nl)\z/] }
|
56
112
|
no_print_message = ARGV.any? { |x| x[/\A\-(\-no\-message|nm)\z/] }
|
57
113
|
no_print_date = ARGV.any? { |x| x[/\A\-(\-no\-date|nd)\z/] }
|
58
114
|
|
59
115
|
clean = ARGV.any? { |x| x[/\A\-(\-clean)\z/] }
|
60
116
|
|
61
117
|
if clean
|
62
|
-
no_print_info = no_print_message = no_print_date = true
|
118
|
+
no_print_info = no_print_message = no_print_date = no_logo = true
|
119
|
+
end
|
120
|
+
|
121
|
+
begin
|
122
|
+
Time.now.strftime(time_format)
|
123
|
+
Time.now.strftime(date_format)
|
124
|
+
rescue
|
125
|
+
abort "Date / Time format is invalid\n#{$!.to_s}"
|
63
126
|
end
|
64
127
|
|
65
128
|
Termclock.start(
|
66
129
|
*colours,
|
67
130
|
*text_colours,
|
68
|
-
|
131
|
+
refresh: refresh_time,
|
69
132
|
bold: bold,
|
133
|
+
italic: italic,
|
70
134
|
print_info: !no_print_info,
|
71
135
|
print_message: !no_print_message,
|
72
|
-
print_date: !no_print_date
|
136
|
+
print_date: !no_print_date,
|
137
|
+
no_logo: no_logo,
|
138
|
+
time_format: time_format,
|
139
|
+
date_format: date_format,
|
140
|
+
logo_colour: logo_colour
|
73
141
|
)
|
74
142
|
rescue Interrupt, SignalException
|
75
143
|
print "\e[H\e[2J\e[3J"
|
data/lib/termclock.rb
CHANGED
@@ -1,8 +1,18 @@
|
|
1
1
|
require 'linux_stat'
|
2
2
|
require 'io/console'
|
3
|
+
require_relative "termclock/version"
|
4
|
+
|
5
|
+
module Termclock
|
6
|
+
CLEAR = "\e[H\e[2J\e[3J".freeze
|
7
|
+
NEWLINE = ?\n.freeze
|
8
|
+
SPACE = ?\s.freeze
|
9
|
+
TAB = ?\t.freeze
|
10
|
+
EMPTY = ''.freeze
|
11
|
+
EPSILON = 5.0e-07
|
12
|
+
end
|
13
|
+
|
3
14
|
require_relative "termclock/string"
|
4
15
|
require_relative "termclock/parse_characters"
|
5
16
|
require_relative "termclock/system_info"
|
6
|
-
require_relative "termclock/
|
17
|
+
require_relative "termclock/start"
|
7
18
|
require_relative "termclock/hex2rgb"
|
8
|
-
require_relative "termclock/version"
|
data/lib/termclock/hex2rgb.rb
CHANGED
@@ -1,271 +1,305 @@
|
|
1
1
|
module Termclock
|
2
2
|
module ParseCharacters
|
3
|
-
NEWLINE = ?\n.freeze
|
4
3
|
CHARACTERS = <<~EOF.freeze
|
5
|
-
|
4
|
+
#\s0
|
6
5
|
````````
|
7
|
-
``
|
8
|
-
``
|
9
|
-
``
|
6
|
+
``\s\s\s\s``
|
7
|
+
``\s\s\s\s``
|
8
|
+
``\s\s\s\s``
|
10
9
|
````````
|
11
10
|
|
12
|
-
|
13
|
-
|
11
|
+
#\s1
|
12
|
+
\s\s\s``
|
14
13
|
`````
|
15
|
-
|
16
|
-
|
14
|
+
\s\s\s``
|
15
|
+
\s\s\s``
|
17
16
|
````````
|
18
17
|
|
19
|
-
|
18
|
+
#\s2
|
20
19
|
````````
|
21
|
-
|
20
|
+
\s\s\s\s\s\s``
|
22
21
|
````````
|
23
22
|
``
|
24
23
|
````````
|
25
24
|
|
26
|
-
|
25
|
+
#\s3
|
27
26
|
````````
|
28
|
-
|
27
|
+
\s\s\s\s\s\s``
|
29
28
|
````````
|
30
|
-
|
29
|
+
\s\s\s\s\s\s``
|
31
30
|
````````
|
32
31
|
|
33
|
-
|
34
|
-
``
|
35
|
-
``
|
32
|
+
#\s4
|
33
|
+
``\s\s\s\s``
|
34
|
+
``\s\s\s\s``
|
36
35
|
````````
|
37
|
-
|
38
|
-
|
36
|
+
\s\s\s\s\s\s``
|
37
|
+
\s\s\s\s\s\s``
|
39
38
|
|
40
|
-
|
39
|
+
#\s5
|
41
40
|
````````
|
42
41
|
``
|
43
42
|
````````
|
44
|
-
|
43
|
+
\s\s\s\s\s\s``
|
45
44
|
````````
|
46
45
|
|
47
|
-
|
46
|
+
#\s6
|
48
47
|
````````
|
49
48
|
``
|
50
49
|
````````
|
51
|
-
``
|
50
|
+
``\s\s\s\s``
|
52
51
|
````````
|
53
52
|
|
54
|
-
|
53
|
+
#\s7
|
55
54
|
````````
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
\s\s\s\s\s\s``
|
56
|
+
\s\s\s\s\s\s``
|
57
|
+
\s\s\s\s\s\s``
|
58
|
+
\s\s\s\s\s\s``
|
60
59
|
|
61
|
-
|
60
|
+
#\s8
|
62
61
|
````````
|
63
|
-
``
|
62
|
+
``\s\s\s\s``
|
64
63
|
````````
|
65
|
-
``
|
64
|
+
``\s\s\s\s``
|
66
65
|
````````
|
67
66
|
|
68
|
-
|
67
|
+
#\s9
|
69
68
|
````````
|
70
|
-
``
|
69
|
+
``\s\s\s\s``
|
71
70
|
````````
|
72
|
-
|
71
|
+
\s\s\s\s\s\s``
|
73
72
|
````````
|
74
73
|
|
75
|
-
|
74
|
+
#\s:
|
76
75
|
\u2B29\u2B29
|
77
76
|
\u2B29\u2B29
|
78
77
|
|
79
78
|
\u2B29\u2B29
|
80
79
|
\u2B29\u2B29
|
81
80
|
|
82
|
-
|
81
|
+
#\s$
|
83
82
|
\s\s
|
84
83
|
\s\s
|
85
84
|
|
86
85
|
\s\s
|
87
86
|
\s\s
|
88
|
-
|
87
|
+
#\sA
|
89
88
|
````````
|
90
|
-
``
|
89
|
+
``\s\s\s\s``
|
91
90
|
````````
|
92
|
-
``
|
93
|
-
``
|
91
|
+
``\s\s\s\s``
|
92
|
+
``\s\s\s\s``
|
94
93
|
|
95
|
-
|
94
|
+
#\sB
|
96
95
|
````````
|
97
|
-
``
|
96
|
+
``\s\s\s\s\s``
|
98
97
|
````````
|
99
|
-
``
|
98
|
+
``\s\s\s\s\s``
|
100
99
|
````````
|
101
100
|
|
102
|
-
|
101
|
+
#\sC
|
103
102
|
````````
|
104
103
|
``
|
105
104
|
``
|
106
105
|
``
|
107
106
|
````````
|
108
107
|
|
109
|
-
|
108
|
+
#\sD
|
110
109
|
````````
|
111
|
-
``
|
112
|
-
``
|
113
|
-
``
|
110
|
+
``\s\s\s\s\s``
|
111
|
+
``\s\s\s\s\s\s``
|
112
|
+
``\s\s\s\s\s``
|
114
113
|
````````
|
115
114
|
|
116
|
-
|
115
|
+
#\sE
|
117
116
|
````````
|
118
117
|
``
|
119
118
|
````````
|
120
119
|
``
|
121
120
|
````````
|
122
121
|
|
123
|
-
|
122
|
+
#\sF
|
124
123
|
````````
|
125
124
|
``
|
126
125
|
````````
|
127
126
|
``
|
128
127
|
``
|
129
128
|
|
130
|
-
|
129
|
+
#\sG
|
131
130
|
````````
|
132
131
|
``
|
133
132
|
``
|
134
|
-
|
133
|
+
``\s\s````
|
135
134
|
````````
|
136
135
|
|
137
|
-
|
138
|
-
``
|
139
|
-
``
|
136
|
+
#\sH
|
137
|
+
``\s\s\s\s``
|
138
|
+
``\s\s\s\s``
|
140
139
|
````````
|
141
|
-
``
|
142
|
-
``
|
140
|
+
``\s\s\s\s``
|
141
|
+
``\s\s\s\s``
|
143
142
|
|
144
|
-
|
143
|
+
#\sI
|
145
144
|
````````
|
146
|
-
|
147
|
-
|
148
|
-
|
145
|
+
\s\s\s``
|
146
|
+
\s\s\s``
|
147
|
+
\s\s\s``
|
149
148
|
````````
|
150
149
|
|
151
|
-
|
150
|
+
#\sJ
|
152
151
|
````````
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
152
|
+
\s\s\s\s\s\s``
|
153
|
+
\s\s\s\s\s\s``
|
154
|
+
\s``\s\s\s``
|
155
|
+
\s```````
|
157
156
|
|
158
|
-
|
159
|
-
``
|
160
|
-
``
|
157
|
+
#\sK
|
158
|
+
``\s\s\s\s``
|
159
|
+
``\s\s``
|
161
160
|
`````
|
162
|
-
``
|
163
|
-
``
|
161
|
+
``\s\s``
|
162
|
+
``\s\s\s\s``
|
164
163
|
|
165
|
-
|
164
|
+
#\sL
|
166
165
|
``
|
167
166
|
``
|
168
167
|
``
|
169
168
|
``
|
170
169
|
````````
|
171
170
|
|
172
|
-
|
173
|
-
```
|
174
|
-
``
|
175
|
-
``
|
176
|
-
``
|
177
|
-
``
|
171
|
+
#\sM
|
172
|
+
```\s\s```
|
173
|
+
``\s``\s``
|
174
|
+
``\s\s\s\s``
|
175
|
+
``\s\s\s\s``
|
176
|
+
``\s\s\s\s``
|
178
177
|
|
179
|
-
|
180
|
-
|
181
|
-
``
|
182
|
-
``
|
183
|
-
``
|
184
|
-
|
178
|
+
#\sN
|
179
|
+
````\s\s``
|
180
|
+
``\s``\s``
|
181
|
+
``\s``\s``
|
182
|
+
``\s``\s``
|
183
|
+
``\s\s````
|
185
184
|
|
186
|
-
|
185
|
+
#\sO
|
187
186
|
````````
|
188
|
-
``
|
189
|
-
``
|
190
|
-
``
|
187
|
+
``\s\s\s\s``
|
188
|
+
``\s\s\s\s``
|
189
|
+
``\s\s\s\s``
|
191
190
|
````````
|
192
191
|
|
193
|
-
|
192
|
+
#\sP
|
194
193
|
````````
|
195
|
-
``
|
194
|
+
``\s\s\s\s``
|
196
195
|
````````
|
197
196
|
``
|
198
197
|
``
|
199
198
|
|
200
|
-
|
199
|
+
#\sQ
|
201
200
|
````````
|
202
|
-
``
|
201
|
+
``\s\s\s\s``
|
203
202
|
````````
|
204
|
-
|
205
|
-
|
203
|
+
\s\s\s\s\s\s``
|
204
|
+
\s\s\s\s\s\s``
|
206
205
|
|
207
|
-
|
206
|
+
#\sR
|
208
207
|
````````
|
209
|
-
``
|
208
|
+
``\s\s\s\s``
|
210
209
|
````````
|
211
210
|
`````
|
212
|
-
``
|
211
|
+
``\s\s\s``
|
213
212
|
|
214
|
-
|
213
|
+
#\sS
|
215
214
|
````````
|
216
215
|
``
|
217
216
|
````````
|
218
|
-
|
219
|
-
````````
|
220
|
-
|
221
|
-
|
222
|
-
````````
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
``
|
230
|
-
``
|
231
|
-
``
|
232
|
-
``
|
233
|
-
````````
|
234
|
-
|
235
|
-
|
236
|
-
``
|
237
|
-
``
|
238
|
-
``
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
``
|
244
|
-
``
|
245
|
-
``
|
246
|
-
``
|
247
|
-
````````
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
``
|
258
|
-
``
|
259
|
-
````````
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
````````
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
````````
|
217
|
+
\s\s\s\s\s\s``
|
218
|
+
````````
|
219
|
+
|
220
|
+
#\sT
|
221
|
+
````````
|
222
|
+
\s\s\s``
|
223
|
+
\s\s\s``
|
224
|
+
\s\s\s``
|
225
|
+
\s\s\s``
|
226
|
+
|
227
|
+
#\sU
|
228
|
+
``\s\s\s\s``
|
229
|
+
``\s\s\s\s``
|
230
|
+
``\s\s\s\s``
|
231
|
+
``\s\s\s\s``
|
232
|
+
````````
|
233
|
+
|
234
|
+
#\sV
|
235
|
+
``\s\s\s\s``
|
236
|
+
``\s\s\s\s``
|
237
|
+
``\s\s\s\s``
|
238
|
+
\s``\s\s``\s
|
239
|
+
\s\s\s``
|
240
|
+
|
241
|
+
#\sW
|
242
|
+
``\s\s\s\s``
|
243
|
+
``\s\s\s\s``
|
244
|
+
``\s\s\s\s``
|
245
|
+
``\s`\s\s``
|
246
|
+
````````
|
247
|
+
|
248
|
+
#\sX
|
249
|
+
``\s\s\s\s``
|
250
|
+
\s``\s\s``
|
251
|
+
\s\s\s``
|
252
|
+
\s``\s\s``
|
253
|
+
``\s\s\s\s``
|
254
|
+
|
255
|
+
#\sY
|
256
|
+
``\s\s\s\s``
|
257
|
+
``\s\s\s\s``
|
258
|
+
````````
|
259
|
+
\s\s\s``
|
260
|
+
\s\s\s``
|
261
|
+
|
262
|
+
#\sZ
|
263
|
+
````````
|
264
|
+
\s\s\s\s\s``
|
265
|
+
\s\s\s``
|
266
|
+
\s``
|
267
|
+
````````
|
268
|
+
|
269
|
+
#\s/
|
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
|
+
#\s\\
|
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
|
+
#\s%
|
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
|
+
#\s|
|
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
|
+
#\s!
|
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
|
269
303
|
EOF
|
270
304
|
|
271
305
|
class << self
|
@@ -293,7 +327,7 @@ module Termclock
|
|
293
327
|
|
294
328
|
if stripped
|
295
329
|
replace_with = x.chars.map { |y|
|
296
|
-
chars = arg.chars.rotate(-1) if y ==
|
330
|
+
chars = arg.chars.rotate(-1) if y == NEWLINE
|
297
331
|
next(y) if y != stripped
|
298
332
|
chars.rotate!(1)[0]
|
299
333
|
}.join
|
@@ -0,0 +1,212 @@
|
|
1
|
+
module Termclock
|
2
|
+
def self.start(colour1, colour2, colour3, colour4,
|
3
|
+
textcolour1 = nil, textcolour2 = nil,
|
4
|
+
refresh: 0.1,
|
5
|
+
bold: false,
|
6
|
+
italic: false,
|
7
|
+
print_info: true, print_message: true,
|
8
|
+
print_date: true,
|
9
|
+
time_format: "%H %M %S %2N",
|
10
|
+
date_format: '%a, %d %B %Y',
|
11
|
+
no_logo: false,
|
12
|
+
logo_colour: [Termclock.hex2rgb('ff0'), Termclock.hex2rgb('f55'), Termclock.hex2rgb('55f')]
|
13
|
+
)
|
14
|
+
|
15
|
+
generate = proc do |start, stop, n = 5|
|
16
|
+
r_op = r_val = nil
|
17
|
+
ary = []
|
18
|
+
|
19
|
+
if start > stop
|
20
|
+
r_op, r_val = :-, start.-(stop).fdiv(n - 1)
|
21
|
+
elsif start < stop
|
22
|
+
r_op, r_val = :+, stop.-(start).fdiv(n - 1)
|
23
|
+
end
|
24
|
+
|
25
|
+
_r = r_op ? start.send(r_op, r_val * -1) : start
|
26
|
+
n.times {
|
27
|
+
_r = _r.send(r_op, r_val) if r_op
|
28
|
+
ary << _r.clamp(0, 255).to_i
|
29
|
+
}
|
30
|
+
|
31
|
+
ary
|
32
|
+
end
|
33
|
+
|
34
|
+
gc_compact, gc_compacted = GC.respond_to?(:compact), Time.now.to_i + 7200
|
35
|
+
print CLEAR
|
36
|
+
|
37
|
+
r1, g1, b1 = *colour1
|
38
|
+
r2, g2, b2 = *colour2
|
39
|
+
r3, g3, b3 = *colour3
|
40
|
+
r4, g4, b4 = *colour4
|
41
|
+
|
42
|
+
# colour1 -> colour3
|
43
|
+
rs1 = generate.(r1, r3)
|
44
|
+
gs1 = generate.(g1, g3)
|
45
|
+
bs1 = generate.(b1, b3)
|
46
|
+
|
47
|
+
# colour2 -> colour4
|
48
|
+
rs2 = generate.(r2, r4)
|
49
|
+
gs2 = generate.(g2, g4)
|
50
|
+
bs2 = generate.(b2, b4)
|
51
|
+
|
52
|
+
# All Gradient Colours
|
53
|
+
colours = [rs1, gs1, bs1].transpose.zip([rs2, gs2, bs2].transpose)
|
54
|
+
colours.unshift(colours[0])
|
55
|
+
colours.push(colours[-1])
|
56
|
+
|
57
|
+
# Text colours
|
58
|
+
tc1 = textcolour1 ? hex2rgb(textcolour1) : hex2rgb('5555ff')
|
59
|
+
tc2 = textcolour2 ? hex2rgb(textcolour2) : hex2rgb('3ce3b5')
|
60
|
+
|
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
|
+
message_counter = -1
|
69
|
+
message = ''
|
70
|
+
message_final = ''
|
71
|
+
message_align = 0
|
72
|
+
message_temp = ''
|
73
|
+
point_five_tick = 0
|
74
|
+
|
75
|
+
date, info = '', ''
|
76
|
+
|
77
|
+
clock_emoji = ?\u{1F550}.ord.-(1).chr('utf-8')
|
78
|
+
clock_emoji = 12.times.map { clock_emoji.next!.dup }
|
79
|
+
|
80
|
+
braille = %W(\u2821 \u2811 \u2812 \u280A \u280C)
|
81
|
+
|
82
|
+
get_message = proc {
|
83
|
+
braille.rotate!
|
84
|
+
braille_0 = braille[0]
|
85
|
+
|
86
|
+
case Time.now.hour
|
87
|
+
when 5...12
|
88
|
+
"\u{1F304} #{braille_0} Good Morning #{braille_0} \u{1F304}"
|
89
|
+
when 12...16
|
90
|
+
"\u26C5 #{braille_0} Good Afternoon #{braille_0} \u26C5"
|
91
|
+
when 16...18
|
92
|
+
"\u{1F307} #{braille_0} Good Evening #{braille_0} \u{1F307}"
|
93
|
+
when 18...20
|
94
|
+
"\u{1F31F} #{braille_0} Good Evening #{braille_0} \u{1F31F}"
|
95
|
+
when 20...24
|
96
|
+
"\u{1F303} #{braille_0} Good Night #{braille_0} \u{1F303}"
|
97
|
+
else
|
98
|
+
"\u{2728} #{braille_0} Good Night #{braille_0} \u{2728}"
|
99
|
+
end
|
100
|
+
}
|
101
|
+
|
102
|
+
version = "Termclock v#{Termclock::VERSION}"
|
103
|
+
|
104
|
+
v_col1 = logo_colour[0]
|
105
|
+
v_col2 = logo_colour[1]
|
106
|
+
v_col3 = logo_colour[2]
|
107
|
+
|
108
|
+
vl_2 = version.length / 2
|
109
|
+
_term_clock_v = version[0...vl_2].gradient(v_col1, v_col2, underline: true, bold: bold, italic: italic) <<
|
110
|
+
version[vl_2..-1].gradient(v_col2, v_col3, underline: true, bold: bold, italic: italic)
|
111
|
+
|
112
|
+
term_clock_v = ''
|
113
|
+
|
114
|
+
chop_message = 0
|
115
|
+
deviation = 0
|
116
|
+
|
117
|
+
while true
|
118
|
+
monotonic_time_1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
119
|
+
time_now = Time.now
|
120
|
+
height, width = *STDOUT.winsize
|
121
|
+
|
122
|
+
if time_now.to_f./(0.5).to_i.even?
|
123
|
+
unless point_five_tick == 1
|
124
|
+
point_five_tick = 1
|
125
|
+
splitter = ?:.freeze
|
126
|
+
clock_emoji.rotate!
|
127
|
+
end
|
128
|
+
else
|
129
|
+
unless point_five_tick == 0
|
130
|
+
point_five_tick = 0
|
131
|
+
splitter = ?$.freeze
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
unless no_logo
|
136
|
+
term_clock_v = "\e[#{height}H #{clock_emoji[0]} #{_term_clock_v} \e[0m"
|
137
|
+
end
|
138
|
+
|
139
|
+
if print_message
|
140
|
+
message_temp = get_message.call
|
141
|
+
message_counter += 1
|
142
|
+
message_length = message.length
|
143
|
+
|
144
|
+
if (width - message_counter % width < 8)
|
145
|
+
unless chop_message == message_temp.length
|
146
|
+
chop_message += 1
|
147
|
+
message_counter -= 1
|
148
|
+
message_align -= 1
|
149
|
+
message.replace(message_temp[chop_message..-1])
|
150
|
+
end
|
151
|
+
else
|
152
|
+
chop_message = 0 unless chop_message == 0
|
153
|
+
message.clear if width - message_counter % width == width
|
154
|
+
message_align = width - message_counter % width + message_length - 4
|
155
|
+
|
156
|
+
if message_temp != message
|
157
|
+
if message_length < message_temp.length
|
158
|
+
message.replace(message_temp[0..message_length])
|
159
|
+
else
|
160
|
+
message.replace(message_temp)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
message_final = (message).rjust(message_align).gradient(
|
166
|
+
tc1, tc2, exclude_spaces: true, bold: bold, italic: italic
|
167
|
+
)
|
168
|
+
end
|
169
|
+
|
170
|
+
if print_info
|
171
|
+
info = system_info(width).gradient(
|
172
|
+
tc1, tc2, bold: bold, italic: italic
|
173
|
+
)
|
174
|
+
end
|
175
|
+
|
176
|
+
if print_date
|
177
|
+
date = time_now.strftime(date_format).center(width)
|
178
|
+
.gradient(tc1, tc2, bold: bold, italic: italic, exclude_spaces: true)
|
179
|
+
end
|
180
|
+
|
181
|
+
time = time_now.strftime(time_format).split.join(splitter)
|
182
|
+
art = Termclock::ParseCharacters.display(time).lines
|
183
|
+
|
184
|
+
art_aligned = art.each_with_index do |x, i|
|
185
|
+
chomped = x.chomp(EMPTY).+(NEWLINE)
|
186
|
+
gr = chomped.gradient(*colours[i], bold: bold, italic: italic)
|
187
|
+
|
188
|
+
w = width./(2.0).-(chomped.length / 2.0) + 2
|
189
|
+
w = 0 if w < 0
|
190
|
+
|
191
|
+
x.replace(SPACE.*(w) + gr)
|
192
|
+
end.join
|
193
|
+
|
194
|
+
vertical_gap = "\e[#{height./(2.0).-(art.length / 2.0).to_i + 1}H"
|
195
|
+
|
196
|
+
print "#{CLEAR}#{info}#{vertical_gap}#{art_aligned}\n#{date}\n\n#{message_final}#{term_clock_v}"
|
197
|
+
|
198
|
+
if gc_compact && time_now.to_i > gc_compacted
|
199
|
+
GC.compact
|
200
|
+
gc_compacted = time_now.to_i + 7200
|
201
|
+
end
|
202
|
+
|
203
|
+
monotonic_time_2 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
204
|
+
time_diff = monotonic_time_2 - monotonic_time_1
|
205
|
+
sleep_time = refresh.-(time_diff + EPSILON + deviation)
|
206
|
+
sleep_time = 0 if sleep_time < 0
|
207
|
+
|
208
|
+
deviation = Process.clock_gettime(Process::CLOCK_MONOTONIC) - monotonic_time_2
|
209
|
+
sleep(sleep_time)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
data/lib/termclock/string.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
class String
|
2
|
-
|
2
|
+
NEWLINE = ?\n.freeze
|
3
|
+
SPACE = ?\s.freeze
|
4
|
+
TAB = ?\t.freeze
|
5
|
+
EMPTY = ''.freeze
|
6
|
+
|
7
|
+
def gradient(*all_rgbs,
|
8
|
+
bg: false,
|
9
|
+
exclude_spaces: false,
|
10
|
+
bold: false, italic: false, underline: false
|
11
|
+
)
|
12
|
+
|
3
13
|
temp = ''
|
4
14
|
|
5
15
|
r, g, b = all_rgbs[0]
|
@@ -8,9 +18,21 @@ class String
|
|
8
18
|
|
9
19
|
init = bg ? 48 : 38
|
10
20
|
|
21
|
+
style = nil
|
22
|
+
if bold || italic || underline
|
23
|
+
style = "\e["
|
24
|
+
style << '1;'.freeze if bold
|
25
|
+
style << '3;'.freeze if italic
|
26
|
+
style << '4;'.freeze if underline
|
27
|
+
style.chop!
|
28
|
+
style << 'm'.freeze
|
29
|
+
end
|
30
|
+
|
11
31
|
each_line do |c|
|
32
|
+
temp << style if style
|
33
|
+
|
12
34
|
_r, _g, _b = r, g, b
|
13
|
-
chomped = !!c.chomp!(
|
35
|
+
chomped = !!c.chomp!(EMPTY)
|
14
36
|
|
15
37
|
len = c.length
|
16
38
|
n_variable = exclude_spaces ? c.delete("\t\s".freeze).length : len
|
@@ -45,13 +67,11 @@ class String
|
|
45
67
|
_g = _g.send(g_op, g_val * -1) if g_op
|
46
68
|
_b = _b.send(b_op, b_val * -1) if b_op
|
47
69
|
|
48
|
-
temp << "\e[1m" if bold
|
49
|
-
|
50
70
|
i = -1
|
51
71
|
while (i += 1) < len
|
52
72
|
_c = c[i]
|
53
73
|
|
54
|
-
if !exclude_spaces || (exclude_spaces && !(_c ==
|
74
|
+
if !exclude_spaces || (exclude_spaces && !(_c == SPACE || _c == TAB))
|
55
75
|
_r = _r.send(r_op, r_val) if r_op
|
56
76
|
_g = _g.send(g_op, g_val) if g_op
|
57
77
|
_b = _b.send(b_op, b_val) if b_op
|
@@ -72,7 +92,7 @@ class String
|
|
72
92
|
ret = if !c.empty?
|
73
93
|
chomped ? "\e[0m\n".freeze : "\e[0m".freeze
|
74
94
|
elsif chomped
|
75
|
-
|
95
|
+
NEWLINE
|
76
96
|
end
|
77
97
|
|
78
98
|
temp << ret
|
@@ -1,24 +1,29 @@
|
|
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
|
-
@@current_net_usage =
|
6
|
-
@@current_net_usage_t = Thread.new { }
|
5
|
+
@@current_net_usage = "\u{1F4CA} Curr. DL/UL:"
|
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
|
-
@@cpu_usage_t = Thread.new {
|
11
|
+
@@cpu_usage_t = Thread.new {
|
12
|
+
_cpu_usage = LS::CPU.usage(0.25)
|
13
|
+
_cpu_usage_i = _cpu_usage.to_i
|
14
|
+
|
15
|
+
@@cpu_usage = "%0.2f" % _cpu_usage
|
16
|
+
}
|
12
17
|
end
|
13
18
|
|
14
19
|
unless @@current_net_usage_t.alive?
|
15
20
|
@@current_net_usage_t = Thread.new do
|
16
21
|
_m = LS::Net.current_usage(0.25)
|
17
22
|
|
18
|
-
_dl = LS::PrettifyBytes.
|
19
|
-
_ul = LS::PrettifyBytes.
|
23
|
+
_dl = LS::PrettifyBytes.convert_short_decimal(_m[:received], precision: 1)
|
24
|
+
_ul = LS::PrettifyBytes.convert_short_decimal(_m[:transmitted], precision: 1)
|
20
25
|
|
21
|
-
@@current_net_usage = "\u{1F4CA} Curr. DL/UL: #{sprintf "%-
|
26
|
+
@@current_net_usage = "\u{1F4CA} Curr. DL/UL: #{sprintf "%-8s", _dl} | #{sprintf "%8s", _ul}"
|
22
27
|
end
|
23
28
|
end
|
24
29
|
|
@@ -26,11 +31,15 @@ module Termclock
|
|
26
31
|
|
27
32
|
battery = if LS::Battery.present?
|
28
33
|
stat = LS::Battery.stat
|
29
|
-
emoji =
|
30
|
-
|
34
|
+
emoji, plug = "\u{1F50B}".freeze, EMPTY
|
35
|
+
|
36
|
+
if LS::Battery.charging?
|
37
|
+
emoji, plug = "\u{1F4A1}".freeze, "\u{1F50C} ".freeze
|
38
|
+
end
|
39
|
+
|
31
40
|
"#{emoji} Battery: #{stat[:charge].to_i}% (#{plug}#{stat[:status]})"
|
32
41
|
else
|
33
|
-
|
42
|
+
EMPTY
|
34
43
|
end
|
35
44
|
|
36
45
|
user = "\u{1F481} User: #{LS::User.get_current_user.capitalize}"
|
@@ -39,35 +48,80 @@ module Termclock
|
|
39
48
|
_m = LS::Net.total_bytes
|
40
49
|
ip = "\u{1F30F} IP Addr: #{LS::Net.ipv4_private}"
|
41
50
|
|
42
|
-
net_usage = "\u{1F4C8} Totl. DL/UL: #{sprintf "%-
|
43
|
-
" | #{sprintf "%
|
51
|
+
net_usage = "\u{1F4C8} Totl. DL/UL: #{sprintf "%-8s", LS::PrettifyBytes.convert_short_decimal(_m[:received], precision: 1)}"\
|
52
|
+
" | #{sprintf "%8s", LS::PrettifyBytes.convert_short_decimal(_m[:transmitted], precision: 1)}"
|
44
53
|
|
45
54
|
_m = LS::Memory.stat
|
46
|
-
|
47
|
-
|
48
|
-
"
|
55
|
+
_m.default = 0
|
56
|
+
|
57
|
+
memory = "\u{1F3B0} Mem: #{LS::PrettifyBytes.convert_short_decimal(_m[:used] * 1000)}"\
|
58
|
+
" / #{LS::PrettifyBytes.convert_short_decimal(_m[:total] * 1000)}"\
|
59
|
+
" (#{_m[:percent_used]}%)"
|
49
60
|
|
50
61
|
_m = LS::Swap.stat
|
51
|
-
|
52
|
-
|
53
|
-
"
|
54
|
-
|
55
|
-
_m
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
62
|
+
_m.default = 0
|
63
|
+
|
64
|
+
swap = "\u{1F300} Swap: #{LS::PrettifyBytes.convert_short_decimal(_m[:used] * 1000)}"\
|
65
|
+
" / #{LS::PrettifyBytes.convert_short_decimal(_m[:total] * 1000)}"\
|
66
|
+
" (#{_m[:percent_used]}%)"
|
67
|
+
|
68
|
+
_m = LS::Filesystem.stat('/')
|
69
|
+
_m.default = 0
|
70
|
+
|
71
|
+
fs = "\u{1F4BD} FS: #{LS::PrettifyBytes.convert_short_decimal(_m[:used])}"\
|
72
|
+
" / #{LS::PrettifyBytes.convert_short_decimal(_m[:total])}"\
|
73
|
+
" (#{_m[:used].*(100).fdiv(_m[:total]).round(2)}%)"
|
74
|
+
|
75
|
+
pt = LS::Process.types.values
|
76
|
+
|
77
|
+
process = "\u{1F9EE} Process: T:#{sprintf "%4s", LS::Process.count}|"\
|
78
|
+
"R:#{sprintf "%3s", pt.count(:running)}|"\
|
79
|
+
"S:#{sprintf "%3s", pt.count(:sleeping)}|"\
|
80
|
+
"I:#{sprintf "%3s", pt.count(:idle)}"
|
81
|
+
|
82
|
+
_os_v = LS::OS.version
|
83
|
+
os_v = unless _os_v.empty?
|
84
|
+
" (#{_os_v})"
|
85
|
+
else
|
86
|
+
EMPTY
|
87
|
+
end
|
88
|
+
|
89
|
+
os = "\u{1F427} Distrib: #{LS::OS.distribution} #{LS::OS.machine}#{os_v}"
|
90
|
+
|
91
|
+
_uptime = LS::OS.uptime
|
92
|
+
_second = _uptime[:second]
|
93
|
+
_second_i = _second.to_i
|
94
|
+
|
95
|
+
hour = "%02d" % _uptime[:hour]
|
96
|
+
minute = "%02d" % _uptime[:minute]
|
97
|
+
second = "%02d" % _second_i
|
98
|
+
ms = "%02d" % _second.-(_second_i).*(100)
|
99
|
+
|
100
|
+
uptime = "\u{1F3A1} Uptime: #{hour}:#{minute}:#{second}:#{ms} (#{LS::OS.uptime_i}s)"
|
101
|
+
|
102
|
+
_loadavg = LS::Sysinfo.loads.map! { |x| sprintf("%.2f", x) }
|
103
|
+
loadavg = "\u{1F9FA} LoadAvg: 1m #{_loadavg[0]}|5m #{_loadavg[1]}|15m #{_loadavg[2]}"
|
104
|
+
|
105
|
+
all_info = [
|
106
|
+
user, hostname,
|
107
|
+
os, battery,
|
108
|
+
cpu, ip,
|
109
|
+
memory, @@current_net_usage,
|
110
|
+
swap, net_usage,
|
111
|
+
fs, process,
|
112
|
+
uptime, loadavg
|
113
|
+
].map(&:to_s).reject(&:empty?)
|
114
|
+
max_l = 0
|
115
|
+
|
116
|
+
all_info.each_with_index { |x, i|
|
117
|
+
max_l = x.length if i.odd? && x.length > max_l
|
118
|
+
}
|
119
|
+
|
120
|
+
max_l += 4
|
121
|
+
|
122
|
+
all_info.each_slice(2).map { |x, y|
|
123
|
+
"\s#{x}#{SPACE.*(width.-(x.length + max_l).abs)}#{y}"
|
124
|
+
}.join(NEWLINE)
|
71
125
|
end
|
72
126
|
end
|
73
127
|
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.4.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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: linux_stat
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.5.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.5.1
|
27
27
|
description: A clock for Linux VTE
|
28
28
|
email:
|
29
29
|
- souravgoswami@protonmail.com
|
@@ -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
|
data/lib/termclock/main.rb
DELETED
@@ -1,152 +0,0 @@
|
|
1
|
-
module Termclock
|
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
|
-
|
11
|
-
newline = ?\n.freeze
|
12
|
-
space = ?\s.freeze
|
13
|
-
|
14
|
-
generate = proc do |start, stop, n = 5|
|
15
|
-
r_op = r_val = nil
|
16
|
-
ary = []
|
17
|
-
|
18
|
-
if start > stop
|
19
|
-
r_op, r_val = :-, start.-(stop).fdiv(n - 1)
|
20
|
-
elsif start < stop
|
21
|
-
r_op, r_val = :+, stop.-(start).fdiv(n - 1)
|
22
|
-
end
|
23
|
-
|
24
|
-
_r = r_op ? start.send(r_op, r_val * -1) : start
|
25
|
-
n.times {
|
26
|
-
_r = _r.send(r_op, r_val) if r_op
|
27
|
-
ary << _r.clamp(0, 255).to_i
|
28
|
-
}
|
29
|
-
|
30
|
-
ary
|
31
|
-
end
|
32
|
-
|
33
|
-
gc_compact, gc_compacted = GC.respond_to?(:compact), Time.now.to_i + 7200
|
34
|
-
print "\e[H\e[2J\e[3J" unless COLOURTERM
|
35
|
-
|
36
|
-
r1, g1, b1 = *colour1
|
37
|
-
r2, g2, b2 = *colour2
|
38
|
-
r3, g3, b3 = *colour3
|
39
|
-
r4, g4, b4 = *colour4
|
40
|
-
|
41
|
-
# colour1 -> colour3
|
42
|
-
rs1 = generate.(r1, r3)
|
43
|
-
gs1 = generate.(g1, g3)
|
44
|
-
bs1 = generate.(b1, b3)
|
45
|
-
|
46
|
-
# colour2 -> colour4
|
47
|
-
rs2 = generate.(r2, r4)
|
48
|
-
gs2 = generate.(g2, g4)
|
49
|
-
bs2 = generate.(b2, b4)
|
50
|
-
|
51
|
-
# All Gradient Colours
|
52
|
-
colours = [rs1, gs1, bs1].transpose.zip([rs2, gs2, bs2].transpose)
|
53
|
-
colours.unshift(colours[0])
|
54
|
-
colours.push(colours[-1])
|
55
|
-
|
56
|
-
# Text colours
|
57
|
-
tc1 = textcolour1 ? hex2rgb(textcolour1) : hex2rgb('5555ff')
|
58
|
-
tc2 = textcolour2 ? hex2rgb(textcolour2) : hex2rgb('3ce3b5')
|
59
|
-
|
60
|
-
cpu_usage = 0
|
61
|
-
cpu_usage_t = Thread.new { }
|
62
|
-
|
63
|
-
current_net_usage = ''
|
64
|
-
current_net_usage_t = Thread.new { }
|
65
|
-
|
66
|
-
message_time = Time.now.to_i - 5
|
67
|
-
message_counter = -1
|
68
|
-
message = ''
|
69
|
-
message_final = ''
|
70
|
-
message_temp = ''
|
71
|
-
caret = "\u2588"
|
72
|
-
|
73
|
-
date, info = '', ''
|
74
|
-
|
75
|
-
get_message = proc {
|
76
|
-
case Time.now.hour
|
77
|
-
when 5...12
|
78
|
-
"\u{1F304} Good Morning..."
|
79
|
-
when 12...16
|
80
|
-
"\u26C5 Good Afternoon..."
|
81
|
-
when 16...18
|
82
|
-
"\u{1F307} Good Evening..."
|
83
|
-
when 18...20
|
84
|
-
"\u{1F31F} Good Evening..."
|
85
|
-
when 20...24
|
86
|
-
"\u{1F303} Good Night..."
|
87
|
-
else
|
88
|
-
"\u{2728} Good Night..."
|
89
|
-
end
|
90
|
-
}
|
91
|
-
|
92
|
-
while true
|
93
|
-
time_now = Time.now
|
94
|
-
height, width = *STDOUT.winsize
|
95
|
-
|
96
|
-
if time_now.to_f./(0.5).to_i.even?
|
97
|
-
splitter = ?:.freeze
|
98
|
-
_caret = caret
|
99
|
-
else
|
100
|
-
splitter = ?$.freeze
|
101
|
-
_caret = ''
|
102
|
-
end
|
103
|
-
|
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
|
118
|
-
|
119
|
-
message_final = message.rjust(message_align).+(_caret).gradient(tc1, tc2, exclude_spaces: true, bold: bold)
|
120
|
-
end
|
121
|
-
|
122
|
-
if print_info
|
123
|
-
info = system_info(width, tc1, tc2, bold)
|
124
|
-
end
|
125
|
-
|
126
|
-
if print_date
|
127
|
-
date = time_now.strftime('%a, %d %B %Y').center(width)
|
128
|
-
.gradient(tc1, tc2, bold: bold)
|
129
|
-
end
|
130
|
-
|
131
|
-
time = time_now.strftime('%H %M %S %2N').split.join(splitter)
|
132
|
-
art = Termclock::ParseCharacters.display(time).lines
|
133
|
-
|
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
|
139
|
-
|
140
|
-
vertical_gap = "\e[#{height./(2.0).-(art.length / 2.0).to_i + 1}H"
|
141
|
-
|
142
|
-
print "#{CLEAR}#{info}#{vertical_gap}#{art_aligned}\n#{date}\n\n#{message_final}"
|
143
|
-
|
144
|
-
if gc_compact && time_now.to_i > gc_compacted
|
145
|
-
GC.compact
|
146
|
-
gc_compacted = time_now.to_i + 7200
|
147
|
-
end
|
148
|
-
|
149
|
-
sleep(sleep)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|