termclock 0.1.6 → 0.2.0

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: '0916f4a4beb06eae575611343e1235e5fa9a0585116fd9694622d1a5e9867938'
4
- data.tar.gz: 53f9236790df604fe8eb5f0c1a4d0cb5ed0179c6aed3c04da4ae8b26398269ee
3
+ metadata.gz: a889b38c921c98e808156b9feeee5dccb8ad10952a17f2b591ed14b6297f2075
4
+ data.tar.gz: 2676b0ba7b8ad4d2b604282845d2fe4d7101eb5a0c39d076833195e6ada67bfd
5
5
  SHA512:
6
- metadata.gz: f85098f0082eca3776b0349b65a34323491c8372cf2b426c91bedde2d5031be210da5fe49d36f773a95afdc9fc6907bbcc9b7e1e3d5e863624106d8e4112ac8f
7
- data.tar.gz: a116f54e530fdfcecfc7f415812aa107bddd7e98409090acbd2f039aefccf0db937f47a8f441d5fa35b1fbe75974ff8795745d3a63da28187c85f275090fb24e
6
+ metadata.gz: 04e505fe18c33d49dcc050e3bf06a2ef2484c38b4b0b6b3d5f00ccb47a5551973641621411304342e3314b8255893db00aef62b775fecac001726347e80f5045
7
+ data.tar.gz: b7c740f14ee7df1ed1c4c4774f0696eb20c84850eec4b402a8fde75f6864bf6a068465a114680095dd5453fb00bcf33a08c4607a46efefa535dcb033cda8e556
@@ -6,23 +6,54 @@ if ARGV.any? { |x| x[/\A\-(\-help|h)\z/] }
6
6
  puts <<~EOF
7
7
  TermClock: A clock that runs on the LinuxTerminal!
8
8
 
9
- Arguments:
9
+ \e[1;4mArguments:\e[0m
10
+
11
+ 1. Help and Version:\e[0m
10
12
  --help|-h\t\t\tShows this help section
11
- --bold\t\t\t\tMake texts bold
13
+ --version|-v\t\t\tShows termclock version
14
+
15
+ 2. Style:\e[0m
16
+ --bold|-b\t\t\tMake texts bold
17
+ --italic|-i\t\t\tMake texts italic
12
18
  --character=|char=\t\tDraws specified character
13
19
  --clean\t\t\t\tJust run the clean bare clock
14
20
  --colour=|-c=\t\t\tSpecify hex colour (4 colours)
15
21
  \t\t\t\t[ with or without # ]
22
+
23
+ 3. Information:\e[0m
16
24
  --no-date|-nd\t\t\tShows no date
17
25
  --no-message|-nm\t\tShows no messages
18
26
  --no-sysinfo|-ni\t\tShows no system info
19
27
  --refresh|r\t\t\tSpecify delay or refresh time
20
28
  --text-colour|-tc\t\tSpecify text colour (2 colours)
29
+
30
+ 4. Formats:\e[0m
31
+ --date-format=|-df=\t\tSpecify the date format
32
+ \t\t\t\t[ Run date --help for formats ]
33
+ --time-format=|-tf=\t\tSpecify the time format
34
+ \t\t\t\t[ Run date --help for formats ]
35
+
36
+ Supported characters are 0 - 9, a - z, /, \\, !, %, and |.
37
+
38
+ This is Termclock v#{Termclock::VERSION}
21
39
  EOF
22
40
 
23
41
  exit 0
24
42
  end
25
43
 
44
+ 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)
54
+ exit 0
55
+ end
56
+
26
57
  begin
27
58
  print "\e[?25l"
28
59
 
@@ -49,10 +80,18 @@ begin
49
80
  _refresh_time = ARGV.find { |x| x[/\A\-(\-refresh|r)=.*\z/] } &.split(?=) &.at(1)
50
81
  refresh_time = _refresh_time ? _refresh_time.to_f : 0.1
51
82
 
83
+ _time_format = ARGV.find { |x| x[/\A\-(\-time\-format|tf)=.*\z/] } &.split(?=) &.at(1)
84
+ time_format = _time_format ? _time_format : "%H %M %S %2N"
85
+
86
+ _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'"
88
+
52
89
  text_colours = ARGV.find { |x| x[/\A\-(\-text\-colour|tc)=.*\z/] } &.split(?=) &.at(1) &.split(?,)
53
90
  abort("Text colours need 2 colours. Example: -tc=55f,3ce3b5") if text_colours && text_colours.length != 2
54
91
 
55
- bold = ARGV.any? { |x| x[/\A\-\-bold\z/] }
92
+ bold = ARGV.any? { |x| x[/\A\-(\-bold|b)\z/] }
93
+ italic = ARGV.any? { |x| x[/\A\-(\-italic|i)\z/] }
94
+
56
95
  no_print_info = ARGV.any? { |x| x[/\A\-(\-no\-sysinfo|ni)\z/] }
57
96
  no_print_message = ARGV.any? { |x| x[/\A\-(\-no\-message|nm)\z/] }
58
97
  no_print_date = ARGV.any? { |x| x[/\A\-(\-no\-date|nd)\z/] }
@@ -68,9 +107,12 @@ begin
68
107
  *text_colours,
69
108
  sleep: refresh_time,
70
109
  bold: bold,
110
+ italic: italic,
71
111
  print_info: !no_print_info,
72
112
  print_message: !no_print_message,
73
- print_date: !no_print_date
113
+ print_date: !no_print_date,
114
+ time_format: time_format,
115
+ date_format: date_format
74
116
  )
75
117
  rescue Interrupt, SignalException
76
118
  print "\e[H\e[2J\e[3J"
@@ -12,6 +12,6 @@ end
12
12
  require_relative "termclock/string"
13
13
  require_relative "termclock/parse_characters"
14
14
  require_relative "termclock/system_info"
15
- require_relative "termclock/main"
15
+ require_relative "termclock/start"
16
16
  require_relative "termclock/hex2rgb"
17
17
  require_relative "termclock/version"
@@ -142,9 +142,9 @@ module Termclock
142
142
 
143
143
  # I
144
144
  ````````
145
- `
146
- `
147
- `
145
+ \s\s\s``
146
+ \s\s\s``
147
+ \s\s\s``
148
148
  ````````
149
149
 
150
150
  # J
@@ -235,8 +235,8 @@ module Termclock
235
235
  `` ``
236
236
  `` ``
237
237
  `` ``
238
- `` ``
239
- `
238
+ \s`` ``\s
239
+ \s\s\s``
240
240
 
241
241
  # W
242
242
  `` ``
@@ -246,11 +246,11 @@ module Termclock
246
246
  ````````
247
247
 
248
248
  # X
249
- ` `
250
- ` `
251
- `
252
- ` `
253
- ` `
249
+ `` ``
250
+ \s`` ``
251
+ \s\s\s``
252
+ \s`` ``
253
+ `` ``
254
254
 
255
255
  # Y
256
256
  `` ``
@@ -265,6 +265,41 @@ module Termclock
265
265
  ``
266
266
  ``
267
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
268
303
  EOF
269
304
 
270
305
  class << self
@@ -3,8 +3,11 @@ module Termclock
3
3
  textcolour1 = nil, textcolour2 = nil,
4
4
  sleep: 0.1,
5
5
  bold: false,
6
+ italic: false,
6
7
  print_info: true, print_message: true,
7
- print_date: true
8
+ print_date: true,
9
+ time_format: "%H %M %S %2N",
10
+ date_format: '%a, %d %B %Y'
8
11
  )
9
12
 
10
13
  generate = proc do |start, stop, n = 5|
@@ -112,24 +115,28 @@ module Termclock
112
115
  end
113
116
  end
114
117
 
115
- message_final = message.rjust(message_align).+(_caret).gradient(tc1, tc2, exclude_spaces: true, bold: bold)
118
+ message_final = message.rjust(message_align).+(_caret).gradient(
119
+ tc1, tc2, exclude_spaces: true, bold: bold, italic: italic
120
+ )
116
121
  end
117
122
 
118
123
  if print_info
119
- info = system_info(width, tc1, tc2, bold)
124
+ info = system_info(width).gradient(
125
+ tc1, tc2, bold: bold, italic: italic
126
+ )
120
127
  end
121
128
 
122
129
  if print_date
123
- date = time_now.strftime('%a, %d %B %Y').center(width)
124
- .gradient(tc1, tc2, bold: bold)
130
+ date = time_now.strftime(date_format).center(width)
131
+ .gradient(tc1, tc2, bold: bold, italic: italic)
125
132
  end
126
133
 
127
- time = time_now.strftime('%H %M %S %2N').split.join(splitter)
134
+ time = time_now.strftime(time_format).split.join(splitter)
128
135
  art = Termclock::ParseCharacters.display(time).lines
129
136
 
130
137
  art_aligned = art.each_with_index do |x, i|
131
138
  chomped = x.chomp(''.freeze).+(NEWLINE)
132
- gr = chomped.gradient(*colours[i], bold: bold)
139
+ gr = chomped.gradient(*colours[i], bold: bold, italic: italic)
133
140
  x.replace(SPACE.*(width./(2.0).-(chomped.length / 2.0).abs.to_i + 1) + gr)
134
141
  end.join
135
142
 
@@ -3,7 +3,12 @@ class String
3
3
  SPACE = ?\s.freeze
4
4
  TAB = ?\t.freeze
5
5
 
6
- def gradient(*all_rgbs, bg: false, exclude_spaces: false, bold: false)
6
+ def gradient(*all_rgbs,
7
+ bg: false,
8
+ exclude_spaces: false,
9
+ bold: false, italic: false, blink: false
10
+ )
11
+
7
12
  temp = ''
8
13
 
9
14
  r, g, b = all_rgbs[0]
@@ -12,7 +17,18 @@ class String
12
17
 
13
18
  init = bg ? 48 : 38
14
19
 
20
+ style = nil
21
+ if bold || italic
22
+ style = "\e["
23
+ style << '1;'.freeze if bold
24
+ style << '3;'.freeze if italic
25
+ style.chop!
26
+ style << 'm'.freeze
27
+ end
28
+
15
29
  each_line do |c|
30
+ temp << style if style
31
+
16
32
  _r, _g, _b = r, g, b
17
33
  chomped = !!c.chomp!(''.freeze)
18
34
 
@@ -49,8 +65,6 @@ class String
49
65
  _g = _g.send(g_op, g_val * -1) if g_op
50
66
  _b = _b.send(b_op, b_val * -1) if b_op
51
67
 
52
- temp << "\e[1m" if bold
53
-
54
68
  i = -1
55
69
  while (i += 1) < len
56
70
  _c = c[i]
@@ -2,11 +2,11 @@ module Termclock
2
2
  @@cpu_usage = 0
3
3
  @@cpu_usage_t = Thread.new { }.join
4
4
 
5
- @@current_net_usage = ''
5
+ @@current_net_usage = "\u{1F4CA} Curr. DL/UL:"
6
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
@@ -57,17 +57,25 @@ module Termclock
57
57
  " / #{LS::PrettifyBytes.convert_short_binary(_m[:total].to_i)}"\
58
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 = "\u{1F427} Distrib: #{LS::OS.distribution} #{LS::OS.machine} (#{LS::OS.version})"
61
68
 
62
69
  max_l = [hostname, process, ip, battery, @@current_net_usage, net_usage].map(&:length).max + 4
63
70
 
64
- <<~EOF.gradient(tc1, tc2, exclude_spaces: true, bold: bold)
71
+ <<~STR
65
72
  \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
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
71
79
  end
72
80
  end
73
81
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Termclock
4
- VERSION = "0.1.6"
4
+ VERSION = "0.2.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.6
4
+ version: 0.2.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-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: linux_stat
@@ -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