termclock 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/exe/termclock +34 -0
- data/lib/termclock.rb +12 -0
- data/lib/termclock/hex2rgb.rb +30 -0
- data/lib/termclock/main.rb +166 -0
- data/lib/termclock/parse_characters.rb +307 -0
- data/lib/termclock/string.rb +87 -0
- data/lib/termclock/version.rb +5 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 035cd03641bd125a2b3da03fe051103d6ce9a8ee75917a6f5c7e6e97a568cfb8
|
4
|
+
data.tar.gz: 466cce8b4ef31fd357191aeada4ff8c5fda0584e21ef0dfc50ca1c2f3886d1ac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9dac45de1be6e3d805a73c429948c7435b2f3b34b9080ff33616d3b1a51f000f35f5a423fa4cfb187119f1f97a8a6c69fc25fe7bc1c9a342506652cf0c43d62f
|
7
|
+
data.tar.gz: 3690251100766cd071af66baba728bfe07f6636c657b3f4ee7a529f656f30fafc2984805d252fb342251d5278cb852297d0bc93935aeb7008436121bc73732d3
|
data/exe/termclock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'termclock'
|
3
|
+
|
4
|
+
$-v = true
|
5
|
+
|
6
|
+
begin
|
7
|
+
print "\e[?25l"
|
8
|
+
|
9
|
+
arg_col = ARGV.find { |x| x[/\A\-(\-colour|\-color|c|)=.*\z/] } &.split(?=) &.at(1) &.split(?,)
|
10
|
+
|
11
|
+
colours = if arg_col
|
12
|
+
abort("4 colours are needed. Example: -c=f55,55f,55f,3eb") if arg_col.length != 4
|
13
|
+
arg_col
|
14
|
+
else
|
15
|
+
%w(ff5555 5555ff 5555ff 33eebb)
|
16
|
+
end
|
17
|
+
|
18
|
+
colours.map! { |x|
|
19
|
+
begin
|
20
|
+
Termclock.hex2rgb(x)
|
21
|
+
rescue ArgumentError
|
22
|
+
abort $!.to_s
|
23
|
+
end
|
24
|
+
}
|
25
|
+
|
26
|
+
chars = ARGV.find { |x| x[/\A\-(\-character|char)=.*\z/] } &.split(?=) &.at(1)
|
27
|
+
Termclock::ParseCharacters.transform_characters!(chars[0]) if chars
|
28
|
+
|
29
|
+
Termclock.main(*colours)
|
30
|
+
rescue Interrupt, SignalException
|
31
|
+
print "\e[H\e[2J\e[3J"
|
32
|
+
ensure
|
33
|
+
print "\e[?25h"
|
34
|
+
end
|
data/lib/termclock.rb
ADDED
@@ -0,0 +1,12 @@
|
|
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
|
+
require 'linux_stat'
|
7
|
+
require 'io/console'
|
8
|
+
require_relative "termclock/string"
|
9
|
+
require_relative "termclock/parse_characters"
|
10
|
+
require_relative "termclock/main"
|
11
|
+
require_relative "termclock/hex2rgb"
|
12
|
+
require_relative "termclock/version"
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Termclock
|
2
|
+
def self.hex2rgb(hex)
|
3
|
+
colour = hex.dup.to_s
|
4
|
+
colour.strip!
|
5
|
+
colour.downcase!
|
6
|
+
colour[0] = ''.freeze if colour[0] == ?#.freeze
|
7
|
+
|
8
|
+
# out of range
|
9
|
+
oor = colour.scan(/[^a-f0-9]/)
|
10
|
+
|
11
|
+
unless oor.empty?
|
12
|
+
invalids = colour.chars.map { |x|
|
13
|
+
oor.include?(x) ? "\e[1;31m#{x}\e[0m" : x
|
14
|
+
}.join
|
15
|
+
|
16
|
+
puts "Hex Colour ##{invalids} is Out of Range"
|
17
|
+
raise ArgumentError
|
18
|
+
end
|
19
|
+
|
20
|
+
clen = colour.length
|
21
|
+
if clen == 3
|
22
|
+
colour.chars.map { |x| x.<<(x).to_i(16) }
|
23
|
+
elsif clen == 6
|
24
|
+
colour.chars.each_slice(2).map { |x| x.join.to_i(16) }
|
25
|
+
else
|
26
|
+
sli = clen > 6 ? 'too long'.freeze : clen < 3 ? 'too short'.freeze : 'invalid'.freeze
|
27
|
+
raise ArgumentError, "Invalid Hex Colour ##{colour} (length #{sli})"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
module Termclock
|
2
|
+
def self.main(colour1, colour2, colour3, colour4, sleep = 0.1)
|
3
|
+
newline = ?\n.freeze
|
4
|
+
space = ?\s.freeze
|
5
|
+
|
6
|
+
generate = proc do |start, stop, n = 5|
|
7
|
+
r_op = r_val = nil
|
8
|
+
ary = []
|
9
|
+
|
10
|
+
if start > stop
|
11
|
+
r_op, r_val = :-, start.-(stop).fdiv(n - 1)
|
12
|
+
elsif start < stop
|
13
|
+
r_op, r_val = :+, stop.-(start).fdiv(n - 1)
|
14
|
+
end
|
15
|
+
|
16
|
+
_r = r_op ? start.send(r_op, r_val * -1) : start
|
17
|
+
n.times {
|
18
|
+
_r = _r.send(r_op, r_val) if r_op
|
19
|
+
ary << _r.clamp(0, 255).to_i
|
20
|
+
}
|
21
|
+
|
22
|
+
ary
|
23
|
+
end
|
24
|
+
|
25
|
+
gc_compact, gc_compacted = GC.respond_to?(:compact), Time.now.to_i + 7200
|
26
|
+
print "\e[H\e[2J\e[3J" unless COLOURTERM
|
27
|
+
|
28
|
+
r1, g1, b1 = *colour1
|
29
|
+
r2, g2, b2 = *colour2
|
30
|
+
r3, g3, b3 = *colour3
|
31
|
+
r4, g4, b4 = *colour4
|
32
|
+
|
33
|
+
# colour1 -> colour3
|
34
|
+
rs1 = generate.(r1, r3)
|
35
|
+
gs1 = generate.(g1, g3)
|
36
|
+
bs1 = generate.(b1, b3)
|
37
|
+
|
38
|
+
# colour2 -> colour4
|
39
|
+
rs2 = generate.(r2, r4)
|
40
|
+
gs2 = generate.(g2, g4)
|
41
|
+
bs2 = generate.(b2, b4)
|
42
|
+
|
43
|
+
# All Gradient Colours
|
44
|
+
colours = [rs1, gs1, bs1].transpose.zip([rs2, gs2, bs2].transpose)
|
45
|
+
colours.unshift(colours[0])
|
46
|
+
colours.push(colours[-1])
|
47
|
+
cpu_usage = 0
|
48
|
+
cpu_usage_t = Thread.new { }
|
49
|
+
message_time = Time.now.to_i - 5
|
50
|
+
message = ''
|
51
|
+
message_temp = ''
|
52
|
+
caret = "\u2588"
|
53
|
+
|
54
|
+
get_message = proc {
|
55
|
+
case Time.now.hour
|
56
|
+
when 6...12
|
57
|
+
"\u{1F304} Good Morning..."
|
58
|
+
when 12...16
|
59
|
+
"\u26C5 Good Afternoon..."
|
60
|
+
when 16...19
|
61
|
+
"\u{1F306} Good Evening..."
|
62
|
+
when 19...22
|
63
|
+
"\u{1F303} Good Night..."
|
64
|
+
else
|
65
|
+
"\u{1F30C} Good Night..."
|
66
|
+
end
|
67
|
+
}
|
68
|
+
|
69
|
+
i = -1
|
70
|
+
|
71
|
+
while true
|
72
|
+
i += 1
|
73
|
+
time_now = Time.now
|
74
|
+
height, width = *STDOUT.winsize
|
75
|
+
|
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
|
+
if time_now.to_f./(0.5).to_i.even?
|
92
|
+
splitter = ?:.freeze
|
93
|
+
_caret = caret
|
94
|
+
else
|
95
|
+
splitter = ?$.freeze
|
96
|
+
_caret = ''
|
97
|
+
end
|
98
|
+
|
99
|
+
time = time_now.strftime("%H %M %S %2N").split.join(splitter)
|
100
|
+
art = Termclock::ParseCharacters.display(time)
|
101
|
+
|
102
|
+
art_aligned = art.lines.each_with_index do |x, i|
|
103
|
+
chomped = x.chomp(''.freeze).+(newline)
|
104
|
+
gr = chomped.gradient(*colours[i])
|
105
|
+
x.replace(space.*(width./(2.0).-(chomped.length / 2.0).abs.to_i + 1) + gr)
|
106
|
+
end.join
|
107
|
+
|
108
|
+
horizontal_gap = "\e[#{height./(2.0).-(art.lines.length / 2.0).to_i + 1}H"
|
109
|
+
|
110
|
+
unless cpu_usage_t.alive?
|
111
|
+
cpu_usage_t = Thread.new { cpu_usage = LS::CPU.usage(0.25) }
|
112
|
+
end
|
113
|
+
|
114
|
+
cpu = "\u{1F9E0} CPU: #{cpu_usage}% (#{LS::CPU.count_online} / #{LS::CPU.count})"
|
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
|
+
end
|
123
|
+
|
124
|
+
_m = LS::Net.total_bytes
|
125
|
+
ip = "\u{1F30F} IP: #{LS::Net.ipv4_private}"
|
126
|
+
net_usage = "\u{1F4C8} D/L | U/L: #{LS::PrettifyBytes.convert_short_binary _m[:received]}"\
|
127
|
+
" | #{LS::PrettifyBytes.convert_short_binary _m[:transmitted]}"
|
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)}%)"
|
143
|
+
|
144
|
+
process = "\u{1F9EE} Process: #{LS::Process.count}"
|
145
|
+
|
146
|
+
max_l = [process, ip, battery, net_usage].map(&:length).max
|
147
|
+
|
148
|
+
info = <<~EOF.gradient(*colours[2], exclude_spaces: true)
|
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
|
154
|
+
|
155
|
+
print "#{CLEAR}#{info}#{horizontal_gap}#{art_aligned}\n"\
|
156
|
+
"#{message.rjust(message_align).+(_caret).gradient(*colours[1], exclude_spaces: true)}"
|
157
|
+
|
158
|
+
if gc_compact && time_now.to_i > gc_compacted
|
159
|
+
GC.compact
|
160
|
+
gc_compacted = time_now.to_i + 7200
|
161
|
+
end
|
162
|
+
|
163
|
+
sleep(sleep)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,307 @@
|
|
1
|
+
module Termclock
|
2
|
+
module ParseCharacters
|
3
|
+
NEWLINE = ?\n.freeze
|
4
|
+
CHARACTERS = <<~EOF.freeze
|
5
|
+
# 0
|
6
|
+
```````
|
7
|
+
`` ``
|
8
|
+
`` ``
|
9
|
+
`` ``
|
10
|
+
```````
|
11
|
+
|
12
|
+
# 1
|
13
|
+
``
|
14
|
+
````
|
15
|
+
``
|
16
|
+
``
|
17
|
+
```````
|
18
|
+
|
19
|
+
# 2
|
20
|
+
```````
|
21
|
+
``
|
22
|
+
```````
|
23
|
+
``
|
24
|
+
```````
|
25
|
+
|
26
|
+
# 3
|
27
|
+
```````
|
28
|
+
``
|
29
|
+
```````
|
30
|
+
``
|
31
|
+
```````
|
32
|
+
|
33
|
+
# 4
|
34
|
+
`` ``
|
35
|
+
`` ``
|
36
|
+
```````
|
37
|
+
``
|
38
|
+
``
|
39
|
+
|
40
|
+
# 5
|
41
|
+
```````
|
42
|
+
``
|
43
|
+
```````
|
44
|
+
``
|
45
|
+
```````
|
46
|
+
|
47
|
+
# 6
|
48
|
+
```````
|
49
|
+
``
|
50
|
+
```````
|
51
|
+
`` ``
|
52
|
+
```````
|
53
|
+
|
54
|
+
# 7
|
55
|
+
```````
|
56
|
+
``
|
57
|
+
``
|
58
|
+
``
|
59
|
+
``
|
60
|
+
|
61
|
+
# 8
|
62
|
+
```````
|
63
|
+
`` ``
|
64
|
+
```````
|
65
|
+
`` ``
|
66
|
+
```````
|
67
|
+
|
68
|
+
# 9
|
69
|
+
```````
|
70
|
+
`` ``
|
71
|
+
```````
|
72
|
+
``
|
73
|
+
```````
|
74
|
+
|
75
|
+
# :
|
76
|
+
⬩⬩
|
77
|
+
⬩⬩
|
78
|
+
|
79
|
+
⬩⬩
|
80
|
+
⬩⬩
|
81
|
+
|
82
|
+
# $
|
83
|
+
\s\s
|
84
|
+
\s\s
|
85
|
+
|
86
|
+
\s\s
|
87
|
+
\s\s
|
88
|
+
# A
|
89
|
+
```````
|
90
|
+
`` ``
|
91
|
+
```````
|
92
|
+
`` ``
|
93
|
+
`` ``
|
94
|
+
|
95
|
+
# B
|
96
|
+
``````
|
97
|
+
`` ``
|
98
|
+
``````
|
99
|
+
`` ``
|
100
|
+
``````
|
101
|
+
|
102
|
+
# C
|
103
|
+
```````
|
104
|
+
``
|
105
|
+
``
|
106
|
+
``
|
107
|
+
```````
|
108
|
+
|
109
|
+
# D
|
110
|
+
`````
|
111
|
+
`` ``
|
112
|
+
`` ``
|
113
|
+
`` ``
|
114
|
+
`````
|
115
|
+
|
116
|
+
# E
|
117
|
+
```````
|
118
|
+
``
|
119
|
+
```````
|
120
|
+
``
|
121
|
+
```````
|
122
|
+
|
123
|
+
# F
|
124
|
+
```````
|
125
|
+
``
|
126
|
+
```````
|
127
|
+
``
|
128
|
+
``
|
129
|
+
|
130
|
+
# G
|
131
|
+
```````
|
132
|
+
``
|
133
|
+
``
|
134
|
+
`` ```
|
135
|
+
````````
|
136
|
+
|
137
|
+
# H
|
138
|
+
`` ``
|
139
|
+
`` ``
|
140
|
+
```````
|
141
|
+
`` ``
|
142
|
+
`` ``
|
143
|
+
|
144
|
+
# I
|
145
|
+
```````
|
146
|
+
`
|
147
|
+
`
|
148
|
+
`
|
149
|
+
```````
|
150
|
+
|
151
|
+
# J
|
152
|
+
```````
|
153
|
+
``
|
154
|
+
``
|
155
|
+
`` ``
|
156
|
+
``````
|
157
|
+
|
158
|
+
# K
|
159
|
+
`` ``
|
160
|
+
`` ``
|
161
|
+
````
|
162
|
+
`` ``
|
163
|
+
`` ``
|
164
|
+
|
165
|
+
# L
|
166
|
+
``
|
167
|
+
``
|
168
|
+
``
|
169
|
+
``
|
170
|
+
``````
|
171
|
+
|
172
|
+
# M
|
173
|
+
``` ```
|
174
|
+
`` `` ``
|
175
|
+
`` ``
|
176
|
+
`` ``
|
177
|
+
`` ``
|
178
|
+
|
179
|
+
# N
|
180
|
+
```` ``
|
181
|
+
`` ` ``
|
182
|
+
`` ` ``
|
183
|
+
`` ` ``
|
184
|
+
`` ```
|
185
|
+
|
186
|
+
# O
|
187
|
+
````````
|
188
|
+
`` ``
|
189
|
+
`` ``
|
190
|
+
`` ``
|
191
|
+
````````
|
192
|
+
|
193
|
+
# P
|
194
|
+
````````
|
195
|
+
`` ``
|
196
|
+
````````
|
197
|
+
``
|
198
|
+
``
|
199
|
+
|
200
|
+
# Q
|
201
|
+
```````
|
202
|
+
`` ``
|
203
|
+
```````
|
204
|
+
``
|
205
|
+
``
|
206
|
+
|
207
|
+
# R
|
208
|
+
```````
|
209
|
+
`` ``
|
210
|
+
```````
|
211
|
+
````
|
212
|
+
`` ``
|
213
|
+
|
214
|
+
# S
|
215
|
+
```````
|
216
|
+
``
|
217
|
+
```````
|
218
|
+
``
|
219
|
+
```````
|
220
|
+
|
221
|
+
# T
|
222
|
+
````````
|
223
|
+
``
|
224
|
+
``
|
225
|
+
``
|
226
|
+
``
|
227
|
+
|
228
|
+
# U
|
229
|
+
`` ``
|
230
|
+
`` ``
|
231
|
+
`` ``
|
232
|
+
`` ``
|
233
|
+
```````
|
234
|
+
|
235
|
+
# V
|
236
|
+
`` ``
|
237
|
+
`` ``
|
238
|
+
`` ``
|
239
|
+
`` ``
|
240
|
+
`
|
241
|
+
|
242
|
+
# W
|
243
|
+
`` ``
|
244
|
+
`` ``
|
245
|
+
`` ``
|
246
|
+
`` ` ``
|
247
|
+
`````````
|
248
|
+
|
249
|
+
# X
|
250
|
+
`` ``
|
251
|
+
`` ``
|
252
|
+
``
|
253
|
+
`` ``
|
254
|
+
`` ``
|
255
|
+
|
256
|
+
# Y
|
257
|
+
`` ``
|
258
|
+
`` ``
|
259
|
+
````````
|
260
|
+
``
|
261
|
+
``
|
262
|
+
|
263
|
+
# Z
|
264
|
+
````````
|
265
|
+
``
|
266
|
+
``
|
267
|
+
``
|
268
|
+
````````
|
269
|
+
EOF
|
270
|
+
|
271
|
+
class << self
|
272
|
+
@@characters ||= CHARACTERS.gsub(?`.freeze, ?\u2588).strip.split(/#+/).reduce({}) do |x, y|
|
273
|
+
y.lstrip!
|
274
|
+
lines = y[1..-1]
|
275
|
+
next x unless y && lines
|
276
|
+
max = lines.lines.max_by(&:length).length + 1
|
277
|
+
|
278
|
+
hash = {
|
279
|
+
y[0] => lines.lines.each { |z| z.replace(z.chomp.ljust(max) + NEWLINE) }.join
|
280
|
+
}
|
281
|
+
|
282
|
+
x.merge!(hash)
|
283
|
+
end.freeze
|
284
|
+
|
285
|
+
def transform_characters!(arg)
|
286
|
+
@@characters.values.each { |x|
|
287
|
+
stripped = x.strip[0]
|
288
|
+
x.gsub!(stripped, arg) if stripped
|
289
|
+
}
|
290
|
+
end
|
291
|
+
|
292
|
+
def display(c)
|
293
|
+
j = ['', '']
|
294
|
+
|
295
|
+
c.upcase.chars.map! { |x|
|
296
|
+
@@characters.fetch(x, x).split(?\n.freeze)
|
297
|
+
.each_with_index { |z, i|
|
298
|
+
_j = j[i]
|
299
|
+
_j && _j << z || j[i] = z
|
300
|
+
}
|
301
|
+
}
|
302
|
+
|
303
|
+
j.join(?\n.freeze)
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
class String
|
2
|
+
def gradient(*all_rgbs, bg: false, exclude_spaces: false)
|
3
|
+
temp = ''
|
4
|
+
|
5
|
+
r, g, b = all_rgbs[0]
|
6
|
+
r2, g2, b2 = all_rgbs[1]
|
7
|
+
rotate = all_rgbs.length > 2
|
8
|
+
|
9
|
+
init = bg ? 48 : 38
|
10
|
+
|
11
|
+
each_line do |c|
|
12
|
+
_r, _g, _b = r, g, b
|
13
|
+
chomped = !!c.chomp!(''.freeze)
|
14
|
+
|
15
|
+
len = c.length
|
16
|
+
n_variable = exclude_spaces ? c.delete("\t\s".freeze).length : len
|
17
|
+
n_variable -= 1
|
18
|
+
n_variable = 1 if n_variable < 1
|
19
|
+
|
20
|
+
# colour operator, colour value
|
21
|
+
r_op = r_val = nil
|
22
|
+
g_op = g_val = nil
|
23
|
+
b_op = b_val = nil
|
24
|
+
|
25
|
+
if r2 > r
|
26
|
+
r_op, r_val = :+, r2.-(r).fdiv(n_variable)
|
27
|
+
elsif r2 < r
|
28
|
+
r_op, r_val = :-, r.-(r2).fdiv(n_variable)
|
29
|
+
end
|
30
|
+
|
31
|
+
if g2 > g
|
32
|
+
g_op, g_val = :+, g2.-(g).fdiv(n_variable)
|
33
|
+
elsif g2 < g
|
34
|
+
g_op, g_val = :-, g.-(g2).fdiv(n_variable)
|
35
|
+
end
|
36
|
+
|
37
|
+
if b2 > b
|
38
|
+
b_op, b_val = :+, b2.-(b).fdiv(n_variable)
|
39
|
+
elsif b2 < b
|
40
|
+
b_op, b_val = :-, b.-(b2).fdiv(n_variable)
|
41
|
+
end
|
42
|
+
|
43
|
+
# To avoid the value getting adding | subtracted from the initial character
|
44
|
+
_r = _r.send(r_op, r_val * -1) if r_op
|
45
|
+
_g = _g.send(g_op, g_val * -1) if g_op
|
46
|
+
_b = _b.send(b_op, b_val * -1) if b_op
|
47
|
+
|
48
|
+
i = -1
|
49
|
+
while (i += 1) < len
|
50
|
+
_c = c[i]
|
51
|
+
|
52
|
+
if !exclude_spaces || (exclude_spaces && !(_c == ?\s.freeze || _c == ?\t.freeze))
|
53
|
+
_r = _r.send(r_op, r_val) if r_op
|
54
|
+
_g = _g.send(g_op, g_val) if g_op
|
55
|
+
_b = _b.send(b_op, b_val) if b_op
|
56
|
+
end
|
57
|
+
|
58
|
+
r_to_i = _r.to_i
|
59
|
+
g_to_i = _g.to_i
|
60
|
+
b_to_i = _b.to_i
|
61
|
+
|
62
|
+
f_r = r_to_i < 0 ? 0 : r_to_i > 255 ? 255 : r_to_i
|
63
|
+
f_g = g_to_i < 0 ? 0 : g_to_i > 255 ? 255 : g_to_i
|
64
|
+
f_b = b_to_i < 0 ? 0 : b_to_i > 255 ? 255 : b_to_i
|
65
|
+
|
66
|
+
ret = "\e[#{init};2;#{f_r};#{f_g};#{f_b}m#{_c}"
|
67
|
+
temp << ret
|
68
|
+
end
|
69
|
+
|
70
|
+
ret = if !c.empty?
|
71
|
+
chomped ? "\e[0m\n".freeze : "\e[0m".freeze
|
72
|
+
elsif chomped
|
73
|
+
?\n.freeze
|
74
|
+
end
|
75
|
+
|
76
|
+
temp << ret
|
77
|
+
|
78
|
+
if rotate
|
79
|
+
all_rgbs.rotate!
|
80
|
+
r, g, b = all_rgbs[0]
|
81
|
+
r2, g2, b2 = all_rgbs[1]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
temp
|
86
|
+
end
|
87
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: termclock
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sourav Goswami
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-01-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A clock for Linux VTE
|
14
|
+
email:
|
15
|
+
- souravgoswami@protonmail.com
|
16
|
+
executables:
|
17
|
+
- termclock
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- exe/termclock
|
22
|
+
- lib/termclock.rb
|
23
|
+
- lib/termclock/hex2rgb.rb
|
24
|
+
- lib/termclock/main.rb
|
25
|
+
- lib/termclock/parse_characters.rb
|
26
|
+
- lib/termclock/string.rb
|
27
|
+
- lib/termclock/version.rb
|
28
|
+
homepage: https://github.com/souravgoswami/termclock
|
29
|
+
licenses:
|
30
|
+
- MIT
|
31
|
+
metadata: {}
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.5.0
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubygems_version: 3.1.4
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: A clock for Linux VTE
|
51
|
+
test_files: []
|