@effected/cli 0.10.0 → 0.12.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.
Files changed (92) hide show
  1. package/Cancelled.js +44 -0
  2. package/CliAudience.js +178 -0
  3. package/CliColor.js +13 -19
  4. package/CliEnv.js +89 -0
  5. package/CliExit.js +1 -1
  6. package/CliFailure.js +302 -0
  7. package/CliInteractive.js +71 -0
  8. package/CliLinks.js +154 -0
  9. package/CliLog.js +346 -0
  10. package/CliLogger.js +34 -33
  11. package/CliMessage.js +80 -0
  12. package/CliPrompt.js +104 -0
  13. package/CliRuntime.js +110 -54
  14. package/CliTest.js +16 -0
  15. package/CliTheme.js +141 -0
  16. package/ConfigIssueRenderer.js +14 -33
  17. package/Doc.js +536 -0
  18. package/Fmt.js +133 -0
  19. package/GithubAnnotation.js +40 -0
  20. package/Glyphs.js +83 -0
  21. package/NotInteractive.js +42 -0
  22. package/README.md +145 -131
  23. package/Render.js +255 -0
  24. package/SchemaIssueRenderer.js +7 -10
  25. package/Status.js +166 -0
  26. package/TestTerminal.js +80 -0
  27. package/Token.js +69 -0
  28. package/index.d.ts +3089 -169
  29. package/index.js +19 -1
  30. package/internal/ansi.js +230 -0
  31. package/internal/autoFormat.js +34 -0
  32. package/internal/canPrompt.js +15 -0
  33. package/internal/counts.js +84 -0
  34. package/internal/diagnostics.js +32 -0
  35. package/internal/displayWidth.js +35 -0
  36. package/internal/failureTarget.js +195 -0
  37. package/internal/fallbackAnswer.js +18 -0
  38. package/internal/fileSink.js +62 -0
  39. package/internal/format.js +62 -7
  40. package/internal/layout.js +250 -0
  41. package/internal/linkScheme.js +30 -0
  42. package/internal/linkTarget.js +50 -0
  43. package/internal/logSafety.js +46 -0
  44. package/internal/renderAnsi.js +52 -0
  45. package/internal/renderDoc.js +320 -0
  46. package/internal/renderGithubLog.js +46 -0
  47. package/internal/renderMarkdown.js +368 -0
  48. package/internal/renderPlain.js +50 -0
  49. package/internal/scanAudience.js +106 -0
  50. package/internal/splitFrame.js +56 -0
  51. package/internal/wizardGate.js +18 -0
  52. package/package.json +40 -5
  53. package/testing.d.ts +88 -2
  54. package/testing.js +2 -1
  55. package/ui/CliUi.js +432 -0
  56. package/ui/CliUiLive.js +446 -0
  57. package/ui/Confirm.js +245 -0
  58. package/ui/DocView.js +74 -0
  59. package/ui/KeyHelp.js +62 -0
  60. package/ui/KeyTable.js +199 -0
  61. package/ui/MultiSelect.js +260 -0
  62. package/ui/Select.js +230 -0
  63. package/ui/Tabs.js +202 -0
  64. package/ui/TextInput.js +290 -0
  65. package/ui/Toggle.js +32 -0
  66. package/ui/UiKey.js +44 -0
  67. package/ui/UiProvider.js +60 -0
  68. package/ui/UiStreams.js +18 -0
  69. package/ui/UiTheme.js +119 -0
  70. package/ui/Viewport.js +204 -0
  71. package/ui/internal/ErrorBoundary.js +30 -0
  72. package/ui/internal/Holder.js +74 -0
  73. package/ui/internal/ScreenContext.js +52 -0
  74. package/ui/internal/UiProviders.js +21 -0
  75. package/ui/internal/ink.js +122 -0
  76. package/ui/internal/inkChalk.js +58 -0
  77. package/ui/internal/inkConsole.js +146 -0
  78. package/ui/internal/lazyView.js +74 -0
  79. package/ui/internal/lineText.js +19 -0
  80. package/ui/internal/mountPermit.js +16 -0
  81. package/ui/internal/perfDrain.js +33 -0
  82. package/ui/internal/processStreams.js +19 -0
  83. package/ui/internal/renderOptions.js +13 -0
  84. package/ui/testing/CliUiTest.js +760 -0
  85. package/ui/testing/fakeStreams.js +79 -0
  86. package/ui/testing/terminalModel.js +59 -0
  87. package/ui-testing-serializer.d.ts +14 -0
  88. package/ui-testing-serializer.js +33 -0
  89. package/ui-testing.d.ts +527 -0
  90. package/ui-testing.js +3 -0
  91. package/ui.d.ts +1790 -0
  92. package/ui.js +17 -0
package/Cancelled.js ADDED
@@ -0,0 +1,44 @@
1
+ import { Runtime, Schema } from "effect";
2
+
3
+ //#region src/Cancelled.ts
4
+ /**
5
+ * A person backed out of an interactive prompt: they pressed escape, or the
6
+ * prompt was interrupted.
7
+ *
8
+ * @remarks
9
+ * Exits `130`, the conventional status for a run ended by the user, through
10
+ * core's own `Runtime.errorExitCode` marker, so `CliRuntime.reportFailures`
11
+ * keeps it. Its default rendering is one line, `cancelled; nothing written`,
12
+ * because nothing has been written by the time a prompt is cancelled and a
13
+ * stack trace would only alarm. A consumer `render` still overrides the line, and can hand off to it: the line is
14
+ * the error's `message`, so `error.message` and `String(error)` carry it.
15
+ *
16
+ * @public
17
+ */
18
+ var Cancelled = class extends Schema.TaggedError()("Cancelled", { reason: Schema.Literals(["escape", "interrupt"]) }) {
19
+ /**
20
+ * The one line, `cancelled; nothing written`.
21
+ *
22
+ * @remarks
23
+ * A prototype getter, not a field, so it is not part of the encoded form, equality or a JSON dump. Assigning to
24
+ * it is ignored: a library that rewrites `error.message` (to prefix a context, say) must not make this error throw,
25
+ * which a getter-only property does in strict mode. The line is fixed.
26
+ */
27
+ get message() {
28
+ return "cancelled; nothing written";
29
+ }
30
+ set message(_value) {}
31
+ /**
32
+ * The process exit code: `130`.
33
+ *
34
+ * @remarks
35
+ * A prototype getter rather than an own field, so a JSON or logger dump of the error does not carry the
36
+ * runtime marker.
37
+ */
38
+ get [Runtime.errorExitCode]() {
39
+ return 130;
40
+ }
41
+ };
42
+
43
+ //#endregion
44
+ export { Cancelled };
package/CliAudience.js ADDED
@@ -0,0 +1,178 @@
1
+ import { canPrompt } from "./internal/canPrompt.js";
2
+ import { CliInteractive } from "./CliInteractive.js";
3
+ import { refreshFailureTarget } from "./internal/failureTarget.js";
4
+ import { scanAudience, tallyAudience } from "./internal/scanAudience.js";
5
+ import { WizardDropped } from "./internal/wizardGate.js";
6
+ import { Effect, Option, Stdio } from "effect";
7
+ import { Audience, TerminalEnv } from "@effected/env";
8
+ import { CliConfig, CliError, Command, Flag, GlobalFlag } from "effect/cli";
9
+
10
+ //#region src/CliAudience.ts
11
+ const KINDS = [
12
+ "human",
13
+ "agent",
14
+ "ci"
15
+ ];
16
+ /**
17
+ * Whether the run may prompt once a flag has named the audience.
18
+ *
19
+ * Only a `human` audience prompts, and only with a terminal on both standard input and standard output and a `TERM`
20
+ * that is not `dumb` (`canPrompt`, the decision `CliInteractive.layer` makes). With the
21
+ * terminal facts in the environment (`TerminalEnv`) that is decided from them, not from the ambient value, so a
22
+ * flag can WIDEN: `--human` under a detected agent on real terminals prompts, and in a pipe it still cannot. With no
23
+ * `TerminalEnv` there is nothing to decide from and the flag only narrows.
24
+ */
25
+ const interactiveWhenFlagged = (kind, current) => Effect.flatMap(Effect.serviceOption(TerminalEnv), (terminal) => {
26
+ if (kind !== "human") return Effect.succeed(false);
27
+ return Option.isSome(terminal) ? canPrompt(terminal.value) : Effect.succeed(current);
28
+ });
29
+ const CONFLICT = "Give at most one of --audience, --human, --agent, --ci (once).";
30
+ /** Resolve the four flags into the audience to provide, failing when more than one occurrence was given. */
31
+ const resolve = (input) => {
32
+ const { given: named, conflict } = tallyAudience(input);
33
+ if (conflict) return Effect.fail(new CliError.UserError({
34
+ cause: /* @__PURE__ */ new Error(CONFLICT),
35
+ userMessage: CONFLICT
36
+ }));
37
+ const [kind] = named;
38
+ return kind === void 0 ? Audience : Effect.succeed({
39
+ kind,
40
+ source: "flag"
41
+ });
42
+ };
43
+ /**
44
+ * The audience flags of a CLI: `--audience <human|agent|ci>` and the shorthands `--human`, `--agent`, `--ci`,
45
+ * resolved into `@effected/env`'s `Audience`.
46
+ *
47
+ * @remarks
48
+ * The one wiring: share the flags on the root command and hand the root to {@link CliAudience.run} (or
49
+ * {@link CliAudience.runWith}), which resolves the flags from argv before core parses and applies
50
+ * {@link CliAudience.provide} itself:
51
+ *
52
+ * ```ts
53
+ * const root = Command.make("tool").pipe(
54
+ * Command.withSharedFlags(CliAudience.flags()),
55
+ * Command.withSubcommands([verify]),
56
+ * )
57
+ * NodeRuntime.runMain(
58
+ * CliRuntime.main(CliAudience.run(root, { version }), { platform: NodeServices.layer, env: {} }),
59
+ * )
60
+ * ```
61
+ *
62
+ * Core lists a shared flag in the help of every subcommand, not only at the root: that is upstream (Effect-TS/effect
63
+ * issue 8642), and `flags({ hidden: true })` is the way to keep them out of help altogether.
64
+ *
65
+ * A root that forgot `Command.withSharedFlags(CliAudience.flags())` does not compile. Giving more than one
66
+ * occurrence across the four flags is a usage error even when they agree; a boolean set to false (`--no-agent`,
67
+ * `--agent=false`) counts as not given. A bad `--audience` value is core's own parse error. Both exit `64` under
68
+ * `CliRuntime.main`. A conflicting audience together with `--help` exits `0` and prints help, because core handles
69
+ * its action flags before the resolver runs.
70
+ *
71
+ * A flag decides `CliInteractive` from the audience it names and the terminal facts: `--human` is interactive when
72
+ * `TerminalEnv` says there is a terminal on stdin and on stdout, even where the environment detected an agent, so a
73
+ * person running the tool inside an agent can ask for the human experience; in a pipe it still cannot prompt. A
74
+ * non-human flag (`--agent`, `--ci`, `--audience agent|ci`) turns it off and drops `--wizard`, and switches
75
+ * diagnostics to NDJSON, for the whole run including the parse step where a fallback prompt fires. Without
76
+ * `TerminalEnv` in the environment a flag only narrows. `--wizard` follows the decision: a run a flag makes
77
+ * interactive gets it back where the environment's gate had dropped it, and only there: a consumer's own `builtIns`
78
+ * without it stay without it.
79
+ * {@link CliAudience.provide} on its own, the path for a bare `Command.run`, acts only on the subcommand handler,
80
+ * because core parses the root flags into a local context before any of it is visible.
81
+ *
82
+ * @public
83
+ */
84
+ var CliAudience = class CliAudience {
85
+ constructor() {}
86
+ /**
87
+ * The four flags, for `Command.withSharedFlags` on the root command.
88
+ *
89
+ * @remarks
90
+ * Each is repeatable, so every occurrence is counted; a boolean given as `false` (`--agent=false`,
91
+ * `--no-agent`) is not an occurrence. Core lists shared flags in every command's help; pass
92
+ * `hidden` to remove them from all of them.
93
+ */
94
+ static flags = (options) => {
95
+ const hide = options?.hidden === true;
96
+ const maybeHide = (flag) => hide ? Flag.withHidden(flag) : flag;
97
+ return {
98
+ audience: maybeHide(Flag.Literals("audience", KINDS).pipe(Flag.atLeast(0), Flag.withDescription("Who the output is for"))),
99
+ human: maybeHide(Flag.Boolean("human").pipe(Flag.atLeast(0), Flag.withDescription("Shorthand for --audience human"))),
100
+ agent: maybeHide(Flag.Boolean("agent").pipe(Flag.atLeast(0), Flag.withDescription("Shorthand for --audience agent"))),
101
+ ci: maybeHide(Flag.Boolean("ci").pipe(Flag.atLeast(0), Flag.withDescription("Shorthand for --audience ci")))
102
+ };
103
+ };
104
+ /**
105
+ * Resolve the flags before every subcommand handler and re-provide `Audience`.
106
+ *
107
+ * @remarks
108
+ * `CliAudience.run` and `runWith` apply this themselves, so a program run through them never needs it. Use it
109
+ * directly only with a bare `Command.run`, which leaves a fallback prompt blind to the flags (see the class
110
+ * remarks).
111
+ *
112
+ * A failure report is written outside the run, where the flag is not in force, so only `runWith` and `run` carry
113
+ * the flag's audience to it; with this on its own the report follows the environment's audience.
114
+ *
115
+ * Pipe it onto the composite root, after `withSubcommands`, since a parent's handler does not run when a
116
+ * subcommand is selected. With exactly one flag the audience is `{ kind, source: "flag" }`; with none the
117
+ * ambient `Audience` is read and provided back unchanged, so `Audience` stays in the requirement a handler
118
+ * reading it already has, and is added to a program whose handlers do not read it.
119
+ */
120
+ static provide = (command) => Command.provideEffect(command, Audience, (input) => resolve(input)).pipe(Command.provideEffect(CliInteractive, (input) => Effect.gen(function* () {
121
+ const current = yield* CliInteractive;
122
+ const [flagged] = tallyAudience(input).given;
123
+ return flagged === void 0 ? current : yield* interactiveWhenFlagged(flagged, current);
124
+ })));
125
+ /**
126
+ * Run a command the way `Command.runWith` does, with the audience flag resolved BEFORE core parses.
127
+ *
128
+ * @remarks
129
+ * It scans `argv` for the four audience flags first, then runs core around a provided `Audience` (when exactly
130
+ * one is given: `{ kind, source: "flag" }`) and a `CliInteractive` decided from it: `--human` is interactive when
131
+ * `TerminalEnv` reports a terminal on stdin and stdout and `TERM` is not `dumb` (it can turn prompting on under a detected agent), a
132
+ * non-human flag or a conflict makes it false. A fallback prompt fires while core parses, earlier than
133
+ * anything `CliAudience.provide` can reach, so `--agent init` on a terminal would otherwise still prompt. No
134
+ * flag leaves the ambient values untouched. A conflict still gets core's own usage error, exit `64`, from
135
+ * `CliAudience.provide`'s resolver.
136
+ *
137
+ * @param command - the composite root, with the flags shared and `CliAudience.provide` piped on
138
+ * @param config - the same `version` and `renderErrors` as core's
139
+ */
140
+ static runWith = (command, config) => {
141
+ const core = Command.runWith(CliAudience.provide(command), config);
142
+ return (argv) => {
143
+ const run = core(argv);
144
+ const { given, conflict } = scanAudience(argv);
145
+ const [kind] = given;
146
+ if (kind === void 0) return run;
147
+ const withAudience = conflict ? run : Effect.provideService(run, Audience, {
148
+ kind,
149
+ source: "flag"
150
+ });
151
+ return Effect.gen(function* () {
152
+ const current = yield* CliInteractive;
153
+ const ambient = yield* CliConfig.CliConfig;
154
+ if (!conflict) yield* refreshFailureTarget({
155
+ kind,
156
+ source: "flag"
157
+ });
158
+ const interactive = !conflict && (yield* interactiveWhenFlagged(kind, current));
159
+ const decided = Effect.provideService(withAudience, CliInteractive, interactive);
160
+ const hasWizard = ambient.builtIns.includes(GlobalFlag.Wizard);
161
+ if (!(interactive && !hasWizard && (yield* WizardDropped) === ambient) && !(!interactive && hasWizard)) return yield* decided;
162
+ const builtIns = interactive ? [...ambient.builtIns, GlobalFlag.Wizard] : ambient.builtIns.filter((flag) => flag !== GlobalFlag.Wizard);
163
+ return yield* Effect.provideService(decided, CliConfig.CliConfig, CliConfig.make({ builtIns }));
164
+ });
165
+ };
166
+ };
167
+ /**
168
+ * `Command.run` with the audience flag resolved before parsing: reads `Stdio.args` and calls
169
+ * {@link CliAudience.runWith}.
170
+ *
171
+ * @param command - the composite root
172
+ * @param config - the same `version` and `renderErrors` as core's
173
+ */
174
+ static run = (command, config) => Stdio.Stdio.use(({ args }) => Effect.flatMap(args, (argv) => CliAudience.runWith(command, config)(argv)));
175
+ };
176
+
177
+ //#endregion
178
+ export { CliAudience };
package/CliColor.js CHANGED
@@ -1,22 +1,23 @@
1
- import { Config, Effect, Layer, Option, Stdio } from "effect";
1
+ import { Effect, Layer } from "effect";
2
+ import { TerminalEnv } from "@effected/env";
2
3
  import { CliOutput } from "effect/cli";
3
4
 
4
5
  //#region src/CliColor.ts
5
- const noColor = Config.option(Config.String("NO_COLOR"));
6
6
  /**
7
7
  * Whether a CLI's output should carry ANSI colour, decided once and shared by
8
8
  * everything that renders — help text, error output, and any rendered result.
9
9
  *
10
10
  * @remarks
11
- * Follows the no-color.org rule: colour is off when stdout is not a
12
- * terminal, or when `NO_COLOR` is set to any **non-empty** value — an empty
13
- * `NO_COLOR=""` does not disable colour. `FORCE_COLOR` is ignored, matching
14
- * core's own formatter. The environment is read through the ambient
15
- * `ConfigProvider`, never `process`, so a test swaps it with
16
- * `Effect.provideService(ConfigProvider.ConfigProvider, ...)`. The kit's
17
- * default providers (`fromEnv`, `fromUnknown`) already treat an empty
18
- * `NO_COLOR` as unset, so the explicit `set === ""` check exists for a
19
- * provider constructed with `{ preserveEmptyStrings: true }`.
11
+ * The decision is `@effected/env`'s `TerminalEnv.colorLevel("stdout")`, which
12
+ * follows Node's `getColorDepth` precedence: `FORCE_COLOR` first (`0` or an
13
+ * unrecognised value forces colour off; an empty value, `1` or `true` force basic colour, `2` 256 colours and
14
+ * `3` truecolor, even without a terminal), then a non-empty `NO_COLOR` or `NODE_DISABLE_COLORS` and
15
+ * `TERM=dumb`, then the TTY gate. `FORCE_COLOR` therefore beats `NO_COLOR`.
16
+ * The environment
17
+ * is read through the ambient `ConfigProvider`, never `process`, so a test
18
+ * swaps it with `Effect.provideService(ConfigProvider.ConfigProvider, ...)`;
19
+ * an ambient `TerminalEnv`, such as `TerminalEnv.layerTest`, answers instead
20
+ * when one is provided.
20
21
  *
21
22
  * @public
22
23
  */
@@ -27,14 +28,7 @@ var CliColor = class CliColor {
27
28
  *
28
29
  * @public
29
30
  */
30
- static enabled = Effect.gen(function* () {
31
- if (!(yield* (yield* Stdio.Stdio).stdoutIsTerminal)) return false;
32
- const value = yield* noColor.pipe(Effect.orElseSucceed(() => Option.none()));
33
- return Option.match(value, {
34
- onNone: () => true,
35
- onSome: (set) => set === ""
36
- });
37
- });
31
+ static enabled = TerminalEnv.colorLevel("stdout").pipe(Effect.map((level) => level !== "none"));
38
32
  /**
39
33
  * Core's default `CliOutput.Formatter`, coloured by the same decision as
40
34
  * {@link CliColor.enabled}, so help text, parse errors and rendered
package/CliEnv.js ADDED
@@ -0,0 +1,89 @@
1
+ import { CliInteractive } from "./CliInteractive.js";
2
+ import { ambientLinksLayer } from "./CliLinks.js";
3
+ import { CliTheme } from "./CliTheme.js";
4
+ import { CliPrompt } from "./CliPrompt.js";
5
+ import { ConfigProvider, Layer, Option } from "effect";
6
+ import { Audience, CurrentRuntimeEnv, TerminalEnv } from "@effected/env";
7
+
8
+ //#region src/CliEnv.ts
9
+ /**
10
+ * The environment services a CLI reads, built once and in the right order.
11
+ *
12
+ * @remarks
13
+ * Builds `CurrentRuntimeEnv`, `TerminalEnv`, `Audience`, `CliTheme` and `CliLinks`, and sets `CliInteractive` from them, then
14
+ * installs the two gates for the program: `CliPrompt.gateTerminal`, which replaces `Terminal` with a quiet one when
15
+ * the run is not interactive so no prompt runner ever attaches to stdin, and `CliPrompt.gateWizard`, which drops
16
+ * `--wizard` then. `TerminalEnv` is built from the real terminal first. The layer therefore also outputs
17
+ * `Terminal`, the gated one, and consumers never compose the gates themselves. A
18
+ * `Context.Reference`'s key type is `never`, so the layer's output type does not list `CliInteractive`: it sets
19
+ * the reference rather than providing a service. Every read of the environment goes through `Config` and
20
+ * degrades to "unset" when it fails, so building the layer does not fail on a bad provider; it fails only when
21
+ * `Stdio` or `Terminal` do.
22
+ *
23
+ * `CliLinks` reads `FileSystem` and `Path` from the surrounding context if it has them, and does not require them: a
24
+ * `.vscode/` directory is looked for, and a relative path resolved, only when the platform is provided OUTSIDE this
25
+ * layer, as `CliRuntime.main` does. Without them `auto` is `vscode` on the terminal signal alone.
26
+ *
27
+ * Not interactive, the gated `Terminal`'s `readLine` fails as a quit, its input is already ended and its `display`
28
+ * writes nothing. A program that reads piped data must read `Stdio.stdin`, and one that writes output must use
29
+ * `Console` or `Stdio`, never `Terminal`. It also installs `CliTheme.promptTheme`, so core's prompts follow the
30
+ * theme.
31
+ *
32
+ * @public
33
+ */
34
+ var CliEnv = class {
35
+ constructor() {}
36
+ /**
37
+ * The environment services for the terminal `Stdio` and `Terminal` describe.
38
+ *
39
+ * @remarks
40
+ * A layer-returning function mints a fresh layer per call: call it once and bind the result to a constant.
41
+ *
42
+ * @param options - the audience env var, the stderr check and the theme options
43
+ */
44
+ static layer = (options = {}) => {
45
+ const base = Layer.mergeAll(CurrentRuntimeEnv.layer, TerminalEnv.layer(options.stderrIsTerminal === void 0 ? void 0 : { stderrIsTerminal: options.stderrIsTerminal }));
46
+ const withAudience = Audience.layer(options.audienceEnvVar === void 0 ? void 0 : { envVar: options.audienceEnvVar }).pipe(Layer.provideMerge(base));
47
+ const withTheme = CliTheme.layer(options.theme).pipe(Layer.provideMerge(withAudience));
48
+ const withLinks = ambientLinksLayer({
49
+ ...options.editorLinks === void 0 ? {} : { editorLinks: options.editorLinks },
50
+ ...options.editorLinksEnvVar === void 0 ? {} : { envVar: options.editorLinksEnvVar }
51
+ }).pipe(Layer.provideMerge(withTheme));
52
+ const withInteractive = CliInteractive.layer.pipe(Layer.provideMerge(withLinks));
53
+ return Layer.mergeAll(CliPrompt.gateTerminal, CliPrompt.gateWizard, CliTheme.promptTheme).pipe(Layer.provideMerge(withInteractive));
54
+ };
55
+ /**
56
+ * The environment services a test fixes, needing nothing and reading nothing of the host's: `TerminalEnv` and
57
+ * `Audience` from the answers given, `CliTheme` built from them as {@link CliEnv.layer} builds it, and
58
+ * `CliInteractive` set from them by the same rule (a human, every stream a terminal, and a `TERM` that is not
59
+ * `dumb`).
60
+ *
61
+ * @remarks
62
+ * `term` is handed to the theme and interactivity builds alone, through a `ConfigProvider` of their own: the
63
+ * program under the layer keeps its own provider, and a host's `TERM` (a test runner in a dumb terminal) never
64
+ * decides. A screen or a live view also needs `UiStreams` from `@effected/cli/ui`, which `CliUiTest` provides; this
65
+ * layer provides no `Terminal` and installs neither of `CliEnv.layer`'s prompt gates.
66
+ *
67
+ * A layer-returning function mints a fresh layer per call: call it once and bind the result to a constant.
68
+ *
69
+ * @param options - whether the streams are terminals, the `TERM`, the audience, the width, the colour and the theme
70
+ */
71
+ static layerTest = (options = {}) => {
72
+ const tty = options.tty ?? false;
73
+ const stream = {
74
+ isTerminal: tty,
75
+ color: options.color ?? "none",
76
+ columns: options.columns === void 0 ? Option.none() : Option.some(options.columns)
77
+ };
78
+ const facts = Layer.mergeAll(TerminalEnv.layerTest({
79
+ stdinIsTerminal: tty,
80
+ stdout: stream,
81
+ stderr: stream
82
+ }), Audience.layerTest(options.audience ?? "human"));
83
+ const term = ConfigProvider.layer(ConfigProvider.fromUnknown(options.term === void 0 ? {} : { TERM: options.term }));
84
+ return Layer.mergeAll(CliTheme.layer(options.theme), CliInteractive.layer).pipe(Layer.provide(term), Layer.provideMerge(facts));
85
+ };
86
+ };
87
+
88
+ //#endregion
89
+ export { CliEnv };
package/CliExit.js CHANGED
@@ -11,7 +11,7 @@ import { Context, Effect, Layer, MutableRef } from "effect";
11
11
  * handler must return normally — yet the process must exit non-zero. Writing
12
12
  * `process.exitCode` works only because Node's `runMain` skips
13
13
  * `process.exit(0)` on success; `process.exit(n)` in a handler skips every
14
- * finalizer. {@link CliRuntime.main} reads this cell after the program
14
+ * finalizer. `CliRuntime.main` reads this cell after the program
15
15
  * succeeds and turns a non-zero code into a marked failure the runtime's
16
16
  * teardown honours, on any runtime, with finalizers intact.
17
17
  *