termclock 0.2.0 → 0.5.1

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: a889b38c921c98e808156b9feeee5dccb8ad10952a17f2b591ed14b6297f2075
4
- data.tar.gz: 2676b0ba7b8ad4d2b604282845d2fe4d7101eb5a0c39d076833195e6ada67bfd
3
+ metadata.gz: 9d89ea6ed7b04bc61235e7500823b8c29783025115a0366cbf805152a079506a
4
+ data.tar.gz: 4c8f02442b4e972ea784061e9b320ca7fdfe668d55f4b8a94723527c96365dbf
5
5
  SHA512:
6
- metadata.gz: 04e505fe18c33d49dcc050e3bf06a2ef2484c38b4b0b6b3d5f00ccb47a5551973641621411304342e3314b8255893db00aef62b775fecac001726347e80f5045
7
- data.tar.gz: b7c740f14ee7df1ed1c4c4774f0696eb20c84850eec4b402a8fde75f6864bf6a068465a114680095dd5453fb00bcf33a08c4607a46efefa535dcb033cda8e556
6
+ metadata.gz: cb2fc8a8b36a1961a4ab914295d1cb920e03499129065d2a66a0a4f3e3e28f3705ef9eedc21b3a35c7a81cb60af58dc67c26a03dd26643ab7bec3f2953472a60
7
+ data.tar.gz: fa2b54e5ad66ee0dd3e118e41bfba397edf209e5a4b5a5961c353cd8351237837b61f2e98c0cb0cbe9d5574716577839631b344f5d8eef0fb64a8bb7e9b21138
@@ -1,6 +1,25 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'termclock'
3
3
  $-v = nil
4
+ STDOUT.sync = true
5
+
6
+ def version(logo_colour)
7
+ emoji = ?🕐.ord.-(1).chr('utf-8')
8
+ Time.now.strftime('%I').to_i.times { emoji.next! }
9
+
10
+ _v = "#{emoji} This is Termclock v#{Termclock::VERSION}"
11
+ vl_2 = _v.length / 2
12
+
13
+ _v[0...vl_2].gradient(logo_colour[0], logo_colour[1], underline: true, bold: true) <<
14
+ _v[vl_2..-1].gradient(logo_colour[1], logo_colour[2], underline: true, bold: true)
15
+ end
16
+
17
+ unless STDOUT.tty?
18
+ IO.undef_method(:winsize)
19
+ IO.define_method(:winsize) { [100, 100] }
20
+ end
21
+
22
+ LOGO_COLOUR = %w(ff0 f55 55f).map(&Termclock.method(:hex2rgb))
4
23
 
5
24
  if ARGV.any? { |x| x[/\A\-(\-help|h)\z/] }
6
25
  puts <<~EOF
@@ -8,49 +27,52 @@ if ARGV.any? { |x| x[/\A\-(\-help|h)\z/] }
8
27
 
9
28
  \e[1;4mArguments:\e[0m
10
29
 
11
- 1. Help and Version:\e[0m
30
+ \e[1m1. Help and Version:\e[0m
12
31
  --help|-h\t\t\tShows this help section
13
32
  --version|-v\t\t\tShows termclock version
14
33
 
15
- 2. Style:\e[0m
34
+ \e[1m2. Style:\e[0m
16
35
  --bold|-b\t\t\tMake texts bold
17
36
  --italic|-i\t\t\tMake texts italic
18
37
  --character=|char=\t\tDraws specified character
19
38
  --clean\t\t\t\tJust run the clean bare clock
20
39
  --colour=|-c=\t\t\tSpecify hex colour (4 colours)
21
- \t\t\t\t[ with or without # ]
40
+ --text-colour=|-tc=\t\tSpecify text colour (2 colours)
22
41
 
23
- 3. Information:\e[0m
42
+ \u2B22 \e[3mColours has to be hex, 3 or 6 characters with or
43
+ without the leading # in front\e[0m
44
+
45
+ \e[1m3. Information:\e[0m
24
46
  --no-date|-nd\t\t\tShows no date
25
47
  --no-message|-nm\t\tShows no messages
26
48
  --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)
49
+ --refresh=|r=\t\t\tSpecify delay or refresh time
50
+ --no-logo|-nl\t\t\tDon't show the logo at the bottom
51
+
52
+ \e[1m4. Antiflicker:\e[0m
53
+ --antiflicker|-af\t\tDon't flicker terminal
29
54
 
30
- 4. Formats:\e[0m
55
+ \u2B22 \e[3mIf refresh time is low or terminal is slow, use this option\e[0m
56
+
57
+ \e[1m5. Formats:\e[0m
31
58
  --date-format=|-df=\t\tSpecify the date format
32
- \t\t\t\t[ Run date --help for formats ]
33
59
  --time-format=|-tf=\t\tSpecify the time format
34
- \t\t\t\t[ Run date --help for formats ]
60
+
61
+ Usually the format looks like this:
62
+ %H:%M:%S:%2N or %d %B, %Y
63
+
64
+ \u2B22 \e[3mRun `date --help` to know more formats\e[0m
35
65
 
36
66
  Supported characters are 0 - 9, a - z, /, \\, !, %, and |.
37
67
 
38
- This is Termclock v#{Termclock::VERSION}
68
+ #{version(LOGO_COLOUR)}
39
69
  EOF
40
70
 
41
71
  exit 0
42
72
  end
43
73
 
44
74
  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)
75
+ puts version(LOGO_COLOUR)
54
76
  exit 0
55
77
  end
56
78
 
@@ -84,38 +106,52 @@ begin
84
106
  time_format = _time_format ? _time_format : "%H %M %S %2N"
85
107
 
86
108
  _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'"
109
+ date_format = _date_format ? _date_format : "%a, %d %B %Y"
88
110
 
89
111
  text_colours = ARGV.find { |x| x[/\A\-(\-text\-colour|tc)=.*\z/] } &.split(?=) &.at(1) &.split(?,)
90
112
  abort("Text colours need 2 colours. Example: -tc=55f,3ce3b5") if text_colours && text_colours.length != 2
91
113
 
92
114
  bold = ARGV.any? { |x| x[/\A\-(\-bold|b)\z/] }
93
115
  italic = ARGV.any? { |x| x[/\A\-(\-italic|i)\z/] }
116
+ anti_flicker = ARGV.any? { |x| x[/\A\-(\-antiflicker|af)\z/] }
94
117
 
95
118
  no_print_info = ARGV.any? { |x| x[/\A\-(\-no\-sysinfo|ni)\z/] }
119
+ no_logo = ARGV.any? { |x| x[/\A\-(\-no\-logo|nl)\z/] }
96
120
  no_print_message = ARGV.any? { |x| x[/\A\-(\-no\-message|nm)\z/] }
97
121
  no_print_date = ARGV.any? { |x| x[/\A\-(\-no\-date|nd)\z/] }
98
122
 
99
123
  clean = ARGV.any? { |x| x[/\A\-(\-clean)\z/] }
100
124
 
101
125
  if clean
102
- no_print_info = no_print_message = no_print_date = true
126
+ no_print_info = no_print_message = no_print_date = no_logo = true
127
+ end
128
+
129
+ begin
130
+ Time.now.strftime(time_format)
131
+ Time.now.strftime(date_format)
132
+ rescue
133
+ abort "Date / Time format is invalid\n#{$!.to_s}"
103
134
  end
104
135
 
105
136
  Termclock.start(
106
137
  *colours,
107
138
  *text_colours,
108
- sleep: refresh_time,
139
+ refresh: refresh_time,
109
140
  bold: bold,
110
141
  italic: italic,
111
142
  print_info: !no_print_info,
112
143
  print_message: !no_print_message,
113
144
  print_date: !no_print_date,
145
+ no_logo: no_logo,
114
146
  time_format: time_format,
115
- date_format: date_format
147
+ date_format: date_format,
148
+ logo_colour: LOGO_COLOUR,
149
+ anti_flicker: anti_flicker
116
150
  )
117
151
  rescue Interrupt, SignalException
118
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!"
119
155
  ensure
120
156
  print "\e[?25h"
121
157
  end
@@ -1,12 +1,16 @@
1
1
  require 'linux_stat'
2
2
  require 'io/console'
3
+ require_relative "termclock/version"
3
4
 
4
5
  module Termclock
5
- COLOURTERM = ENV.key?('COLORTERM')
6
- CLEAR = COLOURTERM ? "\e[H\e[2J\e[3J" : "\e[H"
6
+ GC_COMPACT_TIME = 7200
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"
@@ -14,4 +18,3 @@ require_relative "termclock/parse_characters"
14
18
  require_relative "termclock/system_info"
15
19
  require_relative "termclock/start"
16
20
  require_relative "termclock/hex2rgb"
17
- require_relative "termclock/version"
@@ -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,15 +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
- date_format: '%a, %d %B %Y'
10
+ date_format: '%a, %d %B %Y',
11
+ no_logo: false,
12
+ anti_flicker: false,
13
+ logo_colour: [Termclock.hex2rgb('ff0'), Termclock.hex2rgb('f55'), Termclock.hex2rgb('55f')]
11
14
  )
12
15
 
16
+ clear_character = anti_flicker ? ANTIFLICKER : CLEAR
17
+
13
18
  generate = proc do |start, stop, n = 5|
14
19
  r_op = r_val = nil
15
20
  ary = []
@@ -29,8 +34,7 @@ module Termclock
29
34
  ary
30
35
  end
31
36
 
32
- gc_compact, gc_compacted = GC.respond_to?(:compact), Time.now.to_i + 7200
33
- print "\e[H\e[2J\e[3J" unless COLOURTERM
37
+ gc_compact, gc_compacted = GC.respond_to?(:compact), Time.now.to_i + GC_COMPACT_TIME
34
38
 
35
39
  r1, g1, b1 = *colour1
36
40
  r2, g2, b2 = *colour2
@@ -56,100 +60,152 @@ module Termclock
56
60
  tc1 = textcolour1 ? hex2rgb(textcolour1) : hex2rgb('5555ff')
57
61
  tc2 = textcolour2 ? hex2rgb(textcolour2) : hex2rgb('3ce3b5')
58
62
 
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
63
  message_counter = -1
67
64
  message = ''
68
65
  message_final = ''
66
+ message_align = 0
69
67
  message_temp = ''
70
- caret = "\u2588"
71
68
 
72
69
  date, info = '', ''
73
70
 
71
+ clock_emoji = ?\u{1F550}.ord.-(1).chr('utf-8')
72
+ clock_emoji = 12.times.map { clock_emoji.next!.dup }
73
+
74
+ braille = %W(\u2821 \u2811 \u2812 \u280A \u280C)
75
+
74
76
  get_message = proc {
77
+ braille.rotate!
78
+ braille_0 = braille[0]
79
+
75
80
  case Time.now.hour
76
81
  when 5...12
77
- "\u{1F304} Good Morning..."
82
+ "\u{1F304} #{braille_0} Good Morning #{braille_0} \u{1F304}"
78
83
  when 12...16
79
- "\u26C5 Good Afternoon..."
84
+ "\u26C5 #{braille_0} Good Afternoon #{braille_0} \u26C5"
80
85
  when 16...18
81
- "\u{1F307} Good Evening..."
86
+ "\u{1F307} #{braille_0} Good Evening #{braille_0} \u{1F307}"
82
87
  when 18...20
83
- "\u{1F31F} Good Evening..."
88
+ "\u{1F31F} #{braille_0} Good Evening #{braille_0} \u{1F31F}"
84
89
  when 20...24
85
- "\u{1F303} Good Night..."
90
+ "\u{1F303} #{braille_0} Good Night #{braille_0} \u{1F303}"
86
91
  else
87
- "\u{2728} Good Night..."
92
+ "\u{2728} #{braille_0} Good Night #{braille_0} \u{2728}"
88
93
  end
89
94
  }
90
95
 
96
+ version = "Termclock v#{Termclock::VERSION}"
97
+
98
+ v_col1 = logo_colour[0]
99
+ v_col2 = logo_colour[1]
100
+ v_col3 = logo_colour[2]
101
+
102
+ vl_2 = version.length / 2
103
+ _term_clock_v = version[0...vl_2].gradient(v_col1, v_col2, underline: true, bold: bold, italic: italic) <<
104
+ version[vl_2..-1].gradient(v_col2, v_col3, underline: true, bold: bold, italic: italic)
105
+
106
+ term_clock_v = ''
107
+
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
119
+
91
120
  while true
121
+ monotonic_time_1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
92
122
  time_now = Time.now
93
123
  height, width = *STDOUT.winsize
94
124
 
95
- if time_now.to_f./(0.5).to_i.even?
96
- splitter = ?:.freeze
97
- _caret = caret
98
- else
99
- splitter = ?$.freeze
100
- _caret = ''
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]
130
+ end
131
+
132
+ unless no_logo
133
+ term_clock_v = "\e[#{height}H #{clock_emoji[0]} #{_term_clock_v} \e[0m"
101
134
  end
102
135
 
103
136
  if print_message
137
+ message_temp = get_message.call
104
138
  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
139
+ message_length = message.length
140
+
141
+ if (width - message_counter % width < 8)
142
+ unless chop_message == message_temp.length
143
+ chop_message += 1
144
+ message_counter -= 1
145
+ message_align -= 1
146
+ message.replace(message_temp[chop_message..-1])
147
+ end
109
148
  else
149
+ chop_message = 0 unless chop_message == 0
110
150
  message.clear if width - message_counter % width == width
111
- message_temp = get_message.call
151
+ message_align = width - message_counter % width + message_length - 4
112
152
 
113
153
  if message_temp != message
114
- message << message_temp[message.length..message.length + 1]
154
+ if message_length < message_temp.length
155
+ message.replace(message_temp[0..message_length])
156
+ else
157
+ message.replace(message_temp)
158
+ end
115
159
  end
116
160
  end
117
161
 
118
- message_final = message.rjust(message_align).+(_caret).gradient(
162
+ message_final = (message).rjust(message_align).gradient(
119
163
  tc1, tc2, exclude_spaces: true, bold: bold, italic: italic
120
164
  )
121
165
  end
122
166
 
123
- if print_info
124
- info = system_info(width).gradient(
125
- tc1, tc2, bold: bold, italic: italic
126
- )
127
- end
167
+ info = system_info(width, tc1, tc2, bold, italic) if print_info
128
168
 
129
169
  if print_date
130
170
  date = time_now.strftime(date_format).center(width)
131
- .gradient(tc1, tc2, bold: bold, italic: italic)
171
+ .gradient(tc1, tc2, bold: bold, italic: italic, exclude_spaces: true)
132
172
  end
133
173
 
134
- time = time_now.strftime(time_format).split.join(splitter)
174
+ time = time_now.strftime(time_format).split.join(time_seperator)
135
175
  art = Termclock::ParseCharacters.display(time).lines
136
176
 
137
177
  art_aligned = art.each_with_index do |x, i|
138
- chomped = x.chomp(''.freeze).+(NEWLINE)
178
+ chomped = x.chomp(EMPTY).+(NEWLINE)
139
179
  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)
180
+
181
+ w = width./(2.0).-(chomped.length / 2.0) + 2
182
+ w = 0 if w < 0
183
+
184
+ x.replace(SPACE.*(w) + gr)
141
185
  end.join
142
186
 
143
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}"
144
189
 
145
- print "#{CLEAR}#{info}#{vertical_gap}#{art_aligned}\n#{date}\n\n#{message_final}"
190
+ if anti_flicker && (height != height2 || width != width2)
191
+ height2, width2 = *STDOUT.winsize
192
+ print CLEAR
193
+ end
194
+
195
+ print "#{clear_character}#{final_output}"
146
196
 
147
197
  if gc_compact && time_now.to_i > gc_compacted
148
198
  GC.compact
149
- gc_compacted = time_now.to_i + 7200
199
+ gc_compacted = time_now.to_i + GC_COMPACT_TIME
150
200
  end
151
201
 
152
- 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)
153
209
  end
154
210
  end
155
211
  end
@@ -2,11 +2,12 @@ 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,
8
9
  exclude_spaces: false,
9
- bold: false, italic: false, blink: false
10
+ bold: false, italic: false, underline: false
10
11
  )
11
12
 
12
13
  temp = ''
@@ -18,10 +19,11 @@ class String
18
19
  init = bg ? 48 : 38
19
20
 
20
21
  style = nil
21
- if bold || italic
22
+ if bold || italic || underline
22
23
  style = "\e["
23
24
  style << '1;'.freeze if bold
24
25
  style << '3;'.freeze if italic
26
+ style << '4;'.freeze if underline
25
27
  style.chop!
26
28
  style << 'm'.freeze
27
29
  end
@@ -30,7 +32,7 @@ class String
30
32
  temp << style if style
31
33
 
32
34
  _r, _g, _b = r, g, b
33
- chomped = !!c.chomp!(''.freeze)
35
+ chomped = !!c.chomp!(EMPTY)
34
36
 
35
37
  len = c.length
36
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,43 +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
95
+
96
+ @@os_v ||= unless LS::OS.version.empty?
97
+ " (#{LS::OS.version})"
98
+ else
99
+ EMPTY
100
+ end
101
+
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" % _second_i
111
+ ms = "%02d" % _second.-(_second_i).*(100)
112
+
113
+ uptime = "\u{1F3A1} Uptime: #{hour}:#{minute}:#{second}:#{ms} (#{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)
66
155
 
67
- os = "\u{1F427} Distrib: #{LS::OS.distribution} #{LS::OS.machine} (#{LS::OS.version})"
156
+ len = str.chars.map { |x|
157
+ _x = x.bytesize./(2)
158
+ _x == 0 ? 1 : _x
159
+ }.sum
68
160
 
69
- max_l = [hostname, process, ip, battery, @@current_net_usage, net_usage].map(&:length).max + 4
161
+ w = width - 2
70
162
 
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
163
+ len < w ? grads.+(SPACE.*(w - len)) : grads
164
+ }.join(NEWLINE)
79
165
  end
80
166
  end
81
167
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Termclock
4
- VERSION = "0.2.0"
4
+ VERSION = "0.5.1"
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.2.0
4
+ version: 0.5.1
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-19 00:00:00.000000000 Z
11
+ date: 2021-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: linux_stat
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.3.1
19
+ version: 1.5.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.3.1
26
+ version: 1.5.1
27
27
  description: A clock for Linux VTE
28
28
  email:
29
29
  - souravgoswami@protonmail.com