@lewishowles/cli-style 0.4.1 → 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ## 0.5.0 - 2026-07-02
6
+
7
+ ### Added
8
+
9
+ - Added Bash adapter convenience functions for common renderers: `cli_style_status`, `cli_style_row`, `cli_style_divider`, and `cli_style_hint`.
10
+ - Added Bash adapter escaping for dynamic string values, so scripts can pass quotes, backslashes, paths, and messages without hand-building JSON.
11
+ - Added README examples for JS CLI entrypoint wiring with `createCliStyle({ argv, env, stdout })` and helper-first Bash adapter usage.
12
+
13
+ ### Changed
14
+
15
+ - Lightened the muted colour token so secondary text stays readable on dark surfaces.
16
+
3
17
  ## 0.4.1 - 2026-07-01
4
18
 
5
19
  ### Fixed
package/README.md CHANGED
@@ -27,8 +27,9 @@ export PATH="/path/to/cli-style/bin:$PATH"
27
27
  import { createCliStyle, status } from "@lewishowles/cli-style";
28
28
 
29
29
  const ui = createCliStyle({
30
- profile: "human",
31
- width: 80,
30
+ argv: process.argv.slice(2),
31
+ env: process.env,
32
+ stdout: process.stdout,
32
33
  });
33
34
 
34
35
  const output = status("success", "184 tests", {
@@ -41,6 +42,8 @@ ui.print(output);
41
42
 
42
43
  Renderer methods return strings. `ui.print()`, `ui.write()`, and CLI commands handle stdout and stderr.
43
44
 
45
+ Create the `ui` instance at the CLI entrypoint, then pass it to command handlers. That keeps flag, environment, stream, colour, Unicode, and width detection in one place.
46
+
44
47
  ## Reporter
45
48
 
46
49
  Use a reporter when a script needs grouped output rather than one row per file.
@@ -131,19 +134,33 @@ The package contains `bin/cli-style` and `adapters/`. Install it into a repo-loc
131
134
  ```bash
132
135
  source "$(cli-style adapter-path bash)"
133
136
 
134
- cli_style_render status --profile diagnostic <<'JSON'
135
- {
136
- "type": "success",
137
- "label": "Build passed",
138
- "detail": "184 tests"
139
- }
140
- JSON
137
+ label='Build "passed"'
138
+ detail="/path/to/project"
139
+
140
+ cli_style_status success "$label" "$detail" --profile diagnostic
141
+ cli_style_row "Workspace" "$detail" --plain
142
+ cli_style_hint "Run \"check\" before release" --plain
143
+ cli_style_divider "Project setup" --plain
144
+ ```
145
+
146
+ Use the convenience functions for dynamic Bash values. They build JSON internally, so callers do not need to escape quotes, backslashes, or paths by hand.
147
+
148
+ `cli_style_status` accepts `type`, `label`, `detail`, then render flags. Pass an empty detail when you only need a label:
149
+
150
+ ```bash
151
+ cli_style_status success "Done" "" --plain
141
152
  ```
142
153
 
143
154
  Set `CLI_STYLE_BIN` when `cli-style` is not on `PATH`:
144
155
 
145
156
  ```bash
146
- CLI_STYLE_BIN="/path/to/cli-style" cli_style_render status --plain <<'JSON'
157
+ CLI_STYLE_BIN="/path/to/cli-style" cli_style_status success "Build passed" "" --plain
158
+ ```
159
+
160
+ Keep `cli_style_render` for literal or prebuilt JSON:
161
+
162
+ ```bash
163
+ cli_style_render status --plain <<'JSON'
147
164
  {
148
165
  "type": "success",
149
166
  "label": "Build passed"
@@ -23,6 +23,40 @@ cli_style_has_binary() {
23
23
  command -v "$binary" >/dev/null 2>&1
24
24
  }
25
25
 
26
+ # Escape a Bash string for JSON string values.
27
+ #
28
+ # @param {string} value
29
+ # String value to encode.
30
+ cli_style_json_string() {
31
+ local value="${1:-}"
32
+
33
+ value="${value//\\/\\\\}"
34
+ value="${value//\"/\\\"}"
35
+ value="${value//$'\b'/\\b}"
36
+ value="${value//$'\f'/\\f}"
37
+ value="${value//$'\n'/\\n}"
38
+ value="${value//$'\r'/\\r}"
39
+ value="${value//$'\t'/\\t}"
40
+
41
+ printf '"%s"' "$value"
42
+ }
43
+
44
+ # Render a JSON object through the shared cli-style command.
45
+ #
46
+ # @param {string} renderer
47
+ # Stable renderer name accepted by `cli-style render`.
48
+ # @param {string} json
49
+ # Prebuilt JSON object.
50
+ # @param {string} ...
51
+ # Render flags passed through to `cli-style render`.
52
+ cli_style_render_json() {
53
+ local renderer="${1:-}"
54
+ local json="${2:-}"
55
+
56
+ shift 2
57
+ printf '%s\n' "$json" | cli_style_render "$renderer" "$@"
58
+ }
59
+
26
60
  # Render stdin JSON through the shared cli-style command.
27
61
  #
28
62
  # @param {string} renderer
@@ -48,3 +82,96 @@ cli_style_render() {
48
82
 
49
83
  "$binary" render "$renderer" "$@"
50
84
  }
85
+
86
+ # Render a result status line from Bash string values.
87
+ #
88
+ # @param {string} type
89
+ # Result type such as success, failed, warning, or skipped.
90
+ # @param {string} label
91
+ # Status label.
92
+ # @param {string} detail
93
+ # Optional detail text.
94
+ # @param {string} ...
95
+ # Render flags passed through to `cli-style render`.
96
+ cli_style_status() {
97
+ local type="${1:-}"
98
+ local label="${2:-}"
99
+ local detail="${3:-}"
100
+ local json
101
+
102
+ if (($# >= 3)); then
103
+ shift 3
104
+ else
105
+ set --
106
+ fi
107
+
108
+ json="{\"type\":$(cli_style_json_string "$type"),\"label\":$(cli_style_json_string "$label"),\"detail\":$(cli_style_json_string "$detail")}"
109
+
110
+ cli_style_render_json status "$json" "$@"
111
+ }
112
+
113
+ # Render a labelled value row from Bash string values.
114
+ #
115
+ # @param {string} label
116
+ # Row label.
117
+ # @param {string} value
118
+ # Row value.
119
+ # @param {string} ...
120
+ # Render flags passed through to `cli-style render`.
121
+ cli_style_row() {
122
+ local label="${1:-}"
123
+ local value="${2:-}"
124
+ local json
125
+
126
+ if (($# >= 2)); then
127
+ shift 2
128
+ else
129
+ set --
130
+ fi
131
+
132
+ json="{\"label\":$(cli_style_json_string "$label"),\"value\":$(cli_style_json_string "$value")}"
133
+
134
+ cli_style_render_json row "$json" "$@"
135
+ }
136
+
137
+ # Render a divider from a Bash string value.
138
+ #
139
+ # @param {string} label
140
+ # Optional divider label.
141
+ # @param {string} ...
142
+ # Render flags passed through to `cli-style render`.
143
+ cli_style_divider() {
144
+ local label="${1:-}"
145
+ local json
146
+
147
+ if (($# >= 1)); then
148
+ shift
149
+ else
150
+ set --
151
+ fi
152
+
153
+ json="{\"label\":$(cli_style_json_string "$label")}"
154
+
155
+ cli_style_render_json divider "$json" "$@"
156
+ }
157
+
158
+ # Render a hint from a Bash string value.
159
+ #
160
+ # @param {string} message
161
+ # Hint message.
162
+ # @param {string} ...
163
+ # Render flags passed through to `cli-style render`.
164
+ cli_style_hint() {
165
+ local message="${1:-}"
166
+ local json
167
+
168
+ if (($# >= 1)); then
169
+ shift
170
+ else
171
+ set --
172
+ fi
173
+
174
+ json="{\"message\":$(cli_style_json_string "$message")}"
175
+
176
+ cli_style_render_json hint "$json" "$@"
177
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lewishowles/cli-style",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Shared terminal output styles for Lewis Howles tools, diagnostics, and package CLIs.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -5,7 +5,7 @@ export const colourTokens = {
5
5
  border: "#2a3a42",
6
6
  danger: "#ff7272",
7
7
  info: "#8bbdff",
8
- muted: "#6f7f87",
8
+ muted: "#7a8a92",
9
9
  success: "#8fdf72",
10
10
  surface: "#0f181b",
11
11
  surfaceRaised: "#132024",