termclock 0.3.0 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec9759a77ce797b7110a4d5427cf56ca1e7c7188558a84220d233b873d2db1b6
4
- data.tar.gz: 6262c03faf908cdf536aa461181ed8564408e838f2df4a016da5f90817d25135
3
+ metadata.gz: '098660e91498baced640456738b0e3d4ec38f00fd386c50f97e4ae24327b8ac1'
4
+ data.tar.gz: c120438c0609d8a725f58ff32105300f79f531dfebea552726069fe2ceb0f36d
5
5
  SHA512:
6
- metadata.gz: be6ba479d498ea9155a16e950e8c5f6a240ec3556f3a5a0bccb7120ab48142f9084ea01c0c17c81c229172c9cbd2ac61fd8234063fe9c537d36e1e20ee23e524
7
- data.tar.gz: 4d17f5be9b2d8b8c61800173c4fc7fb09294d10f17c2d69e35b78d24d1b1ffd758484525594a91bbf627052cfefe6bb0f96d02c9d304f0f94d7429a803abebd8
6
+ metadata.gz: 42707afa6c2cdd329b0f14d174b94ce74d52dbcf8aeea6423d71d7b7848c398661d5b6f1367d9dc649eda5a561c9dc85cee3414152993adc40c617ebb5a75a0d
7
+ data.tar.gz: 1ad86795402c131050e1513376d014378efc632cb7c45da2d4e8dafab11fed43e81bb7adb9cf2133a13f3bcfca646bd461fe6fe810207f5614963a66344dc59b
data/exe/termclock CHANGED
@@ -1,22 +1,26 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'termclock'
3
3
  $-v = nil
4
+ STDOUT.sync = true
4
5
 
5
- def version
6
+ def version(logo_colour)
6
7
  emoji = ?🕐.ord.-(1).chr('utf-8')
7
8
  Time.now.strftime('%I').to_i.times { emoji.next! }
8
9
 
9
10
  _v = "#{emoji} This is Termclock v#{Termclock::VERSION}"
10
11
  vl_2 = _v.length / 2
11
12
 
12
- v_col1 = Termclock.hex2rgb('ff0')
13
- v_col2 = Termclock.hex2rgb('f55')
14
- v_col3 = Termclock.hex2rgb('55f')
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
15
16
 
16
- _v[0...vl_2].gradient(v_col1, v_col2, underline: true, bold: true) <<
17
- _v[vl_2..-1].gradient(v_col2, v_col3, underline: true, bold: true)
17
+ unless STDOUT.tty?
18
+ IO.undef_method(:winsize)
19
+ IO.define_method(:winsize) { [100, 100] }
18
20
  end
19
21
 
22
+ LOGO_COLOUR = %w(ff0 f55 55f).map(&Termclock.method(:hex2rgb))
23
+
20
24
  if ARGV.any? { |x| x[/\A\-(\-help|h)\z/] }
21
25
  puts <<~EOF
22
26
  TermClock: A clock that runs on the LinuxTerminal!
@@ -33,43 +37,42 @@ if ARGV.any? { |x| x[/\A\-(\-help|h)\z/] }
33
37
  --character=|char=\t\tDraws specified character
34
38
  --clean\t\t\t\tJust run the clean bare clock
35
39
  --colour=|-c=\t\t\tSpecify hex colour (4 colours)
36
- \t\t\t\t[ with or without # ]
40
+ --text-colour=|-tc=\t\tSpecify text colour (2 colours)
41
+
42
+ \u2B22 \e[3mColours has to be hex, 3 or 6 characters with or
43
+ without the leading # in front\e[0m
37
44
 
38
45
  \e[1m3. Information:\e[0m
39
46
  --no-date|-nd\t\t\tShows no date
40
47
  --no-message|-nm\t\tShows no messages
41
48
  --no-sysinfo|-ni\t\tShows no system info
42
- --refresh|r\t\t\tSpecify delay or refresh time
43
- --text-colour|-tc\t\tSpecify text colour (2 colours)
49
+ --refresh=|r=\t\t\tSpecify delay or refresh time
44
50
  --no-logo|-nl\t\t\tDon't show the logo at the bottom
45
51
 
46
- \e[1m4. Formats:\e[0m
52
+ \e[1m4. Antiflicker:\e[0m
53
+ --antiflicker|-af\t\tDon't flicker terminal
54
+
55
+ \u2B22 \e[3mIf refresh time is low or terminal is slow, use this option\e[0m
56
+
57
+ \e[1m5. Formats:\e[0m
47
58
  --date-format=|-df=\t\tSpecify the date format
48
59
  --time-format=|-tf=\t\tSpecify the time format
49
60
 
50
61
  Usually the format looks like this:
51
62
  %H:%M:%S:%2N or %d %B, %Y
52
63
 
53
- \e[3mRun `date --help` to know more formats\e[0m
64
+ \u2B22 \e[3mRun `date --help` to know more formats\e[0m
54
65
 
55
66
  Supported characters are 0 - 9, a - z, /, \\, !, %, and |.
56
67
 
57
- #{version}
68
+ #{version(LOGO_COLOUR)}
58
69
  EOF
59
70
 
60
71
  exit 0
61
72
  end
62
73
 
63
74
  if ARGV.any? { |x| x[/\A\-(-version|v)\z/] }
64
- colour = [
65
- [[255, 100, 100], [100, 100, 255]],
66
- [[60, 230, 180], [100, 100, 255]],
67
- [[255, 255, 0], [100, 100, 255]],
68
- [[255, 80, 170], [255, 200, 0]],
69
- ].sample
70
-
71
- colour.reverse! if rand < 0.5
72
- puts version
75
+ puts version(LOGO_COLOUR)
73
76
  exit 0
74
77
  end
75
78
 
@@ -110,6 +113,7 @@ begin
110
113
 
111
114
  bold = ARGV.any? { |x| x[/\A\-(\-bold|b)\z/] }
112
115
  italic = ARGV.any? { |x| x[/\A\-(\-italic|i)\z/] }
116
+ anti_flicker = ARGV.any? { |x| x[/\A\-(\-antiflicker|af)\z/] }
113
117
 
114
118
  no_print_info = ARGV.any? { |x| x[/\A\-(\-no\-sysinfo|ni)\z/] }
115
119
  no_logo = ARGV.any? { |x| x[/\A\-(\-no\-logo|nl)\z/] }
@@ -132,7 +136,7 @@ begin
132
136
  Termclock.start(
133
137
  *colours,
134
138
  *text_colours,
135
- sleep: refresh_time,
139
+ refresh: refresh_time,
136
140
  bold: bold,
137
141
  italic: italic,
138
142
  print_info: !no_print_info,
@@ -140,10 +144,14 @@ begin
140
144
  print_date: !no_print_date,
141
145
  no_logo: no_logo,
142
146
  time_format: time_format,
143
- date_format: date_format
147
+ date_format: date_format,
148
+ logo_colour: LOGO_COLOUR,
149
+ anti_flicker: anti_flicker
144
150
  )
145
151
  rescue Interrupt, SignalException
146
152
  print "\e[H\e[2J\e[3J"
153
+ # rescue Errno::ENOTTY
154
+ # abort "This should be run on a TTY! Also please don't pipe or redirect the output!"
147
155
  ensure
148
156
  print "\e[?25h"
149
157
  end
data/lib/termclock.rb CHANGED
@@ -3,10 +3,14 @@ require 'io/console'
3
3
  require_relative "termclock/version"
4
4
 
5
5
  module Termclock
6
+ GC_COMPACT_TIME = 7200
6
7
  CLEAR = "\e[H\e[2J\e[3J".freeze
8
+ ANTIFLICKER = "\e[J\e[1;1H".freeze
7
9
  NEWLINE = ?\n.freeze
8
10
  SPACE = ?\s.freeze
9
11
  TAB = ?\t.freeze
12
+ EMPTY = ''.freeze
13
+ EPSILON = 5.0e-07
10
14
  end
11
15
 
12
16
  require_relative "termclock/string"
@@ -3,7 +3,7 @@ module Termclock
3
3
  colour = hex.dup.to_s
4
4
  colour.strip!
5
5
  colour.downcase!
6
- colour[0] = ''.freeze if colour[0] == ?#.freeze
6
+ colour[0] = EMPTY if colour[0] == ?#.freeze
7
7
 
8
8
  # out of range
9
9
  oor = colour.scan(/[^a-f0-9]/)
@@ -1,300 +1,300 @@
1
1
  module Termclock
2
2
  module ParseCharacters
3
3
  CHARACTERS = <<~EOF.freeze
4
- # 0
4
+ #\s0
5
5
  ````````
6
- `` ``
7
- `` ``
8
- `` ``
6
+ ``\s\s\s\s``
7
+ ``\s\s\s\s``
8
+ ``\s\s\s\s``
9
9
  ````````
10
10
 
11
- # 1
12
- ``
11
+ #\s1
12
+ \s\s\s``
13
13
  `````
14
- ``
15
- ``
14
+ \s\s\s``
15
+ \s\s\s``
16
16
  ````````
17
17
 
18
- # 2
18
+ #\s2
19
19
  ````````
20
- ``
20
+ \s\s\s\s\s\s``
21
21
  ````````
22
22
  ``
23
23
  ````````
24
24
 
25
- # 3
25
+ #\s3
26
26
  ````````
27
- ``
27
+ \s\s\s\s\s\s``
28
28
  ````````
29
- ``
29
+ \s\s\s\s\s\s``
30
30
  ````````
31
31
 
32
- # 4
33
- `` ``
34
- `` ``
32
+ #\s4
33
+ ``\s\s\s\s``
34
+ ``\s\s\s\s``
35
35
  ````````
36
- ``
37
- ``
36
+ \s\s\s\s\s\s``
37
+ \s\s\s\s\s\s``
38
38
 
39
- # 5
39
+ #\s5
40
40
  ````````
41
41
  ``
42
42
  ````````
43
- ``
43
+ \s\s\s\s\s\s``
44
44
  ````````
45
45
 
46
- # 6
46
+ #\s6
47
47
  ````````
48
48
  ``
49
49
  ````````
50
- `` ``
50
+ ``\s\s\s\s``
51
51
  ````````
52
52
 
53
- # 7
53
+ #\s7
54
54
  ````````
55
- ``
56
- ``
57
- ``
58
- ``
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``
59
59
 
60
- # 8
60
+ #\s8
61
61
  ````````
62
- `` ``
62
+ ``\s\s\s\s``
63
63
  ````````
64
- `` ``
64
+ ``\s\s\s\s``
65
65
  ````````
66
66
 
67
- # 9
67
+ #\s9
68
68
  ````````
69
- `` ``
69
+ ``\s\s\s\s``
70
70
  ````````
71
- ``
71
+ \s\s\s\s\s\s``
72
72
  ````````
73
73
 
74
- # :
74
+ #\s:
75
75
  \u2B29\u2B29
76
76
  \u2B29\u2B29
77
77
 
78
78
  \u2B29\u2B29
79
79
  \u2B29\u2B29
80
80
 
81
- # $
81
+ #\s$
82
82
  \s\s
83
83
  \s\s
84
84
 
85
85
  \s\s
86
86
  \s\s
87
- # A
87
+ #\sA
88
88
  ````````
89
- `` ``
89
+ ``\s\s\s\s``
90
90
  ````````
91
- `` ``
92
- `` ``
91
+ ``\s\s\s\s``
92
+ ``\s\s\s\s``
93
93
 
94
- # B
94
+ #\sB
95
95
  ````````
96
- `` ``
96
+ ``\s\s\s\s\s``
97
97
  ````````
98
- `` ``
98
+ ``\s\s\s\s\s``
99
99
  ````````
100
100
 
101
- # C
101
+ #\sC
102
102
  ````````
103
103
  ``
104
104
  ``
105
105
  ``
106
106
  ````````
107
107
 
108
- # D
108
+ #\sD
109
109
  ````````
110
- `` ``
111
- `` ``
112
- `` ``
110
+ ``\s\s\s\s\s``
111
+ ``\s\s\s\s\s\s``
112
+ ``\s\s\s\s\s``
113
113
  ````````
114
114
 
115
- # E
115
+ #\sE
116
116
  ````````
117
117
  ``
118
118
  ````````
119
119
  ``
120
120
  ````````
121
121
 
122
- # F
122
+ #\sF
123
123
  ````````
124
124
  ``
125
125
  ````````
126
126
  ``
127
127
  ``
128
128
 
129
- # G
129
+ #\sG
130
130
  ````````
131
131
  ``
132
132
  ``
133
- `` ````
133
+ ``\s\s````
134
134
  ````````
135
135
 
136
- # H
137
- `` ``
138
- `` ``
136
+ #\sH
137
+ ``\s\s\s\s``
138
+ ``\s\s\s\s``
139
139
  ````````
140
- `` ``
141
- `` ``
140
+ ``\s\s\s\s``
141
+ ``\s\s\s\s``
142
142
 
143
- # I
143
+ #\sI
144
144
  ````````
145
145
  \s\s\s``
146
146
  \s\s\s``
147
147
  \s\s\s``
148
148
  ````````
149
149
 
150
- # J
150
+ #\sJ
151
151
  ````````
152
- ``
153
- ``
154
- `` ``
155
- ```````
152
+ \s\s\s\s\s\s``
153
+ \s\s\s\s\s\s``
154
+ \s``\s\s\s``
155
+ \s```````
156
156
 
157
- # K
158
- `` ``
159
- `` ``
157
+ #\sK
158
+ ``\s\s\s\s``
159
+ ``\s\s``
160
160
  `````
161
- `` ``
162
- `` ``
161
+ ``\s\s``
162
+ ``\s\s\s\s``
163
163
 
164
- # L
164
+ #\sL
165
165
  ``
166
166
  ``
167
167
  ``
168
168
  ``
169
169
  ````````
170
170
 
171
- # M
172
- ``` ```
173
- `` `` ``
174
- `` ``
175
- `` ``
176
- `` ``
171
+ #\sM
172
+ ```\s\s```
173
+ ``\s``\s``
174
+ ``\s\s\s\s``
175
+ ``\s\s\s\s``
176
+ ``\s\s\s\s``
177
177
 
178
- # N
179
- ```` ``
180
- `` `` ``
181
- `` `` ``
182
- `` `` ``
183
- `` ````
178
+ #\sN
179
+ ````\s\s``
180
+ ``\s``\s``
181
+ ``\s``\s``
182
+ ``\s``\s``
183
+ ``\s\s````
184
184
 
185
- # O
185
+ #\sO
186
186
  ````````
187
- `` ``
188
- `` ``
189
- `` ``
187
+ ``\s\s\s\s``
188
+ ``\s\s\s\s``
189
+ ``\s\s\s\s``
190
190
  ````````
191
191
 
192
- # P
192
+ #\sP
193
193
  ````````
194
- `` ``
194
+ ``\s\s\s\s``
195
195
  ````````
196
196
  ``
197
197
  ``
198
198
 
199
- # Q
199
+ #\sQ
200
200
  ````````
201
- `` ``
201
+ ``\s\s\s\s``
202
202
  ````````
203
- ``
204
- ``
203
+ \s\s\s\s\s\s``
204
+ \s\s\s\s\s\s``
205
205
 
206
- # R
206
+ #\sR
207
207
  ````````
208
- `` ``
208
+ ``\s\s\s\s``
209
209
  ````````
210
210
  `````
211
- `` ``
211
+ ``\s\s\s``
212
212
 
213
- # S
213
+ #\sS
214
214
  ````````
215
215
  ``
216
216
  ````````
217
- ``
217
+ \s\s\s\s\s\s``
218
218
  ````````
219
219
 
220
- # T
220
+ #\sT
221
221
  ````````
222
- ``
223
- ``
224
- ``
225
- ``
222
+ \s\s\s``
223
+ \s\s\s``
224
+ \s\s\s``
225
+ \s\s\s``
226
226
 
227
- # U
228
- `` ``
229
- `` ``
230
- `` ``
231
- `` ``
227
+ #\sU
228
+ ``\s\s\s\s``
229
+ ``\s\s\s\s``
230
+ ``\s\s\s\s``
231
+ ``\s\s\s\s``
232
232
  ````````
233
233
 
234
- # V
235
- `` ``
236
- `` ``
237
- `` ``
238
- \s`` ``\s
234
+ #\sV
235
+ ``\s\s\s\s``
236
+ ``\s\s\s\s``
237
+ ``\s\s\s\s``
238
+ \s``\s\s``\s
239
239
  \s\s\s``
240
240
 
241
- # W
242
- `` ``
243
- `` ``
244
- `` ``
245
- `` ` ``
241
+ #\sW
242
+ ``\s\s\s\s``
243
+ ``\s\s\s\s``
244
+ ``\s\s\s\s``
245
+ ``\s`\s\s``
246
246
  ````````
247
247
 
248
- # X
249
- `` ``
250
- \s`` ``
248
+ #\sX
249
+ ``\s\s\s\s``
250
+ \s``\s\s``
251
251
  \s\s\s``
252
- \s`` ``
253
- `` ``
252
+ \s``\s\s``
253
+ ``\s\s\s\s``
254
254
 
255
- # Y
256
- `` ``
257
- `` ``
255
+ #\sY
256
+ ``\s\s\s\s``
257
+ ``\s\s\s\s``
258
258
  ````````
259
- ``
260
- ``
259
+ \s\s\s``
260
+ \s\s\s``
261
261
 
262
- # Z
262
+ #\sZ
263
263
  ````````
264
- ``
265
- ``
266
- ``
264
+ \s\s\s\s\s``
265
+ \s\s\s``
266
+ \s``
267
267
  ````````
268
268
 
269
- # /
269
+ #\s/
270
270
  \s\s\s\s\s``\s
271
271
  \s\s\s\s``\s\s
272
272
  \s\s\s``\s\s\s
273
273
  \s\s``\s\s\s\s
274
274
  \s``\s\s\s\s\s
275
275
 
276
- # \\
276
+ #\s\\
277
277
  \s``\s\s\s\s\s
278
278
  \s\s``\s\s\s\s
279
279
  \s\s\s``\s\s\s
280
280
  \s\s\s\s``\s\s
281
281
  \s\s\s\s\s``\s
282
282
 
283
- # %
283
+ #\s%
284
284
  \s\s\s\s\s``\s
285
285
  ``\s\s``\s\s
286
286
  \s\s\s``\s\s\s
287
287
  \s\s``\s\s``
288
288
  \s``\s\s\s\s\s
289
289
 
290
- # |
290
+ #\s|
291
291
  \s\s\s``\s\s\s
292
292
  \s\s\s``\s\s\s
293
293
  \s\s\s``\s\s\s
294
294
  \s\s\s``\s\s\s
295
295
  \s\s\s``\s\s\s
296
296
 
297
- # !
297
+ #\s!
298
298
  \s\s\s``\s\s\s
299
299
  \s\s\s``\s\s\s
300
300
  \s\s\s``\s\s\s
@@ -1,16 +1,20 @@
1
1
  module Termclock
2
2
  def self.start(colour1, colour2, colour3, colour4,
3
3
  textcolour1 = nil, textcolour2 = nil,
4
- sleep: 0.1,
4
+ refresh: 0.1,
5
5
  bold: false,
6
6
  italic: false,
7
7
  print_info: true, print_message: true,
8
8
  print_date: true,
9
9
  time_format: "%H %M %S %2N",
10
10
  date_format: '%a, %d %B %Y',
11
- no_logo: false
11
+ no_logo: false,
12
+ anti_flicker: false,
13
+ logo_colour: [Termclock.hex2rgb('ff0'), Termclock.hex2rgb('f55'), Termclock.hex2rgb('55f')]
12
14
  )
13
15
 
16
+ clear_character = anti_flicker ? ANTIFLICKER : CLEAR
17
+
14
18
  generate = proc do |start, stop, n = 5|
15
19
  r_op = r_val = nil
16
20
  ary = []
@@ -30,8 +34,7 @@ module Termclock
30
34
  ary
31
35
  end
32
36
 
33
- gc_compact, gc_compacted = GC.respond_to?(:compact), Time.now.to_i + 7200
34
- print CLEAR
37
+ gc_compact, gc_compacted = GC.respond_to?(:compact), Time.now.to_i + GC_COMPACT_TIME
35
38
 
36
39
  r1, g1, b1 = *colour1
37
40
  r2, g2, b2 = *colour2
@@ -57,19 +60,11 @@ module Termclock
57
60
  tc1 = textcolour1 ? hex2rgb(textcolour1) : hex2rgb('5555ff')
58
61
  tc2 = textcolour2 ? hex2rgb(textcolour2) : hex2rgb('3ce3b5')
59
62
 
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
63
  message_counter = -1
68
64
  message = ''
69
65
  message_final = ''
70
66
  message_align = 0
71
67
  message_temp = ''
72
- point_five_tick = 0
73
68
 
74
69
  date, info = '', ''
75
70
 
@@ -100,34 +95,38 @@ module Termclock
100
95
 
101
96
  version = "Termclock v#{Termclock::VERSION}"
102
97
 
103
- v_col1 = hex2rgb('ff0')
104
- v_col2 = hex2rgb('f55')
105
- v_col3 = hex2rgb('f55')
106
- v_col4 = hex2rgb('55f')
98
+ v_col1 = logo_colour[0]
99
+ v_col2 = logo_colour[1]
100
+ v_col3 = logo_colour[2]
107
101
 
108
102
  vl_2 = version.length / 2
109
103
  _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_col3, v_col4, underline: true, bold: bold, italic: italic)
104
+ version[vl_2..-1].gradient(v_col2, v_col3, underline: true, bold: bold, italic: italic)
111
105
 
112
106
  term_clock_v = ''
113
107
 
114
108
  chop_message = 0
109
+ deviation = 0
110
+
111
+ time_seperators = [?:, ?$]
112
+ time_seperator = time_seperators[0]
113
+ point_five_tick = -0.5
114
+
115
+ height, width = *STDOUT.winsize
116
+ height2, width2 = *STDOUT.winsize
117
+
118
+ print CLEAR
115
119
 
116
120
  while true
121
+ monotonic_time_1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
117
122
  time_now = Time.now
118
123
  height, width = *STDOUT.winsize
119
124
 
120
- if time_now.to_f./(0.5).to_i.even?
121
- unless point_five_tick == 1
122
- point_five_tick = 1
123
- splitter = ?:.freeze
124
- clock_emoji.rotate!
125
- end
126
- else
127
- unless point_five_tick == 0
128
- point_five_tick = 0
129
- splitter = ?$.freeze
130
- end
125
+ if time_now.to_f > point_five_tick
126
+ point_five_tick = time_now.to_f + 0.5
127
+ time_seperators.rotate!
128
+ clock_emoji.rotate!
129
+ time_seperator = time_seperators[0]
131
130
  end
132
131
 
133
132
  unless no_logo
@@ -165,36 +164,48 @@ module Termclock
165
164
  )
166
165
  end
167
166
 
168
- if print_info
169
- info = system_info(width).gradient(
170
- tc1, tc2, bold: bold, italic: italic
171
- )
172
- end
167
+ info = system_info(width, tc1, tc2, bold, italic) if print_info
173
168
 
174
169
  if print_date
175
170
  date = time_now.strftime(date_format).center(width)
176
- .gradient(tc1, tc2, bold: bold, italic: italic)
171
+ .gradient(tc1, tc2, bold: bold, italic: italic, exclude_spaces: true)
177
172
  end
178
173
 
179
- time = time_now.strftime(time_format).split.join(splitter)
174
+ time = time_now.strftime(time_format).split.join(time_seperator)
180
175
  art = Termclock::ParseCharacters.display(time).lines
181
176
 
182
177
  art_aligned = art.each_with_index do |x, i|
183
- chomped = x.chomp(''.freeze).+(NEWLINE)
178
+ chomped = x.chomp(EMPTY).+(NEWLINE)
184
179
  gr = chomped.gradient(*colours[i], bold: bold, italic: italic)
185
- x.replace(SPACE.*(width./(2.0).-(chomped.length / 2.0).abs.to_i + 1) + gr)
180
+
181
+ w = width./(2.0).-(chomped.length / 2.0) + 2
182
+ w = 0 if w < 0
183
+
184
+ x.replace(SPACE.*(w) + gr)
186
185
  end.join
187
186
 
188
187
  vertical_gap = "\e[#{height./(2.0).-(art.length / 2.0).to_i + 1}H"
188
+ final_output = "#{info}#{vertical_gap}#{art_aligned}\n#{date}\n\n\e[K#{message_final}#{term_clock_v}"
189
+
190
+ if anti_flicker && (height != height2 || width != width2)
191
+ height2, width2 = *STDOUT.winsize
192
+ print CLEAR
193
+ end
189
194
 
190
- print "#{CLEAR}#{info}#{vertical_gap}#{art_aligned}\n#{date}\n\n#{message_final}#{term_clock_v}"
195
+ print "#{clear_character}#{final_output}"
191
196
 
192
197
  if gc_compact && time_now.to_i > gc_compacted
193
198
  GC.compact
194
- gc_compacted = time_now.to_i + 7200
199
+ gc_compacted = time_now.to_i + GC_COMPACT_TIME
195
200
  end
196
201
 
197
- sleep(sleep)
202
+ monotonic_time_2 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
203
+ time_diff = monotonic_time_2 - monotonic_time_1
204
+ sleep_time = refresh.-(time_diff + deviation)
205
+ sleep_time = 0 if sleep_time < 0
206
+
207
+ sleep(sleep_time)
208
+ deviation = Process.clock_gettime(Process::CLOCK_MONOTONIC).-(monotonic_time_2 + sleep_time + EPSILON)
198
209
  end
199
210
  end
200
211
  end
@@ -2,6 +2,7 @@ class String
2
2
  NEWLINE = ?\n.freeze
3
3
  SPACE = ?\s.freeze
4
4
  TAB = ?\t.freeze
5
+ EMPTY = ''.freeze
5
6
 
6
7
  def gradient(*all_rgbs,
7
8
  bg: false,
@@ -31,7 +32,7 @@ class String
31
32
  temp << style if style
32
33
 
33
34
  _r, _g, _b = r, g, b
34
- chomped = !!c.chomp!(''.freeze)
35
+ chomped = !!c.chomp!(EMPTY)
35
36
 
36
37
  len = c.length
37
38
  n_variable = exclude_spaces ? c.delete("\t\s".freeze).length : len
@@ -1,4 +1,10 @@
1
1
  module Termclock
2
+ FILESYSTEM = if LS::FS.stat('/')[:blocks].to_i == 0
3
+ ?.
4
+ else
5
+ ?/
6
+ end.freeze
7
+
2
8
  @@cpu_usage = 0
3
9
  @@cpu_usage_t = Thread.new { }.join
4
10
 
@@ -6,31 +12,44 @@ module Termclock
6
12
  @@current_net_usage_t = Thread.new { }.join
7
13
 
8
14
  class << self
9
- def system_info(width)
15
+ def system_info(width, tc1, tc2, bold, italic)
10
16
  unless @@cpu_usage_t.alive?
11
- @@cpu_usage_t = Thread.new { @@cpu_usage = LS::CPU.usage(0.25) }
17
+ @@cpu_usage_t = Thread.new {
18
+ _cpu_usage = LS::CPU.usage(0.25)
19
+ _cpu_usage_i = _cpu_usage.to_i
20
+
21
+ @@cpu_usage = "%0.2f" % _cpu_usage
22
+ }
12
23
  end
13
24
 
14
25
  unless @@current_net_usage_t.alive?
15
26
  @@current_net_usage_t = Thread.new do
16
27
  _m = LS::Net.current_usage(0.25)
17
28
 
18
- _dl = LS::PrettifyBytes.convert_short_binary(_m[:received], precision: 0)
19
- _ul = LS::PrettifyBytes.convert_short_binary(_m[:transmitted], precision: 0)
29
+ _dl = LS::PrettifyBytes.convert_short_decimal(_m[:received])
30
+ _ul = LS::PrettifyBytes.convert_short_decimal(_m[:transmitted])
20
31
 
21
- @@current_net_usage = "\u{1F4CA} Curr. DL/UL: #{sprintf "%-7s", _dl} | #{sprintf "%7s", _ul}"
32
+ @@current_net_usage = "\u{1F4CA} Curr. DL/UL: #{"%-9s" % _dl} | #{ "%9s" % _ul}"
22
33
  end
23
34
  end
24
35
 
25
- cpu = "\u{1F9E0} CPU: #{sprintf "%5s", @@cpu_usage}% (#{LS::CPU.count_online} / #{LS::CPU.count})"
36
+ cpu = "\u{1F9E0} CPU: #{"%6s" % @@cpu_usage}% (#{LS::CPU.count_online}/#{LS::CPU.count})"
26
37
 
27
38
  battery = if LS::Battery.present?
28
39
  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]})"
40
+ charge = stat[:charge].to_i
41
+
42
+ emoji, plug = "\u{1F50B}".freeze, EMPTY
43
+
44
+ if LS::Battery.charging?
45
+ emoji, plug = "\u{1F4A1}".freeze, "\u{1F50C} ".freeze
46
+ end
47
+
48
+ lives = "\u2665 ".freeze.*(charge.fdiv(20).ceil).chop
49
+
50
+ "#{emoji} Battery: #{charge}% #{lives} (#{plug}#{stat[:status]})"
32
51
  else
33
- ''.freeze
52
+ EMPTY
34
53
  end
35
54
 
36
55
  user = "\u{1F481} User: #{LS::User.get_current_user.capitalize}"
@@ -39,50 +58,110 @@ module Termclock
39
58
  _m = LS::Net.total_bytes
40
59
  ip = "\u{1F30F} IP Addr: #{LS::Net.ipv4_private}"
41
60
 
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)}"
61
+ net_usage = "\u{1F4C8} Totl. DL/UL: #{"%-9s" % LS::PrettifyBytes.convert_short_decimal(_m[:received])}"\
62
+ " | #{"%9s" % LS::PrettifyBytes.convert_short_decimal(_m[:transmitted])}"
44
63
 
45
64
  _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}%)"
65
+ _m.default = 0
66
+
67
+ memory = "\u{1F3B0} Mem: #{LS::PrettifyBytes.convert_short_decimal(_m[:used] * 1000)}"\
68
+ " / #{LS::PrettifyBytes.convert_short_decimal(_m[:total] * 1000)}"\
69
+ " (#{"%.2f" % _m[:percent_used]}%)"
49
70
 
50
71
  _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}%)"
72
+ _m.default = 0
73
+
74
+ swap = "\u{1F300} Swap: #{LS::PrettifyBytes.convert_short_decimal(_m[:used] * 1000)}"\
75
+ " / #{LS::PrettifyBytes.convert_short_decimal(_m[:total] * 1000)}"\
76
+ " (#{"%.2f" % _m[:percent_used]}%)"
54
77
 
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)}%)"
78
+ _m = LS::Filesystem.stat(FILESYSTEM)
79
+ _m.default = 0
80
+
81
+ fs = "\u{1F4BD} FS: #{LS::PrettifyBytes.convert_short_decimal(_m[:used])}"\
82
+ " / #{LS::PrettifyBytes.convert_short_decimal(_m[:total])}"\
83
+ " (#{"%.2f" % _m[:used].*(100).fdiv(_m[:total]).round(2)}%)"
59
84
 
60
85
  pt = LS::Process.types.values
61
86
 
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)}"
87
+ process = if pt.length > 0
88
+ "\u{1F3ED} Process: T:#{"%4s" % pt.length}|"\
89
+ "R:#{"%3s" % pt.count(:running)}|"\
90
+ "S:#{"%3s" % pt.count(:sleeping)}|"\
91
+ "I:#{"%3s" % pt.count(:idle)}"
92
+ else
93
+ EMPTY
94
+ end
66
95
 
67
- _os_v = LS::OS.version
68
- os_v = unless _os_v.empty?
69
- " (#{_os_v})"
96
+ @@os_v ||= unless LS::OS.version.empty?
97
+ " (#{LS::OS.version})"
70
98
  else
71
- ''.freeze
99
+ EMPTY
72
100
  end
73
101
 
74
- os = "\u{1F427} Distrib: #{LS::OS.distribution} #{LS::OS.machine}#{os_v}"
102
+ @@os ||= "\u{1F427} Distrib: #{LS::OS.distribution} #{LS::OS.machine}#{@@os_v}"
103
+
104
+ _uptime = LS::OS.uptime
105
+ _second = _uptime[:second]
106
+ _second_i = _second.to_i
107
+
108
+ hour = "%02d" % _uptime[:hour]
109
+ minute = "%02d" % _uptime[:minute]
110
+ second = "%02d" % _uptime[:second]
111
+ jiffy = "%02d" % _uptime[:jiffy]
112
+
113
+ uptime = "\u{1F3A1} Uptime: #{hour}:#{minute}:#{second}:#{jiffy} (#{LS::OS.uptime_i}s)"
114
+
115
+ _loadavg = LS::Sysinfo.loads.map! { |x| "%.2f" % x }
116
+ loadavg = "\u{1F525} LoadAvg: 1m #{_loadavg[0]}|5m #{_loadavg[1]}|15m #{_loadavg[2]}"
117
+
118
+ all_info = []
119
+ max_l = 0
120
+ i = -1
121
+
122
+ [
123
+ user, hostname,
124
+ @@os, battery,
125
+ cpu, ip,
126
+ memory, @@current_net_usage,
127
+ swap, net_usage,
128
+ fs, process,
129
+ uptime, loadavg
130
+ ].each { |x|
131
+ unless x.empty?
132
+ all_info << x
133
+ i += 1
134
+
135
+ if i.odd?
136
+ _x_len = x.length
137
+ max_l = _x_len if max_l < _x_len
138
+ end
139
+ end
140
+ }
141
+
142
+ max_l += 4
143
+
144
+ all_info.each_slice(2).map { |x, y|
145
+ _diff = width.-(x.length + max_l)
146
+ _diff = 0 if _diff < 1
147
+ y_to_s = y.to_s
148
+
149
+ padding = "#{SPACE * _diff}"
150
+ str = SPACE + x + padding + y_to_s
151
+
152
+ grads = SPACE + x.gradient(tc1, tc2, bold: bold, italic: italic) +
153
+ padding +
154
+ y_to_s.gradient(tc1, tc2, bold: bold, italic: italic)
155
+
156
+ len = str.chars.map { |x|
157
+ _x = x.bytesize./(2)
158
+ _x == 0 ? 1 : _x
159
+ }.sum
75
160
 
76
- max_l = [hostname, process, ip, battery, @@current_net_usage, net_usage].map(&:length).max + 4
161
+ w = width - 2
77
162
 
78
- <<~STR
79
- \s#{user}#{SPACE.*(width.-(user.length + max_l).abs)}#{hostname}
80
- \s#{os}#{SPACE.*(width.-(os.length + max_l).abs)}#{battery}
81
- \s#{cpu}#{SPACE.*(width.-(cpu.length + max_l).abs)}#{ip}
82
- \s#{memory}#{SPACE.*(width.-(memory.length + max_l).abs)}#{@@current_net_usage}
83
- \s#{swap}#{SPACE.*(width.-(swap.length + max_l).abs)}#{net_usage}
84
- \s#{fs}#{SPACE.*(width.-(fs.length + max_l).abs)}#{process}
85
- STR
163
+ len < w ? grads.+(SPACE.*(w - len)) : grads
164
+ }.join(NEWLINE)
86
165
  end
87
166
  end
88
167
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Termclock
4
- VERSION = "0.3.0"
4
+ VERSION = "0.5.3"
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.3.0
4
+ version: 0.5.3
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-21 00:00:00.000000000 Z
11
+ date: 2021-02-06 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.4.0
19
+ version: 2.2.0
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.4.0
26
+ version: 2.2.0
27
27
  description: A clock for Linux VTE
28
28
  email:
29
29
  - souravgoswami@protonmail.com
@@ -59,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  requirements: []
62
- rubygems_version: 3.1.4
62
+ rubygems_version: 3.2.7
63
63
  signing_key:
64
64
  specification_version: 4
65
65
  summary: A clock for Linux VTE