hackmac 1.9.1 → 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 +4 -4
- data/CHANGES.md +16 -0
- data/VERSION +1 -1
- data/bin/gfxmon +7 -5
- data/hackmac.gemspec +2 -2
- data/lib/hackmac/graph/display.rb +12 -5
- data/lib/hackmac/graph.rb +72 -23
- data/lib/hackmac/ioreg.rb +4 -2
- data/lib/hackmac/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5d8b91e07ca88dc28f574608697201338b76a9c33bce86c6c92e49bfea49716b
|
|
4
|
+
data.tar.gz: 38fbeec1739607ce09da13ce4f200a7c484479d0ed859bd5db2e8d4fb06b52ff
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c2c4528dbf84320e01fdc90380bcb7eec65f38b28e885c499c2c7594eca0ddabe53a7ea70d47e983195d660936fb2c638f0203a2f23054b132e10dcf0c955395
|
|
7
|
+
data.tar.gz: 2499348bd0baa5d217a77f6c4959f2a78a6693e52d93975cf305713203dc4c647c9d9c286b0f2a01bab75f8694d298d8ecbdd165ca87e126ff984ea9037b6c97
|
data/CHANGES.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
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
|
+
|
|
3
19
|
## 2025-10-25 v1.9.1
|
|
4
20
|
|
|
5
21
|
- Addresses display issues in tmux panes where background colors bled through
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.
|
|
1
|
+
1.10.0
|
data/bin/gfxmon
CHANGED
|
@@ -32,7 +32,7 @@ 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:jlh', defaults: { ?s => true, ?n => 5 }
|
|
36
36
|
|
|
37
37
|
# The usage method displays command-line usage information and options
|
|
38
38
|
#
|
|
@@ -53,6 +53,7 @@ def usage
|
|
|
53
53
|
-n SECONDS measure every SECONDS
|
|
54
54
|
-m METRIC output graph for performance METRIC
|
|
55
55
|
-c COLOR output graph in this terminal COLOR (between 0 - 255)
|
|
56
|
+
-C COLOR output graph using secondary color COLOR
|
|
56
57
|
|
|
57
58
|
EOT
|
|
58
59
|
0
|
|
@@ -176,10 +177,11 @@ def display_graph
|
|
|
176
177
|
sleep_duration = [ 1, ($opts[?n] || 10).to_i ].max
|
|
177
178
|
format_value = derive_formatter(metric)
|
|
178
179
|
graph = Hackmac::Graph.new(
|
|
179
|
-
title:
|
|
180
|
-
sleep:
|
|
181
|
-
value:
|
|
182
|
-
color:
|
|
180
|
+
title: metric,
|
|
181
|
+
sleep: sleep_duration,
|
|
182
|
+
value: -> _ { ps[metric] || 0 },
|
|
183
|
+
color: $opts[?c],
|
|
184
|
+
color_secondary: $opts[?C],
|
|
183
185
|
format_value:
|
|
184
186
|
)
|
|
185
187
|
graph.start
|
data/hackmac.gemspec
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
# stub: hackmac 1.
|
|
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.
|
|
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
|
-
|
|
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 =
|
|
51
|
-
@on_color =
|
|
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 =
|
|
74
|
-
@on_color =
|
|
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
|
|
53
|
-
#
|
|
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
|
|
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:
|
|
61
|
-
format_value:
|
|
62
|
-
sleep:
|
|
63
|
-
color:
|
|
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
|
|
67
|
-
@value
|
|
68
|
-
@format_value
|
|
69
|
-
@sleep
|
|
70
|
-
@continue
|
|
71
|
-
@data
|
|
72
|
-
@color
|
|
73
|
-
@
|
|
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
|
|
112
|
-
color
|
|
113
|
-
|
|
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(
|
|
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
151
|
@display.at(iy, x).on_color(0).color(color).write(?▄)
|
|
126
152
|
else
|
|
127
|
-
@display.at(iy, x).on_color(color).color(
|
|
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
|
-
|
|
369
|
-
|
|
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
|
|
32
|
-
|
|
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/version.rb
CHANGED