termclock 0.1.4 → 0.3.0

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: b642d436f341a05ce85e4203af397fe5b3bc37ffa0c562584c4239d986528949
4
- data.tar.gz: 3352cdd08951821375f5fe6b177c3be8e68bab5af267bfdfead6448a30a8b293
3
+ metadata.gz: ec9759a77ce797b7110a4d5427cf56ca1e7c7188558a84220d233b873d2db1b6
4
+ data.tar.gz: 6262c03faf908cdf536aa461181ed8564408e838f2df4a016da5f90817d25135
5
5
  SHA512:
6
- metadata.gz: '038ed7235df48c8770a3b3dd87e60ec15400b71b8ec25757e186f1ff2bd3ba6c028da1c21144a8295f3eda575ef6872d050594a1f4e49f3e7afae43967ac53a1'
7
- data.tar.gz: 283724a271297ef9af4bd07efa055112f537a91827f4a662f4420754243b383d33981daab6c2ec524409bfff288fbc96e939d6598d3af4c56fad48215830fd9a
6
+ metadata.gz: be6ba479d498ea9155a16e950e8c5f6a240ec3556f3a5a0bccb7120ab48142f9084ea01c0c17c81c229172c9cbd2ac61fd8234063fe9c537d36e1e20ee23e524
7
+ data.tar.gz: 4d17f5be9b2d8b8c61800173c4fc7fb09294d10f17c2d69e35b78d24d1b1ffd758484525594a91bbf627052cfefe6bb0f96d02c9d304f0f94d7429a803abebd8
@@ -2,25 +2,77 @@
2
2
  require 'termclock'
3
3
  $-v = nil
4
4
 
5
+ def version
6
+ emoji = ?🕐.ord.-(1).chr('utf-8')
7
+ Time.now.strftime('%I').to_i.times { emoji.next! }
8
+
9
+ _v = "#{emoji} This is Termclock v#{Termclock::VERSION}"
10
+ vl_2 = _v.length / 2
11
+
12
+ v_col1 = Termclock.hex2rgb('ff0')
13
+ v_col2 = Termclock.hex2rgb('f55')
14
+ v_col3 = Termclock.hex2rgb('55f')
15
+
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)
18
+ end
19
+
5
20
  if ARGV.any? { |x| x[/\A\-(\-help|h)\z/] }
6
21
  puts <<~EOF
7
22
  TermClock: A clock that runs on the LinuxTerminal!
8
23
 
9
- Arguments:
24
+ \e[1;4mArguments:\e[0m
25
+
26
+ \e[1m1. Help and Version:\e[0m
10
27
  --help|-h\t\t\tShows this help section
28
+ --version|-v\t\t\tShows termclock version
29
+
30
+ \e[1m2. Style:\e[0m
31
+ --bold|-b\t\t\tMake texts bold
32
+ --italic|-i\t\t\tMake texts italic
11
33
  --character=|char=\t\tDraws specified character
12
34
  --clean\t\t\t\tJust run the clean bare clock
13
35
  --colour=|-c=\t\t\tSpecify hex colour (4 colours)
14
36
  \t\t\t\t[ with or without # ]
37
+
38
+ \e[1m3. Information:\e[0m
15
39
  --no-date|-nd\t\t\tShows no date
16
40
  --no-message|-nm\t\tShows no messages
17
41
  --no-sysinfo|-ni\t\tShows no system info
42
+ --refresh|r\t\t\tSpecify delay or refresh time
18
43
  --text-colour|-tc\t\tSpecify text colour (2 colours)
44
+ --no-logo|-nl\t\t\tDon't show the logo at the bottom
45
+
46
+ \e[1m4. Formats:\e[0m
47
+ --date-format=|-df=\t\tSpecify the date format
48
+ --time-format=|-tf=\t\tSpecify the time format
49
+
50
+ Usually the format looks like this:
51
+ %H:%M:%S:%2N or %d %B, %Y
52
+
53
+ \e[3mRun `date --help` to know more formats\e[0m
54
+
55
+ Supported characters are 0 - 9, a - z, /, \\, !, %, and |.
56
+
57
+ #{version}
19
58
  EOF
20
59
 
21
60
  exit 0
22
61
  end
23
62
 
63
+ 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
73
+ exit 0
74
+ end
75
+
24
76
  begin
25
77
  print "\e[?25l"
26
78
 
@@ -47,18 +99,34 @@ begin
47
99
  _refresh_time = ARGV.find { |x| x[/\A\-(\-refresh|r)=.*\z/] } &.split(?=) &.at(1)
48
100
  refresh_time = _refresh_time ? _refresh_time.to_f : 0.1
49
101
 
102
+ _time_format = ARGV.find { |x| x[/\A\-(\-time\-format|tf)=.*\z/] } &.split(?=) &.at(1)
103
+ time_format = _time_format ? _time_format : "%H %M %S %2N"
104
+
105
+ _date_format = ARGV.find { |x| x[/\A\-(\-date\-format|df)=.*\z/] } &.split(?=) &.at(1)
106
+ date_format = _date_format ? _date_format : "%a, %d %B %Y"
107
+
50
108
  text_colours = ARGV.find { |x| x[/\A\-(\-text\-colour|tc)=.*\z/] } &.split(?=) &.at(1) &.split(?,)
51
109
  abort("Text colours need 2 colours. Example: -tc=55f,3ce3b5") if text_colours && text_colours.length != 2
52
110
 
53
- bold = ARGV.any? { |x| x[/\A\-\-bold\z/] }
111
+ bold = ARGV.any? { |x| x[/\A\-(\-bold|b)\z/] }
112
+ italic = ARGV.any? { |x| x[/\A\-(\-italic|i)\z/] }
113
+
54
114
  no_print_info = ARGV.any? { |x| x[/\A\-(\-no\-sysinfo|ni)\z/] }
115
+ no_logo = ARGV.any? { |x| x[/\A\-(\-no\-logo|nl)\z/] }
55
116
  no_print_message = ARGV.any? { |x| x[/\A\-(\-no\-message|nm)\z/] }
56
117
  no_print_date = ARGV.any? { |x| x[/\A\-(\-no\-date|nd)\z/] }
57
118
 
58
119
  clean = ARGV.any? { |x| x[/\A\-(\-clean)\z/] }
59
120
 
60
121
  if clean
61
- no_print_info = no_print_message = no_print_date = true
122
+ no_print_info = no_print_message = no_print_date = no_logo = true
123
+ end
124
+
125
+ begin
126
+ Time.now.strftime(time_format)
127
+ Time.now.strftime(date_format)
128
+ rescue
129
+ abort "Date / Time format is invalid\n#{$!.to_s}"
62
130
  end
63
131
 
64
132
  Termclock.start(
@@ -66,9 +134,13 @@ begin
66
134
  *text_colours,
67
135
  sleep: refresh_time,
68
136
  bold: bold,
137
+ italic: italic,
69
138
  print_info: !no_print_info,
70
139
  print_message: !no_print_message,
71
- print_date: !no_print_date
140
+ print_date: !no_print_date,
141
+ no_logo: no_logo,
142
+ time_format: time_format,
143
+ date_format: date_format
72
144
  )
73
145
  rescue Interrupt, SignalException
74
146
  print "\e[H\e[2J\e[3J"
@@ -1,8 +1,16 @@
1
1
  require 'linux_stat'
2
2
  require 'io/console'
3
+ require_relative "termclock/version"
4
+
5
+ module Termclock
6
+ CLEAR = "\e[H\e[2J\e[3J".freeze
7
+ NEWLINE = ?\n.freeze
8
+ SPACE = ?\s.freeze
9
+ TAB = ?\t.freeze
10
+ end
11
+
3
12
  require_relative "termclock/string"
4
13
  require_relative "termclock/parse_characters"
5
14
  require_relative "termclock/system_info"
6
- require_relative "termclock/main"
15
+ require_relative "termclock/start"
7
16
  require_relative "termclock/hex2rgb"
8
- require_relative "termclock/version"
@@ -1,6 +1,5 @@
1
1
  module Termclock
2
2
  module ParseCharacters
3
- NEWLINE = ?\n.freeze
4
3
  CHARACTERS = <<~EOF.freeze
5
4
  # 0
6
5
  ````````
@@ -143,9 +142,9 @@ module Termclock
143
142
 
144
143
  # I
145
144
  ````````
146
- `
147
- `
148
- `
145
+ \s\s\s``
146
+ \s\s\s``
147
+ \s\s\s``
149
148
  ````````
150
149
 
151
150
  # J
@@ -236,8 +235,8 @@ module Termclock
236
235
  `` ``
237
236
  `` ``
238
237
  `` ``
239
- `` ``
240
- `
238
+ \s`` ``\s
239
+ \s\s\s``
241
240
 
242
241
  # W
243
242
  `` ``
@@ -247,11 +246,11 @@ module Termclock
247
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
@@ -293,7 +327,7 @@ module Termclock
293
327
 
294
328
  if stripped
295
329
  replace_with = x.chars.map { |y|
296
- chars = arg.chars.rotate(-1) if y == ?\n
330
+ chars = arg.chars.rotate(-1) if y == NEWLINE
297
331
  next(y) if y != stripped
298
332
  chars.rotate!(1)[0]
299
333
  }.join
@@ -0,0 +1,200 @@
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
+ no_logo: false
12
+ )
13
+
14
+ generate = proc do |start, stop, n = 5|
15
+ r_op = r_val = nil
16
+ ary = []
17
+
18
+ if start > stop
19
+ r_op, r_val = :-, start.-(stop).fdiv(n - 1)
20
+ elsif start < stop
21
+ r_op, r_val = :+, stop.-(start).fdiv(n - 1)
22
+ end
23
+
24
+ _r = r_op ? start.send(r_op, r_val * -1) : start
25
+ n.times {
26
+ _r = _r.send(r_op, r_val) if r_op
27
+ ary << _r.clamp(0, 255).to_i
28
+ }
29
+
30
+ ary
31
+ end
32
+
33
+ gc_compact, gc_compacted = GC.respond_to?(:compact), Time.now.to_i + 7200
34
+ print CLEAR
35
+
36
+ r1, g1, b1 = *colour1
37
+ r2, g2, b2 = *colour2
38
+ r3, g3, b3 = *colour3
39
+ r4, g4, b4 = *colour4
40
+
41
+ # colour1 -> colour3
42
+ rs1 = generate.(r1, r3)
43
+ gs1 = generate.(g1, g3)
44
+ bs1 = generate.(b1, b3)
45
+
46
+ # colour2 -> colour4
47
+ rs2 = generate.(r2, r4)
48
+ gs2 = generate.(g2, g4)
49
+ bs2 = generate.(b2, b4)
50
+
51
+ # All Gradient Colours
52
+ colours = [rs1, gs1, bs1].transpose.zip([rs2, gs2, bs2].transpose)
53
+ colours.unshift(colours[0])
54
+ colours.push(colours[-1])
55
+
56
+ # Text colours
57
+ tc1 = textcolour1 ? hex2rgb(textcolour1) : hex2rgb('5555ff')
58
+ tc2 = textcolour2 ? hex2rgb(textcolour2) : hex2rgb('3ce3b5')
59
+
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
+ message_counter = -1
68
+ message = ''
69
+ message_final = ''
70
+ message_align = 0
71
+ message_temp = ''
72
+ point_five_tick = 0
73
+
74
+ date, info = '', ''
75
+
76
+ clock_emoji = ?\u{1F550}.ord.-(1).chr('utf-8')
77
+ clock_emoji = 12.times.map { clock_emoji.next!.dup }
78
+
79
+ braille = %W(\u2821 \u2811 \u2812 \u280A \u280C)
80
+
81
+ get_message = proc {
82
+ braille.rotate!
83
+ braille_0 = braille[0]
84
+
85
+ case Time.now.hour
86
+ when 5...12
87
+ "\u{1F304} #{braille_0} Good Morning #{braille_0} \u{1F304}"
88
+ when 12...16
89
+ "\u26C5 #{braille_0} Good Afternoon #{braille_0} \u26C5"
90
+ when 16...18
91
+ "\u{1F307} #{braille_0} Good Evening #{braille_0} \u{1F307}"
92
+ when 18...20
93
+ "\u{1F31F} #{braille_0} Good Evening #{braille_0} \u{1F31F}"
94
+ when 20...24
95
+ "\u{1F303} #{braille_0} Good Night #{braille_0} \u{1F303}"
96
+ else
97
+ "\u{2728} #{braille_0} Good Night #{braille_0} \u{2728}"
98
+ end
99
+ }
100
+
101
+ version = "Termclock v#{Termclock::VERSION}"
102
+
103
+ v_col1 = hex2rgb('ff0')
104
+ v_col2 = hex2rgb('f55')
105
+ v_col3 = hex2rgb('f55')
106
+ v_col4 = hex2rgb('55f')
107
+
108
+ vl_2 = version.length / 2
109
+ _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)
111
+
112
+ term_clock_v = ''
113
+
114
+ chop_message = 0
115
+
116
+ while true
117
+ time_now = Time.now
118
+ height, width = *STDOUT.winsize
119
+
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
131
+ end
132
+
133
+ unless no_logo
134
+ term_clock_v = "\e[#{height}H #{clock_emoji[0]} #{_term_clock_v} \e[0m"
135
+ end
136
+
137
+ if print_message
138
+ message_temp = get_message.call
139
+ message_counter += 1
140
+ message_length = message.length
141
+
142
+ if (width - message_counter % width < 8)
143
+ unless chop_message == message_temp.length
144
+ chop_message += 1
145
+ message_counter -= 1
146
+ message_align -= 1
147
+ message.replace(message_temp[chop_message..-1])
148
+ end
149
+ else
150
+ chop_message = 0 unless chop_message == 0
151
+ message.clear if width - message_counter % width == width
152
+ message_align = width - message_counter % width + message_length - 4
153
+
154
+ if message_temp != message
155
+ if message_length < message_temp.length
156
+ message.replace(message_temp[0..message_length])
157
+ else
158
+ message.replace(message_temp)
159
+ end
160
+ end
161
+ end
162
+
163
+ message_final = (message).rjust(message_align).gradient(
164
+ tc1, tc2, exclude_spaces: true, bold: bold, italic: italic
165
+ )
166
+ end
167
+
168
+ if print_info
169
+ info = system_info(width).gradient(
170
+ tc1, tc2, bold: bold, italic: italic
171
+ )
172
+ end
173
+
174
+ if print_date
175
+ date = time_now.strftime(date_format).center(width)
176
+ .gradient(tc1, tc2, bold: bold, italic: italic)
177
+ end
178
+
179
+ time = time_now.strftime(time_format).split.join(splitter)
180
+ art = Termclock::ParseCharacters.display(time).lines
181
+
182
+ art_aligned = art.each_with_index do |x, i|
183
+ chomped = x.chomp(''.freeze).+(NEWLINE)
184
+ 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)
186
+ end.join
187
+
188
+ vertical_gap = "\e[#{height./(2.0).-(art.length / 2.0).to_i + 1}H"
189
+
190
+ print "#{CLEAR}#{info}#{vertical_gap}#{art_aligned}\n#{date}\n\n#{message_final}#{term_clock_v}"
191
+
192
+ if gc_compact && time_now.to_i > gc_compacted
193
+ GC.compact
194
+ gc_compacted = time_now.to_i + 7200
195
+ end
196
+
197
+ sleep(sleep)
198
+ end
199
+ end
200
+ end
@@ -1,5 +1,14 @@
1
1
  class String
2
- def gradient(*all_rgbs, bg: false, exclude_spaces: false, bold: 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, underline: false
10
+ )
11
+
3
12
  temp = ''
4
13
 
5
14
  r, g, b = all_rgbs[0]
@@ -8,7 +17,19 @@ class String
8
17
 
9
18
  init = bg ? 48 : 38
10
19
 
20
+ style = nil
21
+ if bold || italic || underline
22
+ style = "\e["
23
+ style << '1;'.freeze if bold
24
+ style << '3;'.freeze if italic
25
+ style << '4;'.freeze if underline
26
+ style.chop!
27
+ style << 'm'.freeze
28
+ end
29
+
11
30
  each_line do |c|
31
+ temp << style if style
32
+
12
33
  _r, _g, _b = r, g, b
13
34
  chomped = !!c.chomp!(''.freeze)
14
35
 
@@ -45,13 +66,11 @@ class String
45
66
  _g = _g.send(g_op, g_val * -1) if g_op
46
67
  _b = _b.send(b_op, b_val * -1) if b_op
47
68
 
48
- temp << "\e[1m" if bold
49
-
50
69
  i = -1
51
70
  while (i += 1) < len
52
71
  _c = c[i]
53
72
 
54
- if !exclude_spaces || (exclude_spaces && !(_c == ?\s.freeze || _c == ?\t.freeze))
73
+ if !exclude_spaces || (exclude_spaces && !(_c == SPACE || _c == TAB))
55
74
  _r = _r.send(r_op, r_val) if r_op
56
75
  _g = _g.send(g_op, g_val) if g_op
57
76
  _b = _b.send(b_op, b_val) if b_op
@@ -72,7 +91,7 @@ class String
72
91
  ret = if !c.empty?
73
92
  chomped ? "\e[0m\n".freeze : "\e[0m".freeze
74
93
  elsif chomped
75
- ?\n.freeze
94
+ NEWLINE
76
95
  end
77
96
 
78
97
  temp << ret
@@ -1,12 +1,12 @@
1
1
  module Termclock
2
2
  @@cpu_usage = 0
3
- @@cpu_usage_t = Thread.new { }
3
+ @@cpu_usage_t = Thread.new { }.join
4
4
 
5
- @@current_net_usage = ''
6
- @@current_net_usage_t = Thread.new { }
5
+ @@current_net_usage = "\u{1F4CA} Curr. DL/UL:"
6
+ @@current_net_usage_t = Thread.new { }.join
7
7
 
8
8
  class << self
9
- def system_info(width, tc1, tc2, bold)
9
+ def system_info(width)
10
10
  unless @@cpu_usage_t.alive?
11
11
  @@cpu_usage_t = Thread.new { @@cpu_usage = LS::CPU.usage(0.25) }
12
12
  end
@@ -55,19 +55,34 @@ module Termclock
55
55
  _m = LS::Filesystem.stat
56
56
  fs = "\u{1F4BD} FS: #{LS::PrettifyBytes.convert_short_binary(_m[:used].to_i)}"\
57
57
  " / #{LS::PrettifyBytes.convert_short_binary(_m[:total].to_i)}"\
58
- " (#{_m[:used].to_i*(100).fdiv(_m[:total].to_i).round(2)}%)"
58
+ " (#{_m[:used].to_i.*(100).fdiv(_m[:total].to_i).round(2)}%)"
59
59
 
60
- process = "\u{1F9EE} Process: #{LS::Process.count}"
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_v = LS::OS.version
68
+ os_v = unless _os_v.empty?
69
+ " (#{_os_v})"
70
+ else
71
+ ''.freeze
72
+ end
73
+
74
+ os = "\u{1F427} Distrib: #{LS::OS.distribution} #{LS::OS.machine}#{os_v}"
61
75
 
62
76
  max_l = [hostname, process, ip, battery, @@current_net_usage, net_usage].map(&:length).max + 4
63
77
 
64
- <<~EOF.gradient(tc1, tc2, exclude_spaces: true, bold: bold)
65
- \s#{user}#{?\s.*(width.-(user.length + max_l).abs)}#{hostname}
66
- \s#{cpu}#{?\s.*(width.-(cpu.length + max_l).abs)}#{battery}
67
- \s#{memory}#{?\s.*(width.-(memory.length + max_l).abs)}#{ip}
68
- \s#{swap}#{?\s.*(width.-(swap.length + max_l).abs)}#{@@current_net_usage}
69
- \s#{fs}#{?\s.*(width.-(fs.length + max_l).abs)}#{net_usage}
70
- EOF
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
71
86
  end
72
87
  end
73
88
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Termclock
4
- VERSION = "0.1.4"
4
+ VERSION = "0.3.0"
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.4
4
+ version: 0.3.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-14 00:00:00.000000000 Z
11
+ date: 2021-01-21 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.4.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.3.1
26
+ version: 1.4.0
27
27
  description: A clock for Linux VTE
28
28
  email:
29
29
  - souravgoswami@protonmail.com
@@ -35,8 +35,8 @@ 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
41
  - lib/termclock/system_info.rb
42
42
  - lib/termclock/version.rb
@@ -1,152 +0,0 @@
1
- module Termclock
2
- COLOURTERM = ENV.key?('COLORTERM')
3
- CLEAR = COLOURTERM ? "\e[H\e[2J\e[3J" : "\e[H"
4
-
5
- def self.start(colour1, colour2, colour3, colour4, textcolour1 = nil,
6
- textcolour2 = nil, sleep: 0.1, bold: false,
7
- print_info: true, print_message: true,
8
- print_date: true
9
- )
10
-
11
- newline = ?\n.freeze
12
- space = ?\s.freeze
13
-
14
- generate = proc do |start, stop, n = 5|
15
- r_op = r_val = nil
16
- ary = []
17
-
18
- if start > stop
19
- r_op, r_val = :-, start.-(stop).fdiv(n - 1)
20
- elsif start < stop
21
- r_op, r_val = :+, stop.-(start).fdiv(n - 1)
22
- end
23
-
24
- _r = r_op ? start.send(r_op, r_val * -1) : start
25
- n.times {
26
- _r = _r.send(r_op, r_val) if r_op
27
- ary << _r.clamp(0, 255).to_i
28
- }
29
-
30
- ary
31
- end
32
-
33
- gc_compact, gc_compacted = GC.respond_to?(:compact), Time.now.to_i + 7200
34
- print "\e[H\e[2J\e[3J" unless COLOURTERM
35
-
36
- r1, g1, b1 = *colour1
37
- r2, g2, b2 = *colour2
38
- r3, g3, b3 = *colour3
39
- r4, g4, b4 = *colour4
40
-
41
- # colour1 -> colour3
42
- rs1 = generate.(r1, r3)
43
- gs1 = generate.(g1, g3)
44
- bs1 = generate.(b1, b3)
45
-
46
- # colour2 -> colour4
47
- rs2 = generate.(r2, r4)
48
- gs2 = generate.(g2, g4)
49
- bs2 = generate.(b2, b4)
50
-
51
- # All Gradient Colours
52
- colours = [rs1, gs1, bs1].transpose.zip([rs2, gs2, bs2].transpose)
53
- colours.unshift(colours[0])
54
- colours.push(colours[-1])
55
-
56
- # Text colours
57
- tc1 = textcolour1 ? hex2rgb(textcolour1) : hex2rgb('5555ff')
58
- tc2 = textcolour2 ? hex2rgb(textcolour2) : hex2rgb('3ce3b5')
59
-
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
- message_counter = -1
68
- message = ''
69
- message_final = ''
70
- message_temp = ''
71
- caret = "\u2588"
72
-
73
- date, info = '', ''
74
-
75
- get_message = proc {
76
- case Time.now.hour
77
- when 5...12
78
- "\u{1F304} Good Morning..."
79
- when 12...16
80
- "\u26C5 Good Afternoon..."
81
- when 16...18
82
- "\u{1F307} Good Evening..."
83
- when 18...20
84
- "\u{1F31F} Good Evening..."
85
- when 20...24
86
- "\u{1F303} Good Night..."
87
- else
88
- "\u{2728} Good Night..."
89
- end
90
- }
91
-
92
- while true
93
- time_now = Time.now
94
- height, width = *STDOUT.winsize
95
-
96
- if time_now.to_f./(0.5).to_i.even?
97
- splitter = ?:.freeze
98
- _caret = caret
99
- else
100
- splitter = ?$.freeze
101
- _caret = ''
102
- end
103
-
104
- if print_message
105
- message_counter += 1
106
- message_align = width - message_counter % width + message.length / 2 - 4
107
- if (width - message_counter % width <= message.length)
108
- message.replace(message[1..-1])
109
- message_align = width - message_counter % width + 4
110
- else
111
- message.clear if width - message_counter % width == width
112
- message_temp = get_message.call
113
-
114
- if message_temp != message
115
- message << message_temp[message.length..message.length + 1]
116
- end
117
- end
118
-
119
- message_final = message.rjust(message_align).+(_caret).gradient(tc1, tc2, exclude_spaces: true, bold: bold)
120
- end
121
-
122
- if print_info
123
- info = system_info(width, tc1, tc2, bold)
124
- end
125
-
126
- if print_date
127
- date = time_now.strftime('%a, %d %B %Y').center(width)
128
- .gradient(tc1, tc2, bold: bold)
129
- end
130
-
131
- time = time_now.strftime('%H %M %S %2N').split.join(splitter)
132
- art = Termclock::ParseCharacters.display(time).lines
133
-
134
- art_aligned = art.each_with_index do |x, i|
135
- chomped = x.chomp(''.freeze).+(newline)
136
- gr = chomped.gradient(*colours[i], bold: bold)
137
- x.replace(space.*(width./(2.0).-(chomped.length / 2.0).abs.to_i + 1) + gr)
138
- end.join
139
-
140
- vertical_gap = "\e[#{height./(2.0).-(art.length / 2.0).to_i + 1}H"
141
-
142
- print "#{CLEAR}#{info}#{vertical_gap}#{art_aligned}\n#{date}\n\n#{message_final}"
143
-
144
- if gc_compact && time_now.to_i > gc_compacted
145
- GC.compact
146
- gc_compacted = time_now.to_i + 7200
147
- end
148
-
149
- sleep(sleep)
150
- end
151
- end
152
- end