termclock 0.1.2 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e17d6410f4890cf9e070491f01c722e08b3678dca7e0cf4af4edfa3e4a6c020
4
- data.tar.gz: a00abd3c09b311a4fa62acd03c5147033a7c758417877db2d132e1b3d5e954b2
3
+ metadata.gz: a889b38c921c98e808156b9feeee5dccb8ad10952a17f2b591ed14b6297f2075
4
+ data.tar.gz: 2676b0ba7b8ad4d2b604282845d2fe4d7101eb5a0c39d076833195e6ada67bfd
5
5
  SHA512:
6
- metadata.gz: 40822adf435db689057290c054ea2f42a9afff94cd49053aed5d5ddf3b0dcbb168e7ce23fe3e130afbcb43c58f128bd689d1243bca52015ac245b44b05e24440
7
- data.tar.gz: 9aa729c8ee4fb0b299da55f666a942ef21cccfc66ff94a5b54969594d8dc80aec38361c9c779cf813a312d89089589fb3e9c8010c31d05181a0435549fcfeac1
6
+ metadata.gz: 04e505fe18c33d49dcc050e3bf06a2ef2484c38b4b0b6b3d5f00ccb47a5551973641621411304342e3314b8255893db00aef62b775fecac001726347e80f5045
7
+ data.tar.gz: b7c740f14ee7df1ed1c4c4774f0696eb20c84850eec4b402a8fde75f6864bf6a068465a114680095dd5453fb00bcf33a08c4607a46efefa535dcb033cda8e556
@@ -1,7 +1,58 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'termclock'
3
+ $-v = nil
3
4
 
4
- $-v = true
5
+ if ARGV.any? { |x| x[/\A\-(\-help|h)\z/] }
6
+ puts <<~EOF
7
+ TermClock: A clock that runs on the LinuxTerminal!
8
+
9
+ \e[1;4mArguments:\e[0m
10
+
11
+ 1. Help and Version:\e[0m
12
+ --help|-h\t\t\tShows this help section
13
+ --version|-v\t\t\tShows termclock version
14
+
15
+ 2. Style:\e[0m
16
+ --bold|-b\t\t\tMake texts bold
17
+ --italic|-i\t\t\tMake texts italic
18
+ --character=|char=\t\tDraws specified character
19
+ --clean\t\t\t\tJust run the clean bare clock
20
+ --colour=|-c=\t\t\tSpecify hex colour (4 colours)
21
+ \t\t\t\t[ with or without # ]
22
+
23
+ 3. Information:\e[0m
24
+ --no-date|-nd\t\t\tShows no date
25
+ --no-message|-nm\t\tShows no messages
26
+ --no-sysinfo|-ni\t\tShows no system info
27
+ --refresh|r\t\t\tSpecify delay or refresh time
28
+ --text-colour|-tc\t\tSpecify text colour (2 colours)
29
+
30
+ 4. Formats:\e[0m
31
+ --date-format=|-df=\t\tSpecify the date format
32
+ \t\t\t\t[ Run date --help for formats ]
33
+ --time-format=|-tf=\t\tSpecify the time format
34
+ \t\t\t\t[ Run date --help for formats ]
35
+
36
+ Supported characters are 0 - 9, a - z, /, \\, !, %, and |.
37
+
38
+ This is Termclock v#{Termclock::VERSION}
39
+ EOF
40
+
41
+ exit 0
42
+ end
43
+
44
+ if ARGV.any? { |x| x[/\A\-(-version|v)\z/] }
45
+ colour = [
46
+ [[255, 100, 100], [100, 100, 255]],
47
+ [[60, 230, 180], [100, 100, 255]],
48
+ [[255, 255, 0], [100, 100, 255]],
49
+ [[255, 80, 170], [255, 200, 0]],
50
+ ].sample
51
+
52
+ colour.reverse! if rand < 0.5
53
+ puts "This is Termclock v#{Termclock::VERSION}".gradient(*colour)
54
+ exit 0
55
+ end
5
56
 
6
57
  begin
7
58
  print "\e[?25l"
@@ -24,9 +75,45 @@ begin
24
75
  }
25
76
 
26
77
  chars = ARGV.find { |x| x[/\A\-(\-character|char)=.*\z/] } &.split(?=) &.at(1)
27
- Termclock::ParseCharacters.transform_characters!(chars[0]) if chars
78
+ Termclock::ParseCharacters.transform_characters!(*chars) if chars
79
+
80
+ _refresh_time = ARGV.find { |x| x[/\A\-(\-refresh|r)=.*\z/] } &.split(?=) &.at(1)
81
+ refresh_time = _refresh_time ? _refresh_time.to_f : 0.1
82
+
83
+ _time_format = ARGV.find { |x| x[/\A\-(\-time\-format|tf)=.*\z/] } &.split(?=) &.at(1)
84
+ time_format = _time_format ? _time_format : "%H %M %S %2N"
85
+
86
+ _date_format = ARGV.find { |x| x[/\A\-(\-date\-format|df)=.*\z/] } &.split(?=) &.at(1)
87
+ date_format = _date_format ? _date_format : "'%a, %d %B %Y'"
88
+
89
+ text_colours = ARGV.find { |x| x[/\A\-(\-text\-colour|tc)=.*\z/] } &.split(?=) &.at(1) &.split(?,)
90
+ abort("Text colours need 2 colours. Example: -tc=55f,3ce3b5") if text_colours && text_colours.length != 2
91
+
92
+ bold = ARGV.any? { |x| x[/\A\-(\-bold|b)\z/] }
93
+ italic = ARGV.any? { |x| x[/\A\-(\-italic|i)\z/] }
94
+
95
+ no_print_info = ARGV.any? { |x| x[/\A\-(\-no\-sysinfo|ni)\z/] }
96
+ no_print_message = ARGV.any? { |x| x[/\A\-(\-no\-message|nm)\z/] }
97
+ no_print_date = ARGV.any? { |x| x[/\A\-(\-no\-date|nd)\z/] }
98
+
99
+ clean = ARGV.any? { |x| x[/\A\-(\-clean)\z/] }
100
+
101
+ if clean
102
+ no_print_info = no_print_message = no_print_date = true
103
+ end
28
104
 
29
- Termclock.main(*colours)
105
+ Termclock.start(
106
+ *colours,
107
+ *text_colours,
108
+ sleep: refresh_time,
109
+ bold: bold,
110
+ italic: italic,
111
+ print_info: !no_print_info,
112
+ print_message: !no_print_message,
113
+ print_date: !no_print_date,
114
+ time_format: time_format,
115
+ date_format: date_format
116
+ )
30
117
  rescue Interrupt, SignalException
31
118
  print "\e[H\e[2J\e[3J"
32
119
  ensure
@@ -1,12 +1,17 @@
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'
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
+
8
12
  require_relative "termclock/string"
9
13
  require_relative "termclock/parse_characters"
10
- require_relative "termclock/main"
14
+ require_relative "termclock/system_info"
15
+ require_relative "termclock/start"
11
16
  require_relative "termclock/hex2rgb"
12
17
  require_relative "termclock/version"
@@ -1,83 +1,82 @@
1
1
  module Termclock
2
2
  module ParseCharacters
3
- NEWLINE = ?\n.freeze
4
3
  CHARACTERS = <<~EOF.freeze
5
4
  # 0
6
- ```````
7
- `` ``
8
- `` ``
9
- `` ``
10
- ```````
5
+ ````````
6
+ `` ``
7
+ `` ``
8
+ `` ``
9
+ ````````
11
10
 
12
11
  # 1
13
12
  ``
14
- ````
13
+ `````
15
14
  ``
16
15
  ``
17
- ```````
16
+ ````````
18
17
 
19
18
  # 2
20
- ```````
21
- ``
22
- ```````
19
+ ````````
20
+ ``
21
+ ````````
23
22
  ``
24
- ```````
23
+ ````````
25
24
 
26
25
  # 3
27
- ```````
28
- ``
29
- ```````
30
- ``
31
- ```````
26
+ ````````
27
+ ``
28
+ ````````
29
+ ``
30
+ ````````
32
31
 
33
32
  # 4
34
- `` ``
35
- `` ``
36
- ```````
37
- ``
38
- ``
33
+ `` ``
34
+ `` ``
35
+ ````````
36
+ ``
37
+ ``
39
38
 
40
39
  # 5
41
- ```````
40
+ ````````
42
41
  ``
43
- ```````
44
- ``
45
- ```````
42
+ ````````
43
+ ``
44
+ ````````
46
45
 
47
46
  # 6
48
- ```````
47
+ ````````
49
48
  ``
50
- ```````
51
- `` ``
52
- ```````
49
+ ````````
50
+ `` ``
51
+ ````````
53
52
 
54
53
  # 7
55
- ```````
56
- ``
57
- ``
58
- ``
59
- ``
54
+ ````````
55
+ ``
56
+ ``
57
+ ``
58
+ ``
60
59
 
61
60
  # 8
62
- ```````
63
- `` ``
64
- ```````
65
- `` ``
66
- ```````
61
+ ````````
62
+ `` ``
63
+ ````````
64
+ `` ``
65
+ ````````
67
66
 
68
67
  # 9
69
- ```````
70
- `` ``
71
- ```````
72
- ``
73
- ```````
68
+ ````````
69
+ `` ``
70
+ ````````
71
+ ``
72
+ ````````
74
73
 
75
74
  # :
76
- ⬩⬩
77
- ⬩⬩
75
+ \u2B29\u2B29
76
+ \u2B29\u2B29
78
77
 
79
- ⬩⬩
80
- ⬩⬩
78
+ \u2B29\u2B29
79
+ \u2B29\u2B29
81
80
 
82
81
  # $
83
82
  \s\s
@@ -86,88 +85,88 @@ module Termclock
86
85
  \s\s
87
86
  \s\s
88
87
  # A
89
- ```````
90
- `` ``
91
- ```````
92
- `` ``
93
- `` ``
88
+ ````````
89
+ `` ``
90
+ ````````
91
+ `` ``
92
+ `` ``
94
93
 
95
94
  # B
96
- ``````
97
- `` ``
98
- ``````
99
- `` ``
100
- ``````
95
+ ````````
96
+ `` ``
97
+ ````````
98
+ `` ``
99
+ ````````
101
100
 
102
101
  # C
103
- ```````
102
+ ````````
104
103
  ``
105
104
  ``
106
105
  ``
107
- ```````
106
+ ````````
108
107
 
109
108
  # D
110
- `````
111
- `` ``
112
- `` ``
113
- `` ``
114
- `````
109
+ ````````
110
+ `` ``
111
+ `` ``
112
+ `` ``
113
+ ````````
115
114
 
116
115
  # E
117
- ```````
116
+ ````````
118
117
  ``
119
- ```````
118
+ ````````
120
119
  ``
121
- ```````
120
+ ````````
122
121
 
123
122
  # F
124
- ```````
123
+ ````````
125
124
  ``
126
- ```````
125
+ ````````
127
126
  ``
128
127
  ``
129
128
 
130
129
  # G
131
- ```````
130
+ ````````
132
131
  ``
133
132
  ``
134
- `` ```
133
+ `` ````
135
134
  ````````
136
135
 
137
136
  # H
138
- `` ``
139
- `` ``
140
- ```````
141
- `` ``
142
- `` ``
137
+ `` ``
138
+ `` ``
139
+ ````````
140
+ `` ``
141
+ `` ``
143
142
 
144
143
  # I
145
- ```````
146
- `
147
- `
148
- `
149
- ```````
144
+ ````````
145
+ \s\s\s``
146
+ \s\s\s``
147
+ \s\s\s``
148
+ ````````
150
149
 
151
150
  # J
152
- ```````
153
- ``
154
- ``
155
- `` ``
156
- ``````
151
+ ````````
152
+ ``
153
+ ``
154
+ `` ``
155
+ ```````
157
156
 
158
157
  # K
159
- `` ``
160
- `` ``
161
- ````
162
- `` ``
163
- `` ``
158
+ `` ``
159
+ `` ``
160
+ `````
161
+ `` ``
162
+ `` ``
164
163
 
165
164
  # L
166
165
  ``
167
166
  ``
168
167
  ``
169
168
  ``
170
- ``````
169
+ ````````
171
170
 
172
171
  # M
173
172
  ``` ```
@@ -177,11 +176,11 @@ module Termclock
177
176
  `` ``
178
177
 
179
178
  # N
180
- ```` ``
181
- `` ` ``
182
- `` ` ``
183
- `` ` ``
184
- `` ```
179
+ ```` ``
180
+ `` `` ``
181
+ `` `` ``
182
+ `` `` ``
183
+ `` ````
185
184
 
186
185
  # O
187
186
  ````````
@@ -198,25 +197,25 @@ module Termclock
198
197
  ``
199
198
 
200
199
  # Q
201
- ```````
202
- `` ``
203
- ```````
204
- ``
205
- ``
200
+ ````````
201
+ `` ``
202
+ ````````
203
+ ``
204
+ ``
206
205
 
207
206
  # R
208
- ```````
207
+ ````````
208
+ `` ``
209
+ ````````
210
+ `````
209
211
  `` ``
210
- ```````
211
- ````
212
- `` ``
213
212
 
214
213
  # S
215
- ```````
214
+ ````````
216
215
  ``
217
- ```````
218
- ``
219
- ```````
216
+ ````````
217
+ ``
218
+ ````````
220
219
 
221
220
  # T
222
221
  ````````
@@ -226,32 +225,32 @@ module Termclock
226
225
  ``
227
226
 
228
227
  # U
229
- `` ``
230
- `` ``
231
- `` ``
232
- `` ``
233
- ```````
228
+ `` ``
229
+ `` ``
230
+ `` ``
231
+ `` ``
232
+ ````````
234
233
 
235
234
  # V
236
- `` ``
237
- `` ``
238
- `` ``
239
- `` ``
240
- `
235
+ `` ``
236
+ `` ``
237
+ `` ``
238
+ \s`` ``\s
239
+ \s\s\s``
241
240
 
242
241
  # W
243
- `` ``
244
- `` ``
245
- `` ``
246
- `` ` ``
247
- `````````
242
+ `` ``
243
+ `` ``
244
+ `` ``
245
+ `` ` ``
246
+ ````````
248
247
 
249
248
  # X
250
- `` ``
251
- `` ``
252
- ``
253
- `` ``
254
- `` ``
249
+ `` ``
250
+ \s`` ``
251
+ \s\s\s``
252
+ \s`` ``
253
+ `` ``
255
254
 
256
255
  # Y
257
256
  `` ``
@@ -266,6 +265,41 @@ module Termclock
266
265
  ``
267
266
  ``
268
267
  ````````
268
+
269
+ # /
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
+ # \\
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
+ # %
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
+ # |
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
+ # !
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
@@ -283,24 +317,38 @@ module Termclock
283
317
  end.freeze
284
318
 
285
319
  def transform_characters!(arg)
320
+ @@transformed ||= nil
321
+ fail RuntimeError, 'Characters already transformed!' if @@transformed
322
+ @@transformed ||= true
323
+
286
324
  @@characters.values.each { |x|
287
325
  stripped = x.strip[0]
288
- x.gsub!(stripped, arg) if stripped
326
+ chars = arg.chars.rotate(-1)
327
+
328
+ if stripped
329
+ replace_with = x.chars.map { |y|
330
+ chars = arg.chars.rotate(-1) if y == NEWLINE
331
+ next(y) if y != stripped
332
+ chars.rotate!(1)[0]
333
+ }.join
334
+
335
+ x.replace(replace_with)
336
+ end
289
337
  }
290
338
  end
291
339
 
292
340
  def display(c)
293
- j = ['', '']
341
+ j = []
294
342
 
295
- c.upcase.chars.map! { |x|
296
- @@characters.fetch(x, x).split(?\n.freeze)
343
+ c.upcase.each_char { |x|
344
+ @@characters.fetch(x, x).split(NEWLINE)
297
345
  .each_with_index { |z, i|
298
346
  _j = j[i]
299
347
  _j && _j << z || j[i] = z
300
348
  }
301
349
  }
302
350
 
303
- j.join(?\n.freeze)
351
+ j.join(NEWLINE)
304
352
  end
305
353
  end
306
354
  end
@@ -0,0 +1,155 @@
1
+ module Termclock
2
+ def self.start(colour1, colour2, colour3, colour4,
3
+ textcolour1 = nil, textcolour2 = nil,
4
+ sleep: 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
+ )
12
+
13
+ generate = proc do |start, stop, n = 5|
14
+ r_op = r_val = nil
15
+ ary = []
16
+
17
+ if start > stop
18
+ r_op, r_val = :-, start.-(stop).fdiv(n - 1)
19
+ elsif start < stop
20
+ r_op, r_val = :+, stop.-(start).fdiv(n - 1)
21
+ end
22
+
23
+ _r = r_op ? start.send(r_op, r_val * -1) : start
24
+ n.times {
25
+ _r = _r.send(r_op, r_val) if r_op
26
+ ary << _r.clamp(0, 255).to_i
27
+ }
28
+
29
+ ary
30
+ end
31
+
32
+ gc_compact, gc_compacted = GC.respond_to?(:compact), Time.now.to_i + 7200
33
+ print "\e[H\e[2J\e[3J" unless COLOURTERM
34
+
35
+ r1, g1, b1 = *colour1
36
+ r2, g2, b2 = *colour2
37
+ r3, g3, b3 = *colour3
38
+ r4, g4, b4 = *colour4
39
+
40
+ # colour1 -> colour3
41
+ rs1 = generate.(r1, r3)
42
+ gs1 = generate.(g1, g3)
43
+ bs1 = generate.(b1, b3)
44
+
45
+ # colour2 -> colour4
46
+ rs2 = generate.(r2, r4)
47
+ gs2 = generate.(g2, g4)
48
+ bs2 = generate.(b2, b4)
49
+
50
+ # All Gradient Colours
51
+ colours = [rs1, gs1, bs1].transpose.zip([rs2, gs2, bs2].transpose)
52
+ colours.unshift(colours[0])
53
+ colours.push(colours[-1])
54
+
55
+ # Text colours
56
+ tc1 = textcolour1 ? hex2rgb(textcolour1) : hex2rgb('5555ff')
57
+ tc2 = textcolour2 ? hex2rgb(textcolour2) : hex2rgb('3ce3b5')
58
+
59
+ cpu_usage = 0
60
+ cpu_usage_t = Thread.new { }
61
+
62
+ current_net_usage = ''
63
+ current_net_usage_t = Thread.new { }
64
+
65
+ message_time = Time.now.to_i - 5
66
+ message_counter = -1
67
+ message = ''
68
+ message_final = ''
69
+ message_temp = ''
70
+ caret = "\u2588"
71
+
72
+ date, info = '', ''
73
+
74
+ get_message = proc {
75
+ case Time.now.hour
76
+ when 5...12
77
+ "\u{1F304} Good Morning..."
78
+ when 12...16
79
+ "\u26C5 Good Afternoon..."
80
+ when 16...18
81
+ "\u{1F307} Good Evening..."
82
+ when 18...20
83
+ "\u{1F31F} Good Evening..."
84
+ when 20...24
85
+ "\u{1F303} Good Night..."
86
+ else
87
+ "\u{2728} Good Night..."
88
+ end
89
+ }
90
+
91
+ while true
92
+ time_now = Time.now
93
+ height, width = *STDOUT.winsize
94
+
95
+ if time_now.to_f./(0.5).to_i.even?
96
+ splitter = ?:.freeze
97
+ _caret = caret
98
+ else
99
+ splitter = ?$.freeze
100
+ _caret = ''
101
+ end
102
+
103
+ if print_message
104
+ message_counter += 1
105
+ message_align = width - message_counter % width + message.length / 2 - 4
106
+ if (width - message_counter % width <= message.length)
107
+ message.replace(message[1..-1])
108
+ message_align = width - message_counter % width + 4
109
+ else
110
+ message.clear if width - message_counter % width == width
111
+ message_temp = get_message.call
112
+
113
+ if message_temp != message
114
+ message << message_temp[message.length..message.length + 1]
115
+ end
116
+ end
117
+
118
+ message_final = message.rjust(message_align).+(_caret).gradient(
119
+ tc1, tc2, exclude_spaces: true, bold: bold, italic: italic
120
+ )
121
+ end
122
+
123
+ if print_info
124
+ info = system_info(width).gradient(
125
+ tc1, tc2, bold: bold, italic: italic
126
+ )
127
+ end
128
+
129
+ if print_date
130
+ date = time_now.strftime(date_format).center(width)
131
+ .gradient(tc1, tc2, bold: bold, italic: italic)
132
+ end
133
+
134
+ time = time_now.strftime(time_format).split.join(splitter)
135
+ art = Termclock::ParseCharacters.display(time).lines
136
+
137
+ art_aligned = art.each_with_index do |x, i|
138
+ chomped = x.chomp(''.freeze).+(NEWLINE)
139
+ gr = chomped.gradient(*colours[i], bold: bold, italic: italic)
140
+ x.replace(SPACE.*(width./(2.0).-(chomped.length / 2.0).abs.to_i + 1) + gr)
141
+ end.join
142
+
143
+ vertical_gap = "\e[#{height./(2.0).-(art.length / 2.0).to_i + 1}H"
144
+
145
+ print "#{CLEAR}#{info}#{vertical_gap}#{art_aligned}\n#{date}\n\n#{message_final}"
146
+
147
+ if gc_compact && time_now.to_i > gc_compacted
148
+ GC.compact
149
+ gc_compacted = time_now.to_i + 7200
150
+ end
151
+
152
+ sleep(sleep)
153
+ end
154
+ end
155
+ end
@@ -1,5 +1,14 @@
1
1
  class String
2
- def gradient(*all_rgbs, bg: false, exclude_spaces: false)
2
+ NEWLINE = ?\n.freeze
3
+ SPACE = ?\s.freeze
4
+ TAB = ?\t.freeze
5
+
6
+ def gradient(*all_rgbs,
7
+ bg: false,
8
+ exclude_spaces: false,
9
+ bold: false, italic: false, blink: false
10
+ )
11
+
3
12
  temp = ''
4
13
 
5
14
  r, g, b = all_rgbs[0]
@@ -8,7 +17,18 @@ class String
8
17
 
9
18
  init = bg ? 48 : 38
10
19
 
20
+ style = nil
21
+ if bold || italic
22
+ style = "\e["
23
+ style << '1;'.freeze if bold
24
+ style << '3;'.freeze if italic
25
+ style.chop!
26
+ style << 'm'.freeze
27
+ end
28
+
11
29
  each_line do |c|
30
+ temp << style if style
31
+
12
32
  _r, _g, _b = r, g, b
13
33
  chomped = !!c.chomp!(''.freeze)
14
34
 
@@ -49,7 +69,7 @@ class String
49
69
  while (i += 1) < len
50
70
  _c = c[i]
51
71
 
52
- if !exclude_spaces || (exclude_spaces && !(_c == ?\s.freeze || _c == ?\t.freeze))
72
+ if !exclude_spaces || (exclude_spaces && !(_c == SPACE || _c == TAB))
53
73
  _r = _r.send(r_op, r_val) if r_op
54
74
  _g = _g.send(g_op, g_val) if g_op
55
75
  _b = _b.send(b_op, b_val) if b_op
@@ -70,7 +90,7 @@ class String
70
90
  ret = if !c.empty?
71
91
  chomped ? "\e[0m\n".freeze : "\e[0m".freeze
72
92
  elsif chomped
73
- ?\n.freeze
93
+ NEWLINE
74
94
  end
75
95
 
76
96
  temp << ret
@@ -0,0 +1,81 @@
1
+ module Termclock
2
+ @@cpu_usage = 0
3
+ @@cpu_usage_t = Thread.new { }.join
4
+
5
+ @@current_net_usage = "\u{1F4CA} Curr. DL/UL:"
6
+ @@current_net_usage_t = Thread.new { }.join
7
+
8
+ class << self
9
+ def system_info(width)
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
+ pt = LS::Process.types.values
61
+
62
+ process = "\u{1F9EE} Process: T:#{sprintf "%4s", LS::Process.count}|"\
63
+ "R:#{sprintf "%3s", pt.count(:running)}|"\
64
+ "S:#{sprintf "%3s", pt.count(:sleeping)}|"\
65
+ "I:#{sprintf "%3s", pt.count(:idle)}"
66
+
67
+ os = "\u{1F427} Distrib: #{LS::OS.distribution} #{LS::OS.machine} (#{LS::OS.version})"
68
+
69
+ max_l = [hostname, process, ip, battery, @@current_net_usage, net_usage].map(&:length).max + 4
70
+
71
+ <<~STR
72
+ \s#{user}#{SPACE.*(width.-(user.length + max_l).abs)}#{hostname}
73
+ \s#{os}#{SPACE.*(width.-(os.length + max_l).abs)}#{battery}
74
+ \s#{cpu}#{SPACE.*(width.-(cpu.length + max_l).abs)}#{ip}
75
+ \s#{memory}#{SPACE.*(width.-(memory.length + max_l).abs)}#{@@current_net_usage}
76
+ \s#{swap}#{SPACE.*(width.-(swap.length + max_l).abs)}#{net_usage}
77
+ \s#{fs}#{SPACE.*(width.-(fs.length + max_l).abs)}#{process}
78
+ STR
79
+ end
80
+ end
81
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Termclock
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: termclock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.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-12 00:00:00.000000000 Z
11
+ date: 2021-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: linux_stat
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.3.0
19
+ version: 1.3.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.3.0
26
+ version: 1.3.1
27
27
  description: A clock for Linux VTE
28
28
  email:
29
29
  - souravgoswami@protonmail.com
@@ -35,9 +35,10 @@ 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
+ - lib/termclock/system_info.rb
41
42
  - lib/termclock/version.rb
42
43
  homepage: https://github.com/souravgoswami/termclock
43
44
  licenses:
@@ -1,168 +0,0 @@
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 5...12
57
- "\u{1F304} Good Morning..."
58
- when 12...16
59
- "\u26C5 Good Afternoon..."
60
- when 16...18
61
- "\u{1F307} Good Evening..."
62
- when 18...20
63
- "\u{1F31F} Good Evening..."
64
- when 20...24
65
- "\u{1F303} Good Night..."
66
- else
67
- "\u{2728} Good Night..."
68
- end
69
- }
70
-
71
- i = -1
72
-
73
- while true
74
- i += 1
75
- time_now = Time.now
76
- height, width = *STDOUT.winsize
77
-
78
- message_align = width - i % width + message.length / 2 - 4
79
-
80
- if (width - i % width <= message.length)
81
- message.replace(message[1..-1])
82
- message_align = width - i % width + 4
83
- else
84
- message.clear if width - i % width == width
85
- message_temp = get_message.call
86
-
87
- if message_temp != message
88
- message << message_temp[message.length..message.length + 1]
89
-
90
- end
91
- end
92
-
93
- if time_now.to_f./(0.5).to_i.even?
94
- splitter = ?:.freeze
95
- _caret = caret
96
- else
97
- splitter = ?$.freeze
98
- _caret = ''
99
- end
100
-
101
- time = time_now.strftime("%H %M %S %2N").split.join(splitter)
102
- art = Termclock::ParseCharacters.display(time)
103
-
104
- art_aligned = art.lines.each_with_index do |x, i|
105
- chomped = x.chomp(''.freeze).+(newline)
106
- gr = chomped.gradient(*colours[i])
107
- x.replace(space.*(width./(2.0).-(chomped.length / 2.0).abs.to_i + 1) + gr)
108
- end.join
109
-
110
- horizontal_gap = "\e[#{height./(2.0).-(art.lines.length / 2.0).to_i + 1}H"
111
-
112
- unless cpu_usage_t.alive?
113
- cpu_usage_t = Thread.new { cpu_usage = LS::CPU.usage(0.25) }
114
- end
115
-
116
- cpu = "\u{1F9E0} CPU: #{cpu_usage}% (#{LS::CPU.count_online} / #{LS::CPU.count})"
117
-
118
- battery = if LS::Battery.present?
119
- stat = LS::Battery.stat
120
- emoji = LS::Battery.charging? ? "\u{1F4A1}" : "\u{1F50B}"
121
- "#{emoji} Battery: #{stat[:charge].to_i}% (#{stat[:status]})"
122
- else
123
- ''.freeze
124
- end
125
-
126
- _m = LS::Net.total_bytes
127
- ip = "\u{1F30F} IP: #{LS::Net.ipv4_private}"
128
- net_usage = "\u{1F4C8} D/L | U/L: #{LS::PrettifyBytes.convert_short_binary(_m[:received].to_i)}"\
129
- " | #{LS::PrettifyBytes.convert_short_binary(_m[:transmitted].to_i)}"
130
-
131
- _m = LS::Memory.stat
132
- memory = "\u{1F3B0} Mem: #{LS::PrettifyBytes.convert_short_binary(_m[:used].to_i * 1024)}"\
133
- " / #{LS::PrettifyBytes.convert_short_binary(_m[:total].to_i * 1024)}"\
134
- " (#{_m[:percent_used].to_i}%)"
135
-
136
- _m = LS::Swap.stat
137
- swap = "\u{1F300} Swap: #{LS::PrettifyBytes.convert_short_binary(_m[:used].to_i * 1024)}"\
138
- " / #{LS::PrettifyBytes.convert_short_binary(_m[:total].to_i * 1024)}"\
139
- " (#{_m[:percent_used].to_i}%)"
140
-
141
- _m = LS::Filesystem.stat
142
- fs = "\u{1F4BD} FS: #{LS::PrettifyBytes.convert_short_binary(_m[:used].to_i)}"\
143
- " / #{LS::PrettifyBytes.convert_short_binary(_m[:total].to_i)}"\
144
- " (#{_m[:used].to_i*(100).fdiv(_m[:total].to_i).round(2)}%)"
145
-
146
- process = "\u{1F9EE} Process: #{LS::Process.count}"
147
-
148
- max_l = [process, ip, battery, net_usage].map(&:length).max
149
-
150
- info = <<~EOF.gradient(*colours[2], exclude_spaces: true)
151
- \s#{cpu}#{?\s.*(width.-(cpu.length + max_l + 4).abs)}#{battery}
152
- \s#{memory}#{?\s.*(width.-(memory.length + max_l + 4).abs)}#{ip}
153
- \s#{swap}#{?\s.*(width.-(swap.length + max_l + 4).abs)}#{net_usage}
154
- \s#{fs}#{?\s.*(width.-(fs.length + max_l + 4).abs)}#{process}
155
- EOF
156
-
157
- print "#{CLEAR}#{info}#{horizontal_gap}#{art_aligned}\n"\
158
- "#{message.rjust(message_align).+(_caret).gradient(*colours[1], exclude_spaces: true)}"
159
-
160
- if gc_compact && time_now.to_i > gc_compacted
161
- GC.compact
162
- gc_compacted = time_now.to_i + 7200
163
- end
164
-
165
- sleep(sleep)
166
- end
167
- end
168
- end