@lewishowles/cli-style 0.8.0 → 0.8.1

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
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.8.1 - 2026-07-15
6
+
7
+ ### Fixed
8
+
9
+ - Fixed the Python and Swift adapters losing ANSI colour: they now set `FORCE_COLOR=1` for the child process when the caller's own stdout is a TTY, unless the caller has already set `FORCE_COLOR` or `NO_COLOR`.
10
+ - Documented that captured Bash output (command substitution) cannot auto-detect its eventual destination and requires an explicit `FORCE_COLOR=1` to opt into colour.
11
+
5
12
  ## 0.8.0 - 2026-07-05
6
13
 
7
14
  ### Added
package/README.md CHANGED
@@ -107,6 +107,14 @@ cli_style_next_step_block "Update helpers scripts" "Wrappers are now available"
107
107
 
108
108
  The convenience functions build JSON internally, so callers do not need to escape quotes, backslashes, or paths by hand.
109
109
 
110
+ Direct Bash calls use `cli-style`'s native stdout detection. When a helper's output is captured, the adapter cannot know where the captured text will be written, so set `FORCE_COLOR=1` explicitly when the destination is an interactive terminal:
111
+
112
+ ```bash
113
+ command="$(FORCE_COLOR=1 cli_style_span "npm run docs:readme" info)"
114
+ ```
115
+
116
+ Python and Swift automatically set `FORCE_COLOR=1` for the child render process when their caller's stdout is an interactive terminal. An existing `FORCE_COLOR` or `NO_COLOR` value is preserved. `FORCE_COLOR=0` does not enable colour, while `NO_COLOR`, `TERM=dumb`, and explicit no-colour flags remain authoritative.
117
+
110
118
  Set `CLI_STYLE_BIN` when `cli-style` is not on `PATH`:
111
119
 
112
120
  ```bash
@@ -506,7 +514,7 @@ Most renderers accept the same output options:
506
514
  | `unicode` | Whether Unicode symbols should be used. |
507
515
  | `width` | Available output width for renderers that adapt layout. |
508
516
 
509
- Use `createCliStyle()` to resolve these options from `argv`, `env`, `stdout`, CI, TTY, `NO_COLOR`, and terminal capability.
517
+ Use `createCliStyle()` to resolve these options from `argv`, `env`, `stdout`, CI, TTY, `NO_COLOR`, `FORCE_COLOR`, and terminal capability.
510
518
 
511
519
  ### CLI and Bash flags
512
520
 
@@ -7,6 +7,7 @@ import json
7
7
  import os
8
8
  import shutil
9
9
  import subprocess
10
+ import sys
10
11
  from pathlib import Path
11
12
  from typing import Any, Sequence
12
13
 
@@ -23,6 +24,20 @@ class CliStyleRenderError(CliStyleError):
23
24
  """Raised when cli-style rejects a render request."""
24
25
 
25
26
 
27
+ # Resolve the child environment while preserving explicit caller controls.
28
+ def resolve_subprocess_environment() -> dict[str, str]:
29
+ environment = os.environ.copy()
30
+
31
+ if (
32
+ sys.stdout.isatty()
33
+ and "FORCE_COLOR" not in environment
34
+ and "NO_COLOR" not in environment
35
+ ):
36
+ environment["FORCE_COLOR"] = "1"
37
+
38
+ return environment
39
+
40
+
26
41
  # Render caller data through `cli-style render`.
27
42
  #
28
43
  # @param {str} renderer
@@ -72,6 +87,7 @@ def render(
72
87
  command,
73
88
  capture_output=True,
74
89
  check=False,
90
+ env=resolve_subprocess_environment(),
75
91
  input=json.dumps(data),
76
92
  text=True,
77
93
  )
@@ -1,4 +1,9 @@
1
1
  import Foundation
2
+ #if canImport(Darwin)
3
+ import Darwin
4
+ #elseif canImport(Glibc)
5
+ import Glibc
6
+ #endif
2
7
 
3
8
  // Error types for cli-style adapter failures.
4
9
  enum CliStyleError: Error {
@@ -89,6 +94,7 @@ enum CliStyle {
89
94
  let process = Process()
90
95
  process.executableURL = URL(fileURLWithPath: resolvedBinary)
91
96
  process.arguments = arguments
97
+ process.environment = resolveProcessEnvironment()
92
98
 
93
99
  let stdinPipe = Pipe()
94
100
  let stdoutPipe = Pipe()
@@ -125,6 +131,21 @@ enum CliStyle {
125
131
  return stdoutText.trimmingCharacters(in: .newlines)
126
132
  }
127
133
 
134
+ /**
135
+ * Resolve the child environment for a captured render.
136
+ */
137
+ private static func resolveProcessEnvironment() -> [String: String] {
138
+ var environment = ProcessInfo.processInfo.environment
139
+
140
+ if isatty(STDOUT_FILENO) == 1 &&
141
+ environment["FORCE_COLOR"] == nil &&
142
+ environment["NO_COLOR"] == nil {
143
+ environment["FORCE_COLOR"] = "1"
144
+ }
145
+
146
+ return environment
147
+ }
148
+
128
149
  /**
129
150
  Render a result status line.
130
151
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lewishowles/cli-style",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "Shared terminal output styles for Lewis Howles tools, diagnostics, and package CLIs.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -23,12 +23,14 @@ export function resolveTerminalCapabilities(options = {}) {
23
23
  const isTty = stdout.isTTY === true;
24
24
  const isCi = env.CI === "true" || env.CI === "1";
25
25
  const isDumb = env.TERM === "dumb";
26
+ const forceColour = env.FORCE_COLOR !== undefined && env.FORCE_COLOR !== "0";
26
27
  const width = resolveWidth(stdout.columns);
27
28
  const usesPlain = argv.includes("--plain");
28
29
 
29
30
  const colour = resolveColour({
30
31
  argv,
31
32
  env,
33
+ forceColour,
32
34
  isDumb,
33
35
  isTty,
34
36
  usesPlain,
@@ -69,7 +71,7 @@ function resolveColour(options) {
69
71
  return false;
70
72
  }
71
73
 
72
- return options.isTty;
74
+ return options.forceColour || options.isTty;
73
75
  }
74
76
 
75
77
  /**