termclock 0.2.1 → 0.3.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: d4c5e863a8c650bfda4aaa58bc010d8526692f47853f2ddae298cec606f4b410
4
- data.tar.gz: 3f3fef454b216911b4a7aaf860f5376e6c2b00b9aef1b72331afa9defba36b59
3
+ metadata.gz: ec9759a77ce797b7110a4d5427cf56ca1e7c7188558a84220d233b873d2db1b6
4
+ data.tar.gz: 6262c03faf908cdf536aa461181ed8564408e838f2df4a016da5f90817d25135
5
5
  SHA512:
6
- metadata.gz: b23b1136a704adc42a90d9cdae7f8de046bc63a19688cfb7bfb7b1b230c2b6f4a59a0088e8817707a6b9ba02d95f72b7764519965c429068a3e9e9981710406b
7
- data.tar.gz: 79c42cb8d83e1077073fcc94c29e19faec8ce67923095d32f6c0adcd8e8687a54c931911621b9ffb4d6a56f7eb7c28037af2ca879cee030ce5ed350c71ce207c
6
+ metadata.gz: be6ba479d498ea9155a16e950e8c5f6a240ec3556f3a5a0bccb7120ab48142f9084ea01c0c17c81c229172c9cbd2ac61fd8234063fe9c537d36e1e20ee23e524
7
+ data.tar.gz: 4d17f5be9b2d8b8c61800173c4fc7fb09294d10f17c2d69e35b78d24d1b1ffd758484525594a91bbf627052cfefe6bb0f96d02c9d304f0f94d7429a803abebd8
@@ -2,17 +2,32 @@
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
24
  \e[1;4mArguments:\e[0m
10
25
 
11
- 1. Help and Version:\e[0m
26
+ \e[1m1. Help and Version:\e[0m
12
27
  --help|-h\t\t\tShows this help section
13
28
  --version|-v\t\t\tShows termclock version
14
29
 
15
- 2. Style:\e[0m
30
+ \e[1m2. Style:\e[0m
16
31
  --bold|-b\t\t\tMake texts bold
17
32
  --italic|-i\t\t\tMake texts italic
18
33
  --character=|char=\t\tDraws specified character
@@ -20,22 +35,26 @@ if ARGV.any? { |x| x[/\A\-(\-help|h)\z/] }
20
35
  --colour=|-c=\t\t\tSpecify hex colour (4 colours)
21
36
  \t\t\t\t[ with or without # ]
22
37
 
23
- 3. Information:\e[0m
38
+ \e[1m3. Information:\e[0m
24
39
  --no-date|-nd\t\t\tShows no date
25
40
  --no-message|-nm\t\tShows no messages
26
41
  --no-sysinfo|-ni\t\tShows no system info
27
42
  --refresh|r\t\t\tSpecify delay or refresh time
28
43
  --text-colour|-tc\t\tSpecify text colour (2 colours)
44
+ --no-logo|-nl\t\t\tDon't show the logo at the bottom
29
45
 
30
- 4. Formats:\e[0m
46
+ \e[1m4. Formats:\e[0m
31
47
  --date-format=|-df=\t\tSpecify the date format
32
- \t\t\t\t[ Run date --help for formats ]
33
48
  --time-format=|-tf=\t\tSpecify the time format
34
- \t\t\t\t[ Run date --help for formats ]
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
35
54
 
36
55
  Supported characters are 0 - 9, a - z, /, \\, !, %, and |.
37
56
 
38
- This is Termclock v#{Termclock::VERSION}
57
+ #{version}
39
58
  EOF
40
59
 
41
60
  exit 0
@@ -50,7 +69,7 @@ if ARGV.any? { |x| x[/\A\-(-version|v)\z/] }
50
69
  ].sample
51
70
 
52
71
  colour.reverse! if rand < 0.5
53
- puts "This is Termclock v#{Termclock::VERSION}".gradient(*colour)
72
+ puts version
54
73
  exit 0
55
74
  end
56
75
 
@@ -93,13 +112,21 @@ begin
93
112
  italic = ARGV.any? { |x| x[/\A\-(\-italic|i)\z/] }
94
113
 
95
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/] }
96
116
  no_print_message = ARGV.any? { |x| x[/\A\-(\-no\-message|nm)\z/] }
97
117
  no_print_date = ARGV.any? { |x| x[/\A\-(\-no\-date|nd)\z/] }
98
118
 
99
119
  clean = ARGV.any? { |x| x[/\A\-(\-clean)\z/] }
100
120
 
101
121
  if clean
102
- 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}"
103
130
  end
104
131
 
105
132
  Termclock.start(
@@ -111,6 +138,7 @@ begin
111
138
  print_info: !no_print_info,
112
139
  print_message: !no_print_message,
113
140
  print_date: !no_print_date,
141
+ no_logo: no_logo,
114
142
  time_format: time_format,
115
143
  date_format: date_format
116
144
  )
@@ -1,9 +1,9 @@
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
+ CLEAR = "\e[H\e[2J\e[3J".freeze
7
7
  NEWLINE = ?\n.freeze
8
8
  SPACE = ?\s.freeze
9
9
  TAB = ?\t.freeze
@@ -14,4 +14,3 @@ require_relative "termclock/parse_characters"
14
14
  require_relative "termclock/system_info"
15
15
  require_relative "termclock/start"
16
16
  require_relative "termclock/hex2rgb"
17
- require_relative "termclock/version"
@@ -7,7 +7,8 @@ module Termclock
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
11
12
  )
12
13
 
13
14
  generate = proc do |start, stop, n = 5|
@@ -30,7 +31,7 @@ module Termclock
30
31
  end
31
32
 
32
33
  gc_compact, gc_compacted = GC.respond_to?(:compact), Time.now.to_i + 7200
33
- print "\e[H\e[2J\e[3J" unless COLOURTERM
34
+ print CLEAR
34
35
 
35
36
  r1, g1, b1 = *colour1
36
37
  r2, g2, b2 = *colour2
@@ -66,53 +67,100 @@ module Termclock
66
67
  message_counter = -1
67
68
  message = ''
68
69
  message_final = ''
70
+ message_align = 0
69
71
  message_temp = ''
72
+ point_five_tick = 0
70
73
 
71
74
  date, info = '', ''
72
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
+
73
81
  get_message = proc {
82
+ braille.rotate!
83
+ braille_0 = braille[0]
84
+
74
85
  case Time.now.hour
75
86
  when 5...12
76
- "\u{1F304} Good Morning..."
87
+ "\u{1F304} #{braille_0} Good Morning #{braille_0} \u{1F304}"
77
88
  when 12...16
78
- "\u26C5 Good Afternoon..."
89
+ "\u26C5 #{braille_0} Good Afternoon #{braille_0} \u26C5"
79
90
  when 16...18
80
- "\u{1F307} Good Evening..."
91
+ "\u{1F307} #{braille_0} Good Evening #{braille_0} \u{1F307}"
81
92
  when 18...20
82
- "\u{1F31F} Good Evening..."
93
+ "\u{1F31F} #{braille_0} Good Evening #{braille_0} \u{1F31F}"
83
94
  when 20...24
84
- "\u{1F303} Good Night..."
95
+ "\u{1F303} #{braille_0} Good Night #{braille_0} \u{1F303}"
85
96
  else
86
- "\u{2728} Good Night..."
97
+ "\u{2728} #{braille_0} Good Night #{braille_0} \u{2728}"
87
98
  end
88
99
  }
89
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
+
90
116
  while true
91
117
  time_now = Time.now
92
118
  height, width = *STDOUT.winsize
93
119
 
94
120
  if time_now.to_f./(0.5).to_i.even?
95
- splitter = ?:.freeze
121
+ unless point_five_tick == 1
122
+ point_five_tick = 1
123
+ splitter = ?:.freeze
124
+ clock_emoji.rotate!
125
+ end
96
126
  else
97
- splitter = ?$.freeze
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"
98
135
  end
99
136
 
100
137
  if print_message
138
+ message_temp = get_message.call
101
139
  message_counter += 1
102
- message_align = width - message_counter % width + message.length / 2 - 4
103
- if (width - message_counter % width <= message.length)
104
- message.replace(message[1..-1])
105
- message_align = width - message_counter % width + 4
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
106
149
  else
150
+ chop_message = 0 unless chop_message == 0
107
151
  message.clear if width - message_counter % width == width
108
- message_temp = get_message.call
152
+ message_align = width - message_counter % width + message_length - 4
109
153
 
110
154
  if message_temp != message
111
- message << message_temp[message.length..message.length + 1]
155
+ if message_length < message_temp.length
156
+ message.replace(message_temp[0..message_length])
157
+ else
158
+ message.replace(message_temp)
159
+ end
112
160
  end
113
161
  end
114
162
 
115
- message_final = message.rjust(message_align).gradient(
163
+ message_final = (message).rjust(message_align).gradient(
116
164
  tc1, tc2, exclude_spaces: true, bold: bold, italic: italic
117
165
  )
118
166
  end
@@ -139,7 +187,7 @@ module Termclock
139
187
 
140
188
  vertical_gap = "\e[#{height./(2.0).-(art.length / 2.0).to_i + 1}H"
141
189
 
142
- print "#{CLEAR}#{info}#{vertical_gap}#{art_aligned}\n#{date}\n\n#{message_final}"
190
+ print "#{CLEAR}#{info}#{vertical_gap}#{art_aligned}\n#{date}\n\n#{message_final}#{term_clock_v}"
143
191
 
144
192
  if gc_compact && time_now.to_i > gc_compacted
145
193
  GC.compact
@@ -6,7 +6,7 @@ class String
6
6
  def gradient(*all_rgbs,
7
7
  bg: false,
8
8
  exclude_spaces: false,
9
- bold: false, italic: false, blink: false
9
+ bold: false, italic: false, underline: false
10
10
  )
11
11
 
12
12
  temp = ''
@@ -18,10 +18,11 @@ class String
18
18
  init = bg ? 48 : 38
19
19
 
20
20
  style = nil
21
- if bold || italic
21
+ if bold || italic || underline
22
22
  style = "\e["
23
23
  style << '1;'.freeze if bold
24
24
  style << '3;'.freeze if italic
25
+ style << '4;'.freeze if underline
25
26
  style.chop!
26
27
  style << 'm'.freeze
27
28
  end
@@ -55,7 +55,7 @@ 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
60
  pt = LS::Process.types.values
61
61
 
@@ -64,7 +64,14 @@ module Termclock
64
64
  "S:#{sprintf "%3s", pt.count(:sleeping)}|"\
65
65
  "I:#{sprintf "%3s", pt.count(:idle)}"
66
66
 
67
- os = "\u{1F427} Distrib: #{LS::OS.distribution} #{LS::OS.machine} (#{LS::OS.version})"
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}"
68
75
 
69
76
  max_l = [hostname, process, ip, battery, @@current_net_usage, net_usage].map(&:length).max + 4
70
77
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Termclock
4
- VERSION = "0.2.1"
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.2.1
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-19 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