termclock 0.1.5 → 0.1.6

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: 173194900216341c3b17b0628a2e559c48bc1ae0f96fb72fd9c6d0f7be8e72d7
4
- data.tar.gz: 62e24514caac359c68865c147bf95cd21bb5993b81c4793d52ed1270f125812f
3
+ metadata.gz: '0916f4a4beb06eae575611343e1235e5fa9a0585116fd9694622d1a5e9867938'
4
+ data.tar.gz: 53f9236790df604fe8eb5f0c1a4d0cb5ed0179c6aed3c04da4ae8b26398269ee
5
5
  SHA512:
6
- metadata.gz: 41b1e7640c8874a8c12448d248d76a5f27e75b920704281e5ec4ef82399e049118b7ef6c44389460de20c6096f331e863cbf6666661f126e63eb1ced9208ac78
7
- data.tar.gz: 90aa2e9ee036d1e02a2eb5dc98fed454663f053d906a7b45c7e8f0f30be95f0e80be73c2985abeeb2ad6f299e5f4479222ba16ac97a3a418127ee5551d7c3132
6
+ metadata.gz: f85098f0082eca3776b0349b65a34323491c8372cf2b426c91bedde2d5031be210da5fe49d36f773a95afdc9fc6907bbcc9b7e1e3d5e863624106d8e4112ac8f
7
+ data.tar.gz: a116f54e530fdfcecfc7f415812aa107bddd7e98409090acbd2f039aefccf0db937f47a8f441d5fa35b1fbe75974ff8795745d3a63da28187c85f275090fb24e
@@ -8,6 +8,7 @@ if ARGV.any? { |x| x[/\A\-(\-help|h)\z/] }
8
8
 
9
9
  Arguments:
10
10
  --help|-h\t\t\tShows this help section
11
+ --bold\t\t\t\tMake texts bold
11
12
  --character=|char=\t\tDraws specified character
12
13
  --clean\t\t\t\tJust run the clean bare clock
13
14
  --colour=|-c=\t\t\tSpecify hex colour (4 colours)
@@ -1,5 +1,14 @@
1
1
  require 'linux_stat'
2
2
  require 'io/console'
3
+
4
+ module Termclock
5
+ COLOURTERM = ENV.key?('COLORTERM')
6
+ CLEAR = COLOURTERM ? "\e[H\e[2J\e[3J" : "\e[H"
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"
@@ -1,15 +1,11 @@
1
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,
2
+ def self.start(colour1, colour2, colour3, colour4,
3
+ textcolour1 = nil, textcolour2 = nil,
4
+ sleep: 0.1,
5
+ bold: false,
7
6
  print_info: true, print_message: true,
8
7
  print_date: true
9
- )
10
-
11
- newline = ?\n.freeze
12
- space = ?\s.freeze
8
+ )
13
9
 
14
10
  generate = proc do |start, stop, n = 5|
15
11
  r_op = r_val = nil
@@ -132,9 +128,9 @@ module Termclock
132
128
  art = Termclock::ParseCharacters.display(time).lines
133
129
 
134
130
  art_aligned = art.each_with_index do |x, i|
135
- chomped = x.chomp(''.freeze).+(newline)
131
+ chomped = x.chomp(''.freeze).+(NEWLINE)
136
132
  gr = chomped.gradient(*colours[i], bold: bold)
137
- x.replace(space.*(width./(2.0).-(chomped.length / 2.0).abs.to_i + 1) + gr)
133
+ x.replace(SPACE.*(width./(2.0).-(chomped.length / 2.0).abs.to_i + 1) + gr)
138
134
  end.join
139
135
 
140
136
  vertical_gap = "\e[#{height./(2.0).-(art.length / 2.0).to_i + 1}H"
@@ -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
  ````````
@@ -293,7 +292,7 @@ module Termclock
293
292
 
294
293
  if stripped
295
294
  replace_with = x.chars.map { |y|
296
- chars = arg.chars.rotate(-1) if y == ?\n
295
+ chars = arg.chars.rotate(-1) if y == NEWLINE
297
296
  next(y) if y != stripped
298
297
  chars.rotate!(1)[0]
299
298
  }.join
@@ -1,4 +1,8 @@
1
1
  class String
2
+ NEWLINE = ?\n.freeze
3
+ SPACE = ?\s.freeze
4
+ TAB = ?\t.freeze
5
+
2
6
  def gradient(*all_rgbs, bg: false, exclude_spaces: false, bold: false)
3
7
  temp = ''
4
8
 
@@ -51,7 +55,7 @@ class String
51
55
  while (i += 1) < len
52
56
  _c = c[i]
53
57
 
54
- if !exclude_spaces || (exclude_spaces && !(_c == ?\s.freeze || _c == ?\t.freeze))
58
+ if !exclude_spaces || (exclude_spaces && !(_c == SPACE || _c == TAB))
55
59
  _r = _r.send(r_op, r_val) if r_op
56
60
  _g = _g.send(g_op, g_val) if g_op
57
61
  _b = _b.send(b_op, b_val) if b_op
@@ -72,7 +76,7 @@ class String
72
76
  ret = if !c.empty?
73
77
  chomped ? "\e[0m\n".freeze : "\e[0m".freeze
74
78
  elsif chomped
75
- ?\n.freeze
79
+ NEWLINE
76
80
  end
77
81
 
78
82
  temp << ret
@@ -1,9 +1,9 @@
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
5
  @@current_net_usage = ''
6
- @@current_net_usage_t = Thread.new { }
6
+ @@current_net_usage_t = Thread.new { }.join
7
7
 
8
8
  class << self
9
9
  def system_info(width, tc1, tc2, bold)
@@ -62,11 +62,11 @@ module Termclock
62
62
  max_l = [hostname, process, ip, battery, @@current_net_usage, net_usage].map(&:length).max + 4
63
63
 
64
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}
65
+ \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
70
  EOF
71
71
  end
72
72
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Termclock
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: termclock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sourav Goswami