hackmac 1.9.0 → 1.10.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: a3965cb839d08ac229629f87ffe259ff8b0ac39a084b25ce2530b2a0eedfab10
4
- data.tar.gz: ff2e1a574431fc027ae09fabf3c31eb41b0c16df1f9f5825995cca48123c8b6e
3
+ metadata.gz: 5d8b91e07ca88dc28f574608697201338b76a9c33bce86c6c92e49bfea49716b
4
+ data.tar.gz: 38fbeec1739607ce09da13ce4f200a7c484479d0ed859bd5db2e8d4fb06b52ff
5
5
  SHA512:
6
- metadata.gz: '018e26bd422ca4405ff37e00719f1238251bb993dbd323cb34351cee6397f378ce3f4972596b26e3987f01ac5fa199f1e8381a2cb24f2fb6cfc29a87254830af'
7
- data.tar.gz: d805a9175d7667ff349883b55d120e1d78f0b039af493afd829906e2cc15ac65e0fc153df4eb1454c0d1745f20ce0f05eaa91246a9dcfbe21dec3089555309f6
6
+ metadata.gz: c2c4528dbf84320e01fdc90380bcb7eec65f38b28e885c499c2c7594eca0ddabe53a7ea70d47e983195d660936fb2c638f0203a2f23054b132e10dcf0c955395
7
+ data.tar.gz: 2499348bd0baa5d217a77f6c4959f2a78a6693e52d93975cf305713203dc4c647c9d9c286b0f2a01bab75f8694d298d8ecbdd165ca87e126ff984ea9037b6c97
data/CHANGES.md CHANGED
@@ -1,5 +1,53 @@
1
1
  # Changes
2
2
 
3
+ ## 2025-10-25 v1.10.0
4
+
5
+ - Added `-C` command line option to specify secondary color for terminal
6
+ graphs, accepting color values between **0** - **255**
7
+ - Updated `Hackmac::Graph.new` call to include `color_secondary:` parameter
8
+ - Modified `usage` method to document the new `-C` option
9
+ - Maintained backward compatibility with existing `-c` color option
10
+ - Added support for `color_secondary`, `adjust_brightness`, and `adjust_brightness_percentage` parameters in `Hackmac::Graph#initialize`
11
+ - Introduced `pick_secondary_color` method to calculate secondary colors based on brightness adjustments
12
+ - Updated `draw_graph` to use secondary colors for improved visual contrast
13
+ - Modified `Hackmac::Graph::Display#initialize` to accept `color` and `on_color` parameters
14
+ - Configured `@display` and `@old_display` with default color settings in `Hackmac::Graph#reset_display`
15
+ - Default `adjust_brightness` to **:lighten** with **15%** brightness adjustment
16
+ - Default `foreground_color` to **:white** and `background_color` to **:black**
17
+ - Added conditional check `if @plist` before extending with `Hashie::Extensions::DeepFind` to prevent `NoMethodError` when `@plist` is nil or undefined
18
+
19
+ ## 2025-10-25 v1.9.1
20
+
21
+ - Addresses display issues in tmux panes where background colors bled through
22
+ due to changed character rendering
23
+ - Updated `ps` method to return an empty hash `{}` instead of raising an error
24
+ when `PerformanceStatistics` key doesn't exist in IORegistry
25
+ - Added `exist?` method to the `Hackmac` module to check if plist data is
26
+ loaded, returning `@plist` instance variable or `nil` if no data is available
27
+ - Ensured the returned value is always a hash in the `ps` method
28
+ - Modified `ps` method to handle nil values from `ps[metric]` by defaulting to
29
+ **0** to prevent potential errors when metric data is missing from the
30
+ process snapshot
31
+
32
+ ## 2025-10-23 v1.9.0
33
+
34
+ - Added `draw_graph` method to render data using Unicode block characters (`▀`)
35
+ - Introduced `data_range` helper to calculate data value range as `Float`
36
+ - Refactored `start_loop` to use `draw_graph` instead of inline rendering logic
37
+ - Moved color calculation and `y_width` logic into `draw_graph` method
38
+ - Replaced direct graph drawing in `start_loop` with call to `draw_graph`
39
+ - Implemented `data_range.zero?` check to handle flat data scenarios
40
+ - Added fractional pixel blending for visual appeal
41
+ - Used `color.to_rgb_triple.to_hsl_triple.lighten(15)` for background shading
42
+ - Added fallback handling for color conversion errors with `rescue color`
43
+ - Supported terminal graphics with 2px vertical resolution using Unicode characters
44
+ - Updated `@display.at(iy, x)` calls with color styling for graph rendering
45
+ - Removed duplicate `pick_color` method
46
+ - Added YARD documentation for `Hackmac::Config::DEFAULT`, `Hackmac::GithubSource::GITHUB_API_URL`, and `Hackmac::Graph::Display::ANSI` constants
47
+ - Updated module documentation with project description and features
48
+ - Refactored Graph formatters into separate `Hackmac::Graph::Formatters` module
49
+ - Refactored `Hackmac::Graph::Display::Cell` class into separate file `lib/hackmac/graph/display/cell.rb`
50
+
3
51
  ## 2025-10-15 v1.8.8
4
52
 
5
53
  ### Features
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.9.0
1
+ 1.10.0
data/bin/gfxmon CHANGED
@@ -19,8 +19,6 @@
19
19
  # gfxmon -n 3 # Update every 3 seconds
20
20
  # gfxmon -m "Temperature(C)" # Show specific metric
21
21
 
22
- require 'tins'
23
- include Tins::GO
24
22
  require 'term/ansicolor'
25
23
  Term::ANSIColor.true_coloring = ENV['COLORTERM'] =~ /\A(truecolor|24bit)\z/
26
24
  include Term::ANSIColor
@@ -29,11 +27,12 @@ class String
29
27
  end
30
28
  require 'hackmac'
31
29
  include Hackmac
30
+ include Tins::GO
32
31
  require 'amatch'
33
32
  require 'search_ui'
34
33
  include SearchUI
35
34
 
36
- $opts = go 'c:m:n:jlh', defaults: { ?s => true, ?n => 5 }
35
+ $opts = go 'c:C:m:n:jlh', defaults: { ?s => true, ?n => 5 }
37
36
 
38
37
  # The usage method displays command-line usage information and options
39
38
  #
@@ -54,6 +53,7 @@ def usage
54
53
  -n SECONDS measure every SECONDS
55
54
  -m METRIC output graph for performance METRIC
56
55
  -c COLOR output graph in this terminal COLOR (between 0 - 255)
56
+ -C COLOR output graph using secondary color COLOR
57
57
 
58
58
  EOT
59
59
  0
@@ -67,7 +67,12 @@ end
67
67
  # @return [ Hash ] a hash containing the performance statistics data from the
68
68
  # IORegistry
69
69
  def ps
70
- Hackmac::IOReg.new(key: 'PerformanceStatistics').as_hash
70
+ ioreg = Hackmac::IOReg.new(key: 'PerformanceStatistics')
71
+ if ioreg.exist?
72
+ ioreg.as_hash
73
+ else
74
+ {}
75
+ end
71
76
  end
72
77
 
73
78
  # The list method displays a formatted key-value pair listing with colored
@@ -172,10 +177,11 @@ def display_graph
172
177
  sleep_duration = [ 1, ($opts[?n] || 10).to_i ].max
173
178
  format_value = derive_formatter(metric)
174
179
  graph = Hackmac::Graph.new(
175
- title: metric,
176
- sleep: sleep_duration,
177
- value: -> _ { ps[metric] },
178
- color: $opts[?c],
180
+ title: metric,
181
+ sleep: sleep_duration,
182
+ value: -> _ { ps[metric] || 0 },
183
+ color: $opts[?c],
184
+ color_secondary: $opts[?C],
179
185
  format_value:
180
186
  )
181
187
  graph.start
data/hackmac.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: hackmac 1.9.0 ruby lib
2
+ # stub: hackmac 1.10.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "hackmac".freeze
6
- s.version = "1.9.0".freeze
6
+ s.version = "1.10.0".freeze
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
@@ -27,9 +27,13 @@ class Hackmac::Graph
27
27
  # @param lines [ Integer ] the number of lines (rows) in the display grid
28
28
  # @param columns [ Integer ] the number of columns (characters per line) in
29
29
  # the display grid
30
- def initialize(lines, columns)
30
+ # @param color [ Symbol ] the default text color for the display
31
+ # @param on_color [ Symbol ] the default background color for the display
32
+ def initialize(lines, columns, color: :white, on_color: :black)
31
33
  @lines_range = 1..lines
32
34
  @columns_range = 1..columns
35
+ @orig_color = color
36
+ @orig_on_color = on_color
33
37
  clear
34
38
  end
35
39
 
@@ -42,13 +46,16 @@ class Hackmac::Graph
42
46
  # array of Cell objects that represent the display grid, filling each cell
43
47
  # with a space character and default styling attributes
44
48
  #
49
+ # @param color [ Symbol ] the default text color for the display
50
+ # @param on_color [ Symbol ] the default background color for the display
51
+ #
45
52
  # @return [ Hackmac::Graph::Display ] returns the Display instance to allow
46
53
  # for method chaining
47
54
  def clear
48
55
  @x = 1
49
56
  @y = 1
50
- @color = 15
51
- @on_color = 0
57
+ @color = @orig_color
58
+ @on_color = @orig_on_color
52
59
  @styles = []
53
60
  @cells =
54
61
  Array.new(lines) {
@@ -70,8 +77,8 @@ class Hackmac::Graph
70
77
  # @return [ Hackmac::Graph::Display ] returns the Display instance to allow
71
78
  # for method chaining
72
79
  def reset
73
- @color = 15
74
- @on_color = 0
80
+ @color = @orig_color
81
+ @on_color = @orig_on_color
75
82
  @styles = []
76
83
  self
77
84
  end
data/lib/hackmac/graph.rb CHANGED
@@ -41,7 +41,7 @@ class Hackmac::Graph
41
41
  include Hackmac::Graph::Formatters
42
42
 
43
43
  # The initialize method sets up a Graph instance by configuring its display
44
- # parameters and internal state
44
+ # parameters and internal state.
45
45
  #
46
46
  # This method configures the graph visualization with title, value provider,
47
47
  # formatting options, update interval, and color settings. It initializes
@@ -49,28 +49,50 @@ class Hackmac::Graph
49
49
  # synchronization through a mutex for thread-safe operations.
50
50
  #
51
51
  # @param title [ String ] the title to display at the bottom of the graph
52
- # @param value [ Proc ] a proc that takes an index and returns a numeric value for plotting
53
- # @param format_value [ Proc, Symbol, nil ] formatting strategy for displaying values
52
+ # @param value [ Proc ] a proc that takes an index and returns a numeric
53
+ # value for plotting
54
+ # @param format_value [ Proc, Symbol, nil ] formatting strategy for
55
+ # displaying values
54
56
  # @param sleep [ Numeric ] time in seconds between updates
55
- # @param color [ Integer, Proc, nil ] color index or proc to determine color dynamically
57
+ # @param color [ Integer, Proc, nil ] color index or proc to determine color
58
+ # dynamically
59
+ # @param color_secondary [ Integer, Proc, nil ] secondary color index or proc
60
+ # for enhanced visuals
61
+ # @param adjust_brightness [ Symbol ] the method to call on the color for
62
+ # brightness adjustment
63
+ # @param adjust_brightness_percentage [ Integer ] the percentage value to use
64
+ # for the brightness adjustment
65
+ # @param foreground_color [ Symbol ] the default text color for the display
66
+ # @param background_color [ Symbol ] the default background color for the
67
+ # display
56
68
  #
57
69
  # @raise [ ArgumentError ] if the sleep parameter is negative
58
70
  def initialize(
59
71
  title:,
60
- value: -> i { 0 },
61
- format_value: nil,
62
- sleep: nil,
63
- color: nil
72
+ value: -> i { 0 },
73
+ format_value: nil,
74
+ sleep: nil,
75
+ color: nil,
76
+ color_secondary: nil,
77
+ adjust_brightness: :lighten,
78
+ adjust_brightness_percentage: 15,
79
+ foreground_color: :white,
80
+ background_color: :black
64
81
  )
65
82
  sleep >= 0 or raise ArgumentError, 'sleep has to be >= 0'
66
- @title = title
67
- @value = value
68
- @format_value = format_value
69
- @sleep = sleep
70
- @continue = false
71
- @data = []
72
- @color = color
73
- @mutex = Mutex.new
83
+ @title = title
84
+ @value = value
85
+ @format_value = format_value
86
+ @sleep = sleep
87
+ @continue = false
88
+ @data = []
89
+ @color = color
90
+ @color_secondary = color_secondary
91
+ @adjust_brightness = adjust_brightness
92
+ @adjust_brightness_percentage = adjust_brightness_percentage
93
+ @foreground_color = foreground_color
94
+ @background_color = background_color
95
+ @mutex = Mutex.new
74
96
  end
75
97
 
76
98
  # The start method initiates the graphical display process by setting up
@@ -108,23 +130,27 @@ class Hackmac::Graph
108
130
  # to achieve 2px vertical resolution in terminal graphics. Each data point is
109
131
  # plotted with appropriate color blending for visual appeal.
110
132
  def draw_graph
111
- y_width = data_range
112
- color = pick_color
113
- color_light = color.to_rgb_triple.to_hsl_triple.lighten(15) rescue color
133
+ y_width = data_range
134
+ color = pick_color
135
+ color_secondary = pick_secondary_color(
136
+ color,
137
+ adjust_brightness: @adjust_brightness,
138
+ adjust_brightness_percentage: @adjust_brightness_percentage
139
+ )
114
140
  data.each_with_index do |value, i|
115
141
  x = 1 + i + columns - data.size
116
142
  y0 = ((value - data.min) * lines / y_width.to_f)
117
143
  y = lines - y0.round + 1
118
144
  y.upto(lines) do |iy|
119
145
  if iy > y
120
- @display.at(iy, x).on_color(color_light).write(' ')
146
+ @display.at(iy, x).on_color(color_secondary).write(' ')
121
147
  else
122
148
  fract = 1 - (y0 - y0.floor).abs
123
149
  case
124
150
  when (0...0.5) === fract
125
- @display.at(iy, x).color(0).on_color(color).write(?▀)
151
+ @display.at(iy, x).on_color(0).color(color).write(?▄)
126
152
  else
127
- @display.at(iy, x).color(color).on_color(color_light).write(?▀)
153
+ @display.at(iy, x).on_color(color).color(color_secondary).write(?▄)
128
154
  end
129
155
  end
130
156
  end
@@ -277,6 +303,25 @@ class Hackmac::Graph
277
303
  ]
278
304
  end
279
305
 
306
+ # The pick_secondary_color method determines a secondary color based on a
307
+ # primary color and brightness adjustment parameters It returns the
308
+ # pre-configured secondary color if one exists, otherwise
309
+ # calculates a new color by adjusting the brightness of the primary color
310
+ #
311
+ # @param color [ Term::ANSIColor::Attribute ] the primary color attribute to
312
+ # be used as a base for calculation
313
+ # @param adjust_brightness [ Symbol ] the method to call on the color for
314
+ # brightness adjustment
315
+ # @param adjust_brightness_percentage [ Integer ] the percentage value to use
316
+ # for the brightness adjustment
317
+ # @return [ Term::ANSIColor::Attribute ] the secondary color attribute,
318
+ # either pre-configured or calculated from the primary color
319
+ def pick_secondary_color(color, adjust_brightness:, adjust_brightness_percentage:)
320
+ @color_secondary and return @color_secondary
321
+ color_primary = color.to_rgb_triple.to_hsl_triple
322
+ color_primary.send(adjust_brightness, adjust_brightness_percentage) rescue color
323
+ end
324
+
280
325
  # The sleep_now method calculates and executes a sleep duration based on the
281
326
  # configured sleep time and elapsed time since start
282
327
  #
@@ -365,8 +410,12 @@ class Hackmac::Graph
365
410
  @mutex.synchronize do
366
411
  perform reset, clear_screen, move_home, show_cursor
367
412
  winsize = Tins::Terminal.winsize
368
- @display = Hackmac::Graph::Display.new(*winsize)
369
- @old_display = Hackmac::Graph::Display.new(*winsize)
413
+ opts = {
414
+ color: @foreground_color,
415
+ on_color: @background_color,
416
+ }
417
+ @display = Hackmac::Graph::Display.new(*winsize, **opts)
418
+ @old_display = Hackmac::Graph::Display.new(*winsize, **opts)
370
419
  perform @display
371
420
  @full_reset = false
372
421
  end
data/lib/hackmac/ioreg.rb CHANGED
@@ -28,8 +28,10 @@ module Hackmac
28
28
  # IOService tree
29
29
  def initialize(key:)
30
30
  plist(*(%w[ioreg -a -p IOService -r -k ] << key))
31
- @plist.extend Hashie::Extensions::DeepFind
32
- @plist = @plist.deep_find_all(key).max_by(&:size)
31
+ if @plist
32
+ @plist.extend Hashie::Extensions::DeepFind
33
+ @plist = @plist.deep_find_all(key).max_by(&:size)
34
+ end
33
35
  end
34
36
  end
35
37
  end
data/lib/hackmac/plist.rb CHANGED
@@ -32,6 +32,17 @@ module Hackmac
32
32
  @plist = ::Plist.parse_xml(`#{Shellwords.join(cmd)}`)
33
33
  end
34
34
 
35
+ # The exist? method checks whether plist data has been loaded
36
+ #
37
+ # This method returns a truthy value if plist data has been successfully
38
+ # parsed and stored in the instance variable, or nil if no plist data is
39
+ # available.
40
+ #
41
+ # @return [ Object, nil ] returns the plist data if present, nil otherwise
42
+ def exist?
43
+ @plist
44
+ end
45
+
35
46
  # Returns a duplicate of the internal plist hash
36
47
  #
37
48
  # This method provides access to the parsed plist data by returning a shallow copy
@@ -40,7 +51,7 @@ module Hackmac
40
51
  #
41
52
  # @return [ Hash ] a duplicate of the plist hash containing the parsed XML data
42
53
  def as_hash(*a)
43
- @plist.dup
54
+ @plist.dup.to_h
44
55
  end
45
56
 
46
57
  # The each method iterates over the parsed plist data
@@ -1,6 +1,6 @@
1
1
  module Hackmac
2
2
  # Hackmac version
3
- VERSION = '1.9.0'
3
+ VERSION = '1.10.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hackmac
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank