philiprehberger-cli_kit 0.4.0 → 0.5.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: c4606c83ce0c95c7b047c9db662457bce97852169987a96a44566d4811e78313
4
- data.tar.gz: 907327c09e57175ca6e1c07d03369fdfe5f157534836e64acf348b79dc439a5e
3
+ metadata.gz: 895e4a8ff9edcfa13591e60cd91454c81840404c61b724e3394d234b71f8e496
4
+ data.tar.gz: b789d3b41ab39145500841661603728c8edccc438ab577319c6166bdf27230cb
5
5
  SHA512:
6
- metadata.gz: '08bb60e7b9c05a9e6d5572a8a393f61b987c07a136f7cb1eaf6e6ac58168fea50230f5855d073c47bd0516b178d19e138d223ccc7ff4e529248b9aef16f08699'
7
- data.tar.gz: 20864d8ed45d20aabe85d072ba1adcb44590c76f346329e51314b4163bce07951b2759327ef852112bccaec05f82705e28b5534502d5b5dde6e2b0efaddb4733
6
+ metadata.gz: 6b708dc9eadf82852b3d683f32dd4adeeaae2bc0f3985ce2c338930a58cc1cb8bbe2cff17a929578907ffe68ae1c63a38ff115129fefdb68a531a18c467d0650
7
+ data.tar.gz: 94e8d68950132d59d2ed894d356374269989d5f73db2837897f957cc3fd70011f5f1b4c96f8ba75554b7069c65900c1385bf357885ba925346009da154ba011f
data/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.5.0] - 2026-04-25
11
+
12
+ ### Added
13
+ - ANSI color helpers via `CliKit.color`, `CliKit.bold`, `CliKit.dim` and the `CliKit::Colorize` module
14
+ - Automatic disable when stdout is not a TTY or `NO_COLOR` is set
15
+
10
16
  ## [0.4.0] - 2026-04-18
11
17
 
12
18
  ### Added
@@ -68,7 +74,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
68
74
  - Animated spinner for long-running operations
69
75
  - Positional argument collection
70
76
 
71
- [Unreleased]: https://github.com/philiprehberger/rb-cli-kit/compare/v0.4.0...HEAD
77
+ [Unreleased]: https://github.com/philiprehberger/rb-cli-kit/compare/v0.5.0...HEAD
78
+ [0.5.0]: https://github.com/philiprehberger/rb-cli-kit/compare/v0.4.0...v0.5.0
72
79
  [0.4.0]: https://github.com/philiprehberger/rb-cli-kit/compare/v0.3.1...v0.4.0
73
80
  [0.3.1]: https://github.com/philiprehberger/rb-cli-kit/compare/v0.3.0...v0.3.1
74
81
  [0.3.0]: https://github.com/philiprehberger/rb-cli-kit/compare/v0.2.1...v0.3.0
data/README.md CHANGED
@@ -177,6 +177,17 @@ data = Philiprehberger::CliKit.spinner('Loading data...') do
177
177
  end
178
178
  ```
179
179
 
180
+ ### Color Output
181
+
182
+ Colors are auto-disabled when stdout is not a TTY or the `NO_COLOR` environment variable is set.
183
+
184
+ ```ruby
185
+ require "philiprehberger/cli_kit"
186
+
187
+ puts Philiprehberger::CliKit.color('OK', :green)
188
+ puts Philiprehberger::CliKit.bold('Important')
189
+ ```
190
+
180
191
  ## API
181
192
 
182
193
  | Method | Description |
@@ -189,6 +200,9 @@ end
189
200
  | `.select(message, choices)` | Present numbered menu and return one selection |
190
201
  | `.multi_select(message, choices, defaults:)` | Present numbered menu and return multiple selections |
191
202
  | `.spinner(message) { ... }` | Show spinner during block execution |
203
+ | `.color(text, name)` | Wrap text in ANSI color (no-op when not a TTY or NO_COLOR set) |
204
+ | `.bold(text)` | Wrap text in ANSI bold |
205
+ | `.dim(text)` | Wrap text in ANSI dim |
192
206
  | `Parser#option(name, multi: true)` | Collect repeated option values into an array |
193
207
  | `Parser#option(name, required: true)` | Raise `CliKit::Error` at parse time when the option is omitted |
194
208
  | `Parser#flags` | Hash of boolean flag values |
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Philiprehberger
4
+ module CliKit
5
+ # ANSI color and style helpers. Output is auto-disabled when stdout is not a
6
+ # TTY or the NO_COLOR environment variable is set (per https://no-color.org).
7
+ module Colorize
8
+ CODES = {
9
+ red: 31, green: 32, yellow: 33, blue: 34,
10
+ magenta: 35, cyan: 36, white: 37, gray: 90
11
+ }.freeze
12
+
13
+ module_function
14
+
15
+ # @return [Boolean] true when ANSI escape codes should be emitted
16
+ def enabled?
17
+ return false if ENV.key?('NO_COLOR')
18
+
19
+ $stdout.tty?
20
+ end
21
+
22
+ # Wraps text in an ANSI color escape, or returns it untouched when colors
23
+ # are disabled.
24
+ #
25
+ # @param text [String]
26
+ # @param name [Symbol] one of :red, :green, :yellow, :blue, :magenta, :cyan, :white, :gray
27
+ # @return [String]
28
+ def color(text, name)
29
+ return text unless enabled?
30
+
31
+ code = CODES.fetch(name) { raise ArgumentError, "unknown color: #{name.inspect}" }
32
+ "\e[#{code}m#{text}\e[0m"
33
+ end
34
+
35
+ # @param text [String]
36
+ # @return [String]
37
+ def bold(text)
38
+ return text unless enabled?
39
+
40
+ "\e[1m#{text}\e[0m"
41
+ end
42
+
43
+ # @param text [String]
44
+ # @return [String]
45
+ def dim(text)
46
+ return text unless enabled?
47
+
48
+ "\e[2m#{text}\e[0m"
49
+ end
50
+ end
51
+ end
52
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module CliKit
5
- VERSION = '0.4.0'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
@@ -5,6 +5,7 @@ require_relative 'cli_kit/parser'
5
5
  require_relative 'cli_kit/prompt'
6
6
  require_relative 'cli_kit/spinner'
7
7
  require_relative 'cli_kit/menu'
8
+ require_relative 'cli_kit/colorize'
8
9
 
9
10
  module Philiprehberger
10
11
  module CliKit
@@ -105,5 +106,26 @@ module Philiprehberger
105
106
  def self.multi_select(message, choices, defaults: [], input: $stdin, output: $stdout)
106
107
  Menu.multi_select(message, choices, defaults: defaults, input: input, output: output)
107
108
  end
109
+
110
+ # Wraps text in ANSI color (auto-disabled when not a TTY or NO_COLOR is set).
111
+ #
112
+ # @param text [String]
113
+ # @param name [Symbol]
114
+ # @return [String]
115
+ def self.color(text, name)
116
+ Colorize.color(text, name)
117
+ end
118
+
119
+ # @param text [String]
120
+ # @return [String]
121
+ def self.bold(text)
122
+ Colorize.bold(text)
123
+ end
124
+
125
+ # @param text [String]
126
+ # @return [String]
127
+ def self.dim(text)
128
+ Colorize.dim(text)
129
+ end
108
130
  end
109
131
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-cli_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Rehberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-19 00:00:00.000000000 Z
11
+ date: 2026-04-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Lightweight CLI toolkit combining argument parsing with flags and options,
14
14
  interactive prompts with confirmation, and animated spinners for long-running operations.
@@ -22,6 +22,7 @@ files:
22
22
  - LICENSE
23
23
  - README.md
24
24
  - lib/philiprehberger/cli_kit.rb
25
+ - lib/philiprehberger/cli_kit/colorize.rb
25
26
  - lib/philiprehberger/cli_kit/menu.rb
26
27
  - lib/philiprehberger/cli_kit/parser.rb
27
28
  - lib/philiprehberger/cli_kit/prompt.rb