hackmac 1.9.1 → 1.11.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: 6a8737823bd35d4307645c94d45e0232b29e9bd174a173959d083bddf20635e8
4
- data.tar.gz: eb8e1c697851e2c55b48dd568f222e9b6355c6d3ca957456239b0721999b8351
3
+ metadata.gz: f08f36e8e85de7ebec84d0e2f98334ae3f644ef48411852c0299c6b439d19702
4
+ data.tar.gz: f2659f7f42f980013730bf9efc6830ee98c3a99d7d1f3a92da5d3505aabf7312
5
5
  SHA512:
6
- metadata.gz: bb1c5bee6a66eaba86b7cf8bc085bd46c46b19aca8e87590f2e8741d3c41d24f8b18a8d539473cc0f2ce359a79d58ad9456f1b68a2ba803b1c4ce07cacd031c3
7
- data.tar.gz: a17a0d413c60c1dfd82535c4a179902f80fb4f5e860e46fb60750d89b139694d962b2af07fbe8d1986a331701e16929b91a0586283fa521d6a0a6a4c00094dc4
6
+ metadata.gz: 8fbb05e777bcf29ef66888ee69eb84bbdcc6f741400038e80b20eeff98d54bc6b41e8ab5360619535ac82f3ad58e06568cfb6fae879576c7d00a6e839a9f95f4
7
+ data.tar.gz: 143eda42ce454475b6d1f3e3a4a1e0fca43b220ddab12ad029d3a916261913ce4731da9c5ad48bde29de814b4a44a925764ead523b8b12c1d27f54638acf4056
data/CHANGES.md CHANGED
@@ -1,5 +1,55 @@
1
1
  # Changes
2
2
 
3
+ ## 2025-10-26 v1.11.0
4
+
5
+ - Reduced minimum sleep duration in gfxmon from **1** second to **0.01**
6
+ seconds
7
+ - Changed sleep duration calculation in gfxmon to use `.to_f` instead of
8
+ `.to_i` for sub-second precision
9
+ - Updated `Hackmac::Graph` parameter handling:
10
+ - Clarified documentation for `color` and `color_secondary` parameters to
11
+ indicate `nil` values derive colors from the title
12
+ - Set default value for `sleep` parameter to **5** seconds
13
+ - Added `@raise [TypeError]` documentation for `sleep` parameter
14
+ - Converted `sleep` parameter to `Float` and validated it's non-negative
15
+ - Added validation and normalization for graph constructor parameters:
16
+ - Validated `adjust_brightness` to be either `:lighten` or `:darken`
17
+ - Converted `adjust_brightness` to symbol using `to_sym`
18
+ - Ensured `adjust_brightness_percentage` is a `Float`
19
+ - Fixed typo in error message for `resolution` parameter
20
+ - Added `-f` and `-b` command-line options to `gfxmon` for foreground and
21
+ background colors
22
+ - Default foreground color is `:white` and background color is `:black`
23
+ - Updated `Hackmac::Graph` class to accept `foreground_color` and
24
+ `background_color` parameters
25
+ - Modified rendering logic to use `@background_color` instead of hardcoded
26
+ `0` for background color
27
+ - Updated help text to document the new `-f` and `-b` options
28
+ - Added `-r` command-line option to `gfxmon` with values `single` or `double`
29
+ - Default resolution is `:double`
30
+ - Updated `Hackmac::Graph` class to accept and validate `resolution`
31
+ parameter
32
+ - Used spaces (`' '`) for `:single` resolution to display lower resolution
33
+ - Added `ArgumentError` validation for invalid resolution values
34
+ - Updated help text to document the new `-r` option
35
+ - Removed redundant `@return` tags from documentation
36
+
37
+ ## 2025-10-25 v1.10.0
38
+
39
+ - Added `-C` command line option to specify secondary color for terminal
40
+ graphs, accepting color values between **0** - **255**
41
+ - Updated `Hackmac::Graph.new` call to include `color_secondary:` parameter
42
+ - Modified `usage` method to document the new `-C` option
43
+ - Maintained backward compatibility with existing `-c` color option
44
+ - Added support for `color_secondary`, `adjust_brightness`, and `adjust_brightness_percentage` parameters in `Hackmac::Graph#initialize`
45
+ - Introduced `pick_secondary_color` method to calculate secondary colors based on brightness adjustments
46
+ - Updated `draw_graph` to use secondary colors for improved visual contrast
47
+ - Modified `Hackmac::Graph::Display#initialize` to accept `color` and `on_color` parameters
48
+ - Configured `@display` and `@old_display` with default color settings in `Hackmac::Graph#reset_display`
49
+ - Default `adjust_brightness` to **:lighten** with **15%** brightness adjustment
50
+ - Default `foreground_color` to **:white** and `background_color` to **:black**
51
+ - Added conditional check `if @plist` before extending with `Hashie::Extensions::DeepFind` to prevent `NoMethodError` when `@plist` is nil or undefined
52
+
3
53
  ## 2025-10-25 v1.9.1
4
54
 
5
55
  - Addresses display issues in tmux panes where background colors bled through
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.9.1
1
+ 1.11.0
data/bin/gfxmon CHANGED
@@ -32,7 +32,13 @@ require 'amatch'
32
32
  require 'search_ui'
33
33
  include SearchUI
34
34
 
35
- $opts = go 'c:m:n:jlh', defaults: { ?s => true, ?n => 5 }
35
+ $opts = go 'c:C:m:n:f:b:r:jlh', defaults: {
36
+ ?s => true,
37
+ ?n => 5,
38
+ ?r => :double,
39
+ ?f => :white,
40
+ ?b => :black,
41
+ }
36
42
 
37
43
  # The usage method displays command-line usage information and options
38
44
  #
@@ -47,12 +53,16 @@ def usage
47
53
 
48
54
  OPTIONS are
49
55
 
50
- -h this help
51
- -l output GPU performance data as list
52
- -j output GPU performance data as json
53
- -n SECONDS measure every SECONDS
54
- -m METRIC output graph for performance METRIC
55
- -c COLOR output graph in this terminal COLOR (between 0 - 255)
56
+ -h this help
57
+ -l output GPU performance data as list
58
+ -j output GPU performance data as json
59
+ -n SECONDS measure every SECONDS
60
+ -m METRIC output graph for performance METRIC
61
+ -c COLOR output graph in this terminal COLOR (between 0 - 255)
62
+ -C COLOR output graph using secondary color COLOR
63
+ -f COLOR foreground color (used for text)
64
+ -b COLOR background color (used for background)
65
+ -r RESOLUTION is either single or double (uses half blocks)
56
66
 
57
67
  EOT
58
68
  0
@@ -173,13 +183,17 @@ end
173
183
  # @see derive_formatter
174
184
  def display_graph
175
185
  if metric = choose_metric(ps)
176
- sleep_duration = [ 1, ($opts[?n] || 10).to_i ].max
186
+ sleep_duration = [ 0.01, ($opts[?n] || 10).to_f ].max
177
187
  format_value = derive_formatter(metric)
178
188
  graph = Hackmac::Graph.new(
179
- title: metric,
180
- sleep: sleep_duration,
181
- value: -> _ { ps[metric] || 0 },
182
- color: $opts[?c],
189
+ title: metric,
190
+ sleep: sleep_duration,
191
+ value: -> _ { ps[metric] || 0 },
192
+ color: $opts[?c],
193
+ color_secondary: $opts[?C],
194
+ foreground_color: $opts[?f],
195
+ background_color: $opts[?b],
196
+ resolution: $opts[?r],
183
197
  format_value:
184
198
  )
185
199
  graph.start
data/hackmac.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: hackmac 1.9.1 ruby lib
2
+ # stub: hackmac 1.11.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "hackmac".freeze
6
- s.version = "1.9.1".freeze
6
+ s.version = "1.11.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]
@@ -48,8 +48,6 @@ module Hackmac
48
48
  #
49
49
  # @param name [ String ] the path to the compressed file to be decompressed
50
50
  #
51
- # @return [ void ] Returns nothing, but performs system decompression operations
52
- #
53
51
  # @raise [ RuntimeError ] raised when the file extension is not supported or
54
52
  # decompression commands fail
55
53
  def decompress(name)
@@ -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
@@ -40,8 +40,7 @@ class Hackmac::Graph
40
40
  include Term::ANSIColor
41
41
  include Hackmac::Graph::Formatters
42
42
 
43
- # The initialize method sets up a Graph instance by configuring its display
44
- # parameters and internal state
43
+ # The initialize method sets up a Graph instance by configuring its display parameters and internal state.
45
44
  #
46
45
  # This method configures the graph visualization with title, value provider,
47
46
  # formatting options, update interval, and color settings. It initializes
@@ -49,28 +48,67 @@ class Hackmac::Graph
49
48
  # synchronization through a mutex for thread-safe operations.
50
49
  #
51
50
  # @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
51
+ # @param value [ Proc ] a proc that takes an index and returns a numeric
52
+ # value for plotting
53
+ # @param format_value [ Proc, Symbol, nil ] formatting strategy for
54
+ # displaying values
54
55
  # @param sleep [ Numeric ] time in seconds between updates
55
- # @param color [ Integer, Proc, nil ] color index or proc to determine color dynamically
56
+ # @param color [ Object, Proc, nil ] color or proc or nil. nil
57
+ # determineicolor dynamically from the title
58
+ # @param color_secondary [ Object, nil ] secondary color or nil
59
+ # for enhanced visuals, nil derives secondary color from (primary) color
60
+ # @param adjust_brightness [ Symbol ] the method to call on the color for
61
+ # brightness adjustment (:lighten or :darken), defaults to :lighten
62
+ # @param adjust_brightness_percentage [ Float ] the percentage value to use
63
+ # for the brightness adjustment
64
+ # @param foreground_color [ Symbol ] the default text color for the display
65
+ # @param background_color [ Symbol ] the default background color for the
66
+ # display
67
+ # @param resolution [ Symbol ] the resolution mode (:single or :double) for
68
+ # the graph display, defaults to :double.
56
69
  #
57
70
  # @raise [ ArgumentError ] if the sleep parameter is negative
71
+ # @raise [ TypeError ] if the sleep parameter is not numeric
72
+ # @raise [ ArgumentError ] if the resolution parameter is not :single or :double
58
73
  def initialize(
59
74
  title:,
60
- value: -> i { 0 },
61
- format_value: nil,
62
- sleep: nil,
63
- color: nil
75
+ value: -> i { 0 },
76
+ format_value: nil,
77
+ sleep: 5,
78
+ color: nil,
79
+ color_secondary: nil,
80
+ adjust_brightness: :lighten,
81
+ adjust_brightness_percentage: 15,
82
+ foreground_color: :white,
83
+ background_color: :black,
84
+ resolution: :double
64
85
  )
86
+ @title = title
87
+ @value = value
88
+ @format_value = format_value
89
+ sleep = Float(sleep)
65
90
  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
91
+ @sleep = sleep
92
+ @continue = false
93
+ @data = []
94
+ @color = color
95
+ @color_secondary = color_secondary
96
+ adjust_brightness = adjust_brightness.to_sym
97
+ if %i[ lighten darken ].include? adjust_brightness
98
+ @adjust_brightness = adjust_brightness
99
+ else
100
+ raise ArgumentError, 'adjust_brightness required to be either :lighten or :darken'
101
+ end
102
+ @adjust_brightness_percentage = Float(adjust_brightness_percentage)
103
+ @foreground_color = foreground_color
104
+ @background_color = background_color
105
+ resolution = resolution.to_sym
106
+ if %i[ single double ].include? resolution
107
+ @resolution = resolution
108
+ else
109
+ raise ArgumentError, 'resolution required to be either :single or :double'
110
+ end
111
+ @mutex = Mutex.new
74
112
  end
75
113
 
76
114
  # The start method initiates the graphical display process by setting up
@@ -108,23 +146,32 @@ class Hackmac::Graph
108
146
  # to achieve 2px vertical resolution in terminal graphics. Each data point is
109
147
  # plotted with appropriate color blending for visual appeal.
110
148
  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
149
+ y_width = data_range
150
+ color = pick_color
151
+ color_secondary = pick_secondary_color(
152
+ color,
153
+ adjust_brightness: @adjust_brightness,
154
+ adjust_brightness_percentage: @adjust_brightness_percentage
155
+ )
114
156
  data.each_with_index do |value, i|
115
157
  x = 1 + i + columns - data.size
116
158
  y0 = ((value - data.min) * lines / y_width.to_f)
117
159
  y = lines - y0.round + 1
118
160
  y.upto(lines) do |iy|
119
161
  if iy > y
120
- @display.at(iy, x).on_color(color_light).write(' ')
162
+ @display.at(iy, x).on_color(color_secondary).write(' ')
121
163
  else
122
- fract = 1 - (y0 - y0.floor).abs
123
- case
124
- when (0...0.5) === fract
125
- @display.at(iy, x).on_color(0).color(color).write(?▄)
164
+ case @resolution
165
+ when :double
166
+ fract = 1 - (y0 - y0.floor).abs
167
+ case
168
+ when (0...0.5) === fract
169
+ @display.at(iy, x).on_color(@background_color).color(color).write(?▄)
170
+ else
171
+ @display.at(iy, x).on_color(color).color(color_secondary).write(?▄)
172
+ end
126
173
  else
127
- @display.at(iy, x).on_color(color).color(color_light).write(?▄)
174
+ @display.at(iy, x).on_color(color).color(color_secondary).write(' ')
128
175
  end
129
176
  end
130
177
  end
@@ -277,6 +324,25 @@ class Hackmac::Graph
277
324
  ]
278
325
  end
279
326
 
327
+ # The pick_secondary_color method determines a secondary color based on a
328
+ # primary color and brightness adjustment parameters It returns the
329
+ # pre-configured secondary color if one exists, otherwise
330
+ # calculates a new color by adjusting the brightness of the primary color
331
+ #
332
+ # @param color [ Term::ANSIColor::Attribute ] the primary color attribute to
333
+ # be used as a base for calculation
334
+ # @param adjust_brightness [ Symbol ] the method to call on the color for
335
+ # brightness adjustment
336
+ # @param adjust_brightness_percentage [ Integer ] the percentage value to use
337
+ # for the brightness adjustment
338
+ # @return [ Term::ANSIColor::Attribute ] the secondary color attribute,
339
+ # either pre-configured or calculated from the primary color
340
+ def pick_secondary_color(color, adjust_brightness:, adjust_brightness_percentage:)
341
+ @color_secondary and return @color_secondary
342
+ color_primary = color.to_rgb_triple.to_hsl_triple
343
+ color_primary.send(adjust_brightness, adjust_brightness_percentage) rescue color
344
+ end
345
+
280
346
  # The sleep_now method calculates and executes a sleep duration based on the
281
347
  # configured sleep time and elapsed time since start
282
348
  #
@@ -307,9 +373,6 @@ class Hackmac::Graph
307
373
  # When the DEBUG_BYTESIZE environment variable is set, it also outputs
308
374
  # debugging information about the size of the diff and the time elapsed since
309
375
  # the last debug output
310
- #
311
- # @return [ void ] Returns nothing but performs terminal output operations
312
- # and updates internal display state
313
376
  def perform_display_diff
314
377
  @mutex.synchronize do
315
378
  unless @old_display && @old_display.dimensions == @display.dimensions
@@ -365,8 +428,12 @@ class Hackmac::Graph
365
428
  @mutex.synchronize do
366
429
  perform reset, clear_screen, move_home, show_cursor
367
430
  winsize = Tins::Terminal.winsize
368
- @display = Hackmac::Graph::Display.new(*winsize)
369
- @old_display = Hackmac::Graph::Display.new(*winsize)
431
+ opts = {
432
+ color: @foreground_color,
433
+ on_color: @background_color,
434
+ }
435
+ @display = Hackmac::Graph::Display.new(*winsize, **opts)
436
+ @old_display = Hackmac::Graph::Display.new(*winsize, **opts)
370
437
  perform @display
371
438
  @full_reset = false
372
439
  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
@@ -47,8 +47,6 @@ module Hackmac
47
47
  # installation paths, and performing the actual file replacement after user
48
48
  # confirmation
49
49
  #
50
- # @return [ void ] Returns nothing but performs file system operations and
51
- # user interaction
52
50
  # @raise [ RuntimeError ] raised when a remote download fails or when no
53
51
  # source is defined for the kext
54
52
  def perform
@@ -28,8 +28,6 @@ module Hackmac
28
28
  #
29
29
  # @param mdev [ String ] the mount device identifier for the EFI partition
30
30
  # @param config [ Object ] the configuration object containing OpenCore settings including the EFI path
31
- #
32
- # @return [ void ] Returns nothing but initializes instance variables for the upgrade process
33
31
  def initialize(mdev:, config:)
34
32
  @config = config
35
33
  mount_path = Pathname.new('/Volumes').join(mdev)
@@ -45,8 +43,6 @@ module Hackmac
45
43
  # operations to replace existing EFI files after ensuring
46
44
  # the installation directory is properly configured
47
45
  #
48
- # @return [ void ] Returns nothing but performs file system operations and
49
- # user interaction
50
46
  # @raise [ RuntimeError ] raised when a remote download fails or when no
51
47
  # source is defined for the OpenCore upgrade
52
48
  def perform
data/lib/hackmac/plist.rb CHANGED
@@ -26,8 +26,6 @@ module Hackmac
26
26
  # \@plist instance variable for later access through other methods.
27
27
  #
28
28
  # @param cmd [Array<String>] command and arguments to execute
29
- #
30
- # @return [void] Returns nothing, but sets the @plist instance variable
31
29
  def plist(*cmd)
32
30
  @plist = ::Plist.parse_xml(`#{Shellwords.join(cmd)}`)
33
31
  end
@@ -1,6 +1,6 @@
1
1
  module Hackmac
2
2
  # Hackmac version
3
- VERSION = '1.9.1'
3
+ VERSION = '1.11.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.1
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank