termclock 0.1.2 → 0.1.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: 1e17d6410f4890cf9e070491f01c722e08b3678dca7e0cf4af4edfa3e4a6c020
4
- data.tar.gz: a00abd3c09b311a4fa62acd03c5147033a7c758417877db2d132e1b3d5e954b2
3
+ metadata.gz: 746cefa7bb14ad6ea4c2886b3631047a1d28eaf65a23709f69dd53a1af139929
4
+ data.tar.gz: 5f71dfabd6b0608b41f7707d89d09521b2d1121d8206f5279d67be242fd49850
5
5
  SHA512:
6
- metadata.gz: 40822adf435db689057290c054ea2f42a9afff94cd49053aed5d5ddf3b0dcbb168e7ce23fe3e130afbcb43c58f128bd689d1243bca52015ac245b44b05e24440
7
- data.tar.gz: 9aa729c8ee4fb0b299da55f666a942ef21cccfc66ff94a5b54969594d8dc80aec38361c9c779cf813a312d89089589fb3e9c8010c31d05181a0435549fcfeac1
6
+ metadata.gz: ac18271d58739a9061f6c582d031f2bcd8e329259069681e8abb253a14af60307fb3253ff8468509afdc01057e2f802cbe1c32ba7d08a91c5df2ab944b65adc3
7
+ data.tar.gz: 83e4ebc5a42e09cc880bd11468730266d8807b8aee72a873b04e8acf1867bcc9ae6500e13909ed421a37b6888c6bcaea9e8764ab5b0d6c7f6f0c0e02374af75c
@@ -26,7 +26,14 @@ begin
26
26
  chars = ARGV.find { |x| x[/\A\-(\-character|char)=.*\z/] } &.split(?=) &.at(1)
27
27
  Termclock::ParseCharacters.transform_characters!(chars[0]) if chars
28
28
 
29
- Termclock.main(*colours)
29
+ _refresh_time = ARGV.find { |x| x[/\A\-(\-refresh|r)=.*\z/] } &.split(?=) &.at(1)
30
+ refresh_time = _refresh_time ? _refresh_time.to_f : 0.1
31
+
32
+ text_colours = ARGV.find { |x| x[/\A\-(\-text\-colour|tc)=.*\z/] } &.split(?=) &.at(1) &.split(?,)
33
+
34
+ abort("Text colours need 2 colours. Example: -tc=55f,3ce3b5") if text_colours && text_colours.length != 2
35
+
36
+ Termclock.start(*colours, *text_colours, sleep: refresh_time)
30
37
  rescue Interrupt, SignalException
31
38
  print "\e[H\e[2J\e[3J"
32
39
  ensure
@@ -1,8 +1,3 @@
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'
8
3
  require_relative "termclock/string"
@@ -1,5 +1,8 @@
1
1
  module Termclock
2
- def self.main(colour1, colour2, colour3, colour4, sleep = 0.1)
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, textcolour2 = nil, sleep: 0.1)
3
6
  newline = ?\n.freeze
4
7
  space = ?\s.freeze
5
8
 
@@ -44,8 +47,17 @@ module Termclock
44
47
  colours = [rs1, gs1, bs1].transpose.zip([rs2, gs2, bs2].transpose)
45
48
  colours.unshift(colours[0])
46
49
  colours.push(colours[-1])
50
+
51
+ # Text colours
52
+ tc1 = textcolour1 ? hex2rgb(textcolour1) : hex2rgb('5555ff')
53
+ tc2 = textcolour2 ? hex2rgb(textcolour2) : hex2rgb('3ce3b5')
54
+
47
55
  cpu_usage = 0
48
56
  cpu_usage_t = Thread.new { }
57
+
58
+ current_net_usage = ''
59
+ current_net_usage_t = Thread.new { }
60
+
49
61
  message_time = Time.now.to_i - 5
50
62
  message = ''
51
63
  message_temp = ''
@@ -69,7 +81,6 @@ module Termclock
69
81
  }
70
82
 
71
83
  i = -1
72
-
73
84
  while true
74
85
  i += 1
75
86
  time_now = Time.now
@@ -99,34 +110,50 @@ module Termclock
99
110
  end
100
111
 
101
112
  time = time_now.strftime("%H %M %S %2N").split.join(splitter)
102
- art = Termclock::ParseCharacters.display(time)
113
+ art = Termclock::ParseCharacters.display(time).lines
103
114
 
104
- art_aligned = art.lines.each_with_index do |x, i|
115
+ art_aligned = art.each_with_index do |x, i|
105
116
  chomped = x.chomp(''.freeze).+(newline)
106
117
  gr = chomped.gradient(*colours[i])
107
118
  x.replace(space.*(width./(2.0).-(chomped.length / 2.0).abs.to_i + 1) + gr)
108
119
  end.join
109
120
 
110
- horizontal_gap = "\e[#{height./(2.0).-(art.lines.length / 2.0).to_i + 1}H"
121
+ vertical_gap = "\e[#{height./(2.0).-(art.length / 2.0).to_i + 1}H"
111
122
 
112
123
  unless cpu_usage_t.alive?
113
124
  cpu_usage_t = Thread.new { cpu_usage = LS::CPU.usage(0.25) }
114
125
  end
115
126
 
116
- cpu = "\u{1F9E0} CPU: #{cpu_usage}% (#{LS::CPU.count_online} / #{LS::CPU.count})"
127
+ unless current_net_usage_t.alive?
128
+ current_net_usage_t = Thread.new do
129
+ _m = LS::Net.current_usage(0.25)
130
+
131
+ _dl = LS::PrettifyBytes.convert_short_binary(_m[:received], precision: 0)
132
+ _ul = LS::PrettifyBytes.convert_short_binary(_m[:transmitted], precision: 0)
133
+
134
+ current_net_usage = "\u{1F4CA} Curr. DL/UL: #{sprintf "%-7s", _dl} | #{sprintf "%7s", _ul}"
135
+ end
136
+ end
137
+
138
+ cpu = "\u{1F9E0} CPU: #{sprintf "%5s", cpu_usage}% (#{LS::CPU.count_online} / #{LS::CPU.count})"
117
139
 
118
140
  battery = if LS::Battery.present?
119
141
  stat = LS::Battery.stat
120
142
  emoji = LS::Battery.charging? ? "\u{1F4A1}" : "\u{1F50B}"
121
- "#{emoji} Battery: #{stat[:charge].to_i}% (#{stat[:status]})"
143
+ plug = LS::Battery.charging? ? "\u{1F50C} " : ''.freeze
144
+ "#{emoji} Battery: #{stat[:charge].to_i}% (#{plug}#{stat[:status]})"
122
145
  else
123
146
  ''.freeze
124
147
  end
125
148
 
149
+ user = "\u{1F481} User: #{LS::User.get_current_user.capitalize}"
150
+ hostname = "\u{1F4BB} Hostname: #{LS::OS.hostname}"
151
+
126
152
  _m = LS::Net.total_bytes
127
- ip = "\u{1F30F} IP: #{LS::Net.ipv4_private}"
128
- net_usage = "\u{1F4C8} D/L | U/L: #{LS::PrettifyBytes.convert_short_binary(_m[:received].to_i)}"\
129
- " | #{LS::PrettifyBytes.convert_short_binary(_m[:transmitted].to_i)}"
153
+ ip = "\u{1F30F} IP Addr: #{LS::Net.ipv4_private}"
154
+
155
+ net_usage = "\u{1F4C8} Totl. DL/UL: #{sprintf "%-7s", LS::PrettifyBytes.convert_short_binary(_m[:received], precision: 0)}"\
156
+ " | #{sprintf "%7s", LS::PrettifyBytes.convert_short_binary(_m[:transmitted], precision: 0)}"
130
157
 
131
158
  _m = LS::Memory.stat
132
159
  memory = "\u{1F3B0} Mem: #{LS::PrettifyBytes.convert_short_binary(_m[:used].to_i * 1024)}"\
@@ -144,18 +171,19 @@ module Termclock
144
171
  " (#{_m[:used].to_i*(100).fdiv(_m[:total].to_i).round(2)}%)"
145
172
 
146
173
  process = "\u{1F9EE} Process: #{LS::Process.count}"
174
+ message_final = message.rjust(message_align).+(_caret).gradient(tc1, tc2, exclude_spaces: true)
147
175
 
148
- max_l = [process, ip, battery, net_usage].map(&:length).max
176
+ max_l = [hostname, process, ip, battery, current_net_usage, net_usage].map(&:length).max + 4
149
177
 
150
- info = <<~EOF.gradient(*colours[2], exclude_spaces: true)
151
- \s#{cpu}#{?\s.*(width.-(cpu.length + max_l + 4).abs)}#{battery}
152
- \s#{memory}#{?\s.*(width.-(memory.length + max_l + 4).abs)}#{ip}
153
- \s#{swap}#{?\s.*(width.-(swap.length + max_l + 4).abs)}#{net_usage}
154
- \s#{fs}#{?\s.*(width.-(fs.length + max_l + 4).abs)}#{process}
178
+ info = <<~EOF.gradient(tc1, tc2, exclude_spaces: true)
179
+ \s#{user}#{?\s.*(width.-(user.length + max_l).abs)}#{hostname}
180
+ \s#{cpu}#{?\s.*(width.-(cpu.length + max_l).abs)}#{battery}
181
+ \s#{memory}#{?\s.*(width.-(memory.length + max_l).abs)}#{ip}
182
+ \s#{swap}#{?\s.*(width.-(swap.length + max_l).abs)}#{current_net_usage}
183
+ \s#{fs}#{?\s.*(width.-(fs.length + max_l).abs)}#{net_usage}
155
184
  EOF
156
185
 
157
- print "#{CLEAR}#{info}#{horizontal_gap}#{art_aligned}\n"\
158
- "#{message.rjust(message_align).+(_caret).gradient(*colours[1], exclude_spaces: true)}"
186
+ print "#{CLEAR}#{info}#{vertical_gap}#{art_aligned}\n#{message_final}"
159
187
 
160
188
  if gc_compact && time_now.to_i > gc_compacted
161
189
  GC.compact
@@ -73,11 +73,11 @@ module Termclock
73
73
  ```````
74
74
 
75
75
  # :
76
- ⬩⬩
77
- ⬩⬩
76
+ \u2B29\u2B29
77
+ \u2B29\u2B29
78
78
 
79
- ⬩⬩
80
- ⬩⬩
79
+ \u2B29\u2B29
80
+ \u2B29\u2B29
81
81
 
82
82
  # $
83
83
  \s\s
@@ -290,17 +290,17 @@ module Termclock
290
290
  end
291
291
 
292
292
  def display(c)
293
- j = ['', '']
293
+ j = []
294
294
 
295
- c.upcase.chars.map! { |x|
296
- @@characters.fetch(x, x).split(?\n.freeze)
295
+ c.upcase.each_char { |x|
296
+ @@characters.fetch(x, x).split(NEWLINE)
297
297
  .each_with_index { |z, i|
298
298
  _j = j[i]
299
299
  _j && _j << z || j[i] = z
300
300
  }
301
301
  }
302
302
 
303
- j.join(?\n.freeze)
303
+ j.join(NEWLINE)
304
304
  end
305
305
  end
306
306
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Termclock
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: termclock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.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-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
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.3.0
19
+ version: 1.3.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.3.0
26
+ version: 1.3.1
27
27
  description: A clock for Linux VTE
28
28
  email:
29
29
  - souravgoswami@protonmail.com