termclock 0.1.1 → 0.1.6

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: 4d1c858f80500fc5d7a8b8eeff7a92eabaa11456017c0cc0abedf093739760af
4
- data.tar.gz: 8ac53cf8b969ac9a0e749724691885fadbef7f56c3b61f267c0706b355f5592f
3
+ metadata.gz: '0916f4a4beb06eae575611343e1235e5fa9a0585116fd9694622d1a5e9867938'
4
+ data.tar.gz: 53f9236790df604fe8eb5f0c1a4d0cb5ed0179c6aed3c04da4ae8b26398269ee
5
5
  SHA512:
6
- metadata.gz: 36afe4651723caf9b4aca777be0cf50d8bb5ef2fe78570272ecf114ab1fe112d38633e9aa6b3169bff98923299a41f3e9a1d22d4376fd8fe1cde11b2dd810058
7
- data.tar.gz: 9393626eaf8a1260f890692e72f3e0894fee07f6348e7ac1c3399c268f86bf45bb111bd812fc902cccc1e095b8a053eb6fcbd34e7bb56009dd7db92599f9b65f
6
+ metadata.gz: f85098f0082eca3776b0349b65a34323491c8372cf2b426c91bedde2d5031be210da5fe49d36f773a95afdc9fc6907bbcc9b7e1e3d5e863624106d8e4112ac8f
7
+ data.tar.gz: a116f54e530fdfcecfc7f415812aa107bddd7e98409090acbd2f039aefccf0db937f47a8f441d5fa35b1fbe75974ff8795745d3a63da28187c85f275090fb24e
@@ -1,7 +1,27 @@
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
+ Arguments:
10
+ --help|-h\t\t\tShows this help section
11
+ --bold\t\t\t\tMake texts bold
12
+ --character=|char=\t\tDraws specified character
13
+ --clean\t\t\t\tJust run the clean bare clock
14
+ --colour=|-c=\t\t\tSpecify hex colour (4 colours)
15
+ \t\t\t\t[ with or without # ]
16
+ --no-date|-nd\t\t\tShows no date
17
+ --no-message|-nm\t\tShows no messages
18
+ --no-sysinfo|-ni\t\tShows no system info
19
+ --refresh|r\t\t\tSpecify delay or refresh time
20
+ --text-colour|-tc\t\tSpecify text colour (2 colours)
21
+ EOF
22
+
23
+ exit 0
24
+ end
5
25
 
6
26
  begin
7
27
  print "\e[?25l"
@@ -24,9 +44,34 @@ begin
24
44
  }
25
45
 
26
46
  chars = ARGV.find { |x| x[/\A\-(\-character|char)=.*\z/] } &.split(?=) &.at(1)
27
- Termclock::ParseCharacters.transform_characters!(chars[0]) if chars
47
+ Termclock::ParseCharacters.transform_characters!(*chars) if chars
48
+
49
+ _refresh_time = ARGV.find { |x| x[/\A\-(\-refresh|r)=.*\z/] } &.split(?=) &.at(1)
50
+ refresh_time = _refresh_time ? _refresh_time.to_f : 0.1
51
+
52
+ text_colours = ARGV.find { |x| x[/\A\-(\-text\-colour|tc)=.*\z/] } &.split(?=) &.at(1) &.split(?,)
53
+ abort("Text colours need 2 colours. Example: -tc=55f,3ce3b5") if text_colours && text_colours.length != 2
54
+
55
+ bold = ARGV.any? { |x| x[/\A\-\-bold\z/] }
56
+ no_print_info = ARGV.any? { |x| x[/\A\-(\-no\-sysinfo|ni)\z/] }
57
+ no_print_message = ARGV.any? { |x| x[/\A\-(\-no\-message|nm)\z/] }
58
+ no_print_date = ARGV.any? { |x| x[/\A\-(\-no\-date|nd)\z/] }
59
+
60
+ clean = ARGV.any? { |x| x[/\A\-(\-clean)\z/] }
61
+
62
+ if clean
63
+ no_print_info = no_print_message = no_print_date = true
64
+ end
28
65
 
29
- Termclock.main(*colours)
66
+ Termclock.start(
67
+ *colours,
68
+ *text_colours,
69
+ sleep: refresh_time,
70
+ bold: bold,
71
+ print_info: !no_print_info,
72
+ print_message: !no_print_message,
73
+ print_date: !no_print_date
74
+ )
30
75
  rescue Interrupt, SignalException
31
76
  print "\e[H\e[2J\e[3J"
32
77
  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"
14
+ require_relative "termclock/system_info"
10
15
  require_relative "termclock/main"
11
16
  require_relative "termclock/hex2rgb"
12
17
  require_relative "termclock/version"
@@ -1,7 +1,11 @@
1
1
  module Termclock
2
- def self.main(colour1, colour2, colour3, colour4, sleep = 0.1)
3
- newline = ?\n.freeze
4
- space = ?\s.freeze
2
+ def self.start(colour1, colour2, colour3, colour4,
3
+ textcolour1 = nil, textcolour2 = nil,
4
+ sleep: 0.1,
5
+ bold: false,
6
+ print_info: true, print_message: true,
7
+ print_date: true
8
+ )
5
9
 
6
10
  generate = proc do |start, stop, n = 5|
7
11
  r_op = r_val = nil
@@ -44,50 +48,47 @@ module Termclock
44
48
  colours = [rs1, gs1, bs1].transpose.zip([rs2, gs2, bs2].transpose)
45
49
  colours.unshift(colours[0])
46
50
  colours.push(colours[-1])
51
+
52
+ # Text colours
53
+ tc1 = textcolour1 ? hex2rgb(textcolour1) : hex2rgb('5555ff')
54
+ tc2 = textcolour2 ? hex2rgb(textcolour2) : hex2rgb('3ce3b5')
55
+
47
56
  cpu_usage = 0
48
57
  cpu_usage_t = Thread.new { }
58
+
59
+ current_net_usage = ''
60
+ current_net_usage_t = Thread.new { }
61
+
49
62
  message_time = Time.now.to_i - 5
63
+ message_counter = -1
50
64
  message = ''
65
+ message_final = ''
51
66
  message_temp = ''
52
67
  caret = "\u2588"
53
68
 
69
+ date, info = '', ''
70
+
54
71
  get_message = proc {
55
72
  case Time.now.hour
56
- when 6...12
73
+ when 5...12
57
74
  "\u{1F304} Good Morning..."
58
75
  when 12...16
59
76
  "\u26C5 Good Afternoon..."
60
- when 16...19
61
- "\u{1F306} Good Evening..."
62
- when 19...22
77
+ when 16...18
78
+ "\u{1F307} Good Evening..."
79
+ when 18...20
80
+ "\u{1F31F} Good Evening..."
81
+ when 20...24
63
82
  "\u{1F303} Good Night..."
64
83
  else
65
- "\u{1F30C} Good Night..."
84
+ "\u{2728} Good Night..."
66
85
  end
67
86
  }
68
87
 
69
- i = -1
70
-
71
88
  while true
72
- i += 1
73
89
  time_now = Time.now
74
90
  height, width = *STDOUT.winsize
75
91
 
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
92
  if time_now.to_f./(0.5).to_i.even?
92
93
  splitter = ?:.freeze
93
94
  _caret = caret
@@ -96,64 +97,45 @@ module Termclock
96
97
  _caret = ''
97
98
  end
98
99
 
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"
100
+ if print_message
101
+ message_counter += 1
102
+ message_align = width - message_counter % width + message.length / 2 - 4
103
+ if (width - message_counter % width <= message.length)
104
+ message.replace(message[1..-1])
105
+ message_align = width - message_counter % width + 4
106
+ else
107
+ message.clear if width - message_counter % width == width
108
+ message_temp = get_message.call
109
+
110
+ if message_temp != message
111
+ message << message_temp[message.length..message.length + 1]
112
+ end
113
+ end
109
114
 
110
- unless cpu_usage_t.alive?
111
- cpu_usage_t = Thread.new { cpu_usage = LS::CPU.usage(0.25) }
115
+ message_final = message.rjust(message_align).+(_caret).gradient(tc1, tc2, exclude_spaces: true, bold: bold)
112
116
  end
113
117
 
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
118
+ if print_info
119
+ info = system_info(width, tc1, tc2, bold)
122
120
  end
123
121
 
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)}%)"
122
+ if print_date
123
+ date = time_now.strftime('%a, %d %B %Y').center(width)
124
+ .gradient(tc1, tc2, bold: bold)
125
+ end
143
126
 
144
- process = "\u{1F9EE} Process: #{LS::Process.count}"
127
+ time = time_now.strftime('%H %M %S %2N').split.join(splitter)
128
+ art = Termclock::ParseCharacters.display(time).lines
145
129
 
146
- max_l = [process, ip, battery, net_usage].map(&:length).max
130
+ art_aligned = art.each_with_index do |x, i|
131
+ chomped = x.chomp(''.freeze).+(NEWLINE)
132
+ gr = chomped.gradient(*colours[i], bold: bold)
133
+ x.replace(SPACE.*(width./(2.0).-(chomped.length / 2.0).abs.to_i + 1) + gr)
134
+ end.join
147
135
 
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
136
+ vertical_gap = "\e[#{height./(2.0).-(art.length / 2.0).to_i + 1}H"
154
137
 
155
- print "#{CLEAR}#{info}#{horizontal_gap}#{art_aligned}\n"\
156
- "#{message.rjust(message_align).+(_caret).gradient(*colours[1], exclude_spaces: true)}"
138
+ print "#{CLEAR}#{info}#{vertical_gap}#{art_aligned}\n#{date}\n\n#{message_final}"
157
139
 
158
140
  if gc_compact && time_now.to_i > gc_compacted
159
141
  GC.compact
@@ -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
- ```````
144
+ ````````
146
145
  `
147
146
  `
148
147
  `
149
- ```````
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
- `` ``
235
+ `` ``
236
+ `` ``
237
+ `` ``
239
238
  `` ``
240
239
  `
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
+ ` `
251
+ `
252
+ ` `
253
+ ` `
255
254
 
256
255
  # Y
257
256
  `` ``
@@ -283,24 +282,38 @@ module Termclock
283
282
  end.freeze
284
283
 
285
284
  def transform_characters!(arg)
285
+ @@transformed ||= nil
286
+ fail RuntimeError, 'Characters already transformed!' if @@transformed
287
+ @@transformed ||= true
288
+
286
289
  @@characters.values.each { |x|
287
290
  stripped = x.strip[0]
288
- x.gsub!(stripped, arg) if stripped
291
+ chars = arg.chars.rotate(-1)
292
+
293
+ if stripped
294
+ replace_with = x.chars.map { |y|
295
+ chars = arg.chars.rotate(-1) if y == NEWLINE
296
+ next(y) if y != stripped
297
+ chars.rotate!(1)[0]
298
+ }.join
299
+
300
+ x.replace(replace_with)
301
+ end
289
302
  }
290
303
  end
291
304
 
292
305
  def display(c)
293
- j = ['', '']
306
+ j = []
294
307
 
295
- c.upcase.chars.map! { |x|
296
- @@characters.fetch(x, x).split(?\n.freeze)
308
+ c.upcase.each_char { |x|
309
+ @@characters.fetch(x, x).split(NEWLINE)
297
310
  .each_with_index { |z, i|
298
311
  _j = j[i]
299
312
  _j && _j << z || j[i] = z
300
313
  }
301
314
  }
302
315
 
303
- j.join(?\n.freeze)
316
+ j.join(NEWLINE)
304
317
  end
305
318
  end
306
319
  end
@@ -1,5 +1,9 @@
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, bg: false, exclude_spaces: false, bold: false)
3
7
  temp = ''
4
8
 
5
9
  r, g, b = all_rgbs[0]
@@ -45,11 +49,13 @@ class String
45
49
  _g = _g.send(g_op, g_val * -1) if g_op
46
50
  _b = _b.send(b_op, b_val * -1) if b_op
47
51
 
52
+ temp << "\e[1m" if bold
53
+
48
54
  i = -1
49
55
  while (i += 1) < len
50
56
  _c = c[i]
51
57
 
52
- if !exclude_spaces || (exclude_spaces && !(_c == ?\s.freeze || _c == ?\t.freeze))
58
+ if !exclude_spaces || (exclude_spaces && !(_c == SPACE || _c == TAB))
53
59
  _r = _r.send(r_op, r_val) if r_op
54
60
  _g = _g.send(g_op, g_val) if g_op
55
61
  _b = _b.send(b_op, b_val) if b_op
@@ -70,7 +76,7 @@ class String
70
76
  ret = if !c.empty?
71
77
  chomped ? "\e[0m\n".freeze : "\e[0m".freeze
72
78
  elsif chomped
73
- ?\n.freeze
79
+ NEWLINE
74
80
  end
75
81
 
76
82
  temp << ret
@@ -0,0 +1,73 @@
1
+ module Termclock
2
+ @@cpu_usage = 0
3
+ @@cpu_usage_t = Thread.new { }.join
4
+
5
+ @@current_net_usage = ''
6
+ @@current_net_usage_t = Thread.new { }.join
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}#{SPACE.*(width.-(user.length + max_l).abs)}#{hostname}
66
+ \s#{cpu}#{SPACE.*(width.-(cpu.length + max_l).abs)}#{battery}
67
+ \s#{memory}#{SPACE.*(width.-(memory.length + max_l).abs)}#{ip}
68
+ \s#{swap}#{SPACE.*(width.-(swap.length + max_l).abs)}#{@@current_net_usage}
69
+ \s#{fs}#{SPACE.*(width.-(fs.length + max_l).abs)}#{net_usage}
70
+ EOF
71
+ end
72
+ end
73
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Termclock
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.6"
5
5
  end
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.1.1
4
+ version: 0.1.6
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-14 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: '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: '0'
26
+ version: 1.3.1
27
27
  description: A clock for Linux VTE
28
28
  email:
29
29
  - souravgoswami@protonmail.com
@@ -38,6 +38,7 @@ files:
38
38
  - lib/termclock/main.rb
39
39
  - lib/termclock/parse_characters.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: