@travetto/terminal 3.0.0-rc.10 → 3.0.0-rc.11

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 (2) hide show
  1. package/README.md +80 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -6,4 +6,84 @@
6
6
  **Install: @travetto/terminal**
7
7
  ```bash
8
8
  npm install @travetto/terminal
9
+
10
+ # or
11
+
12
+ yarn add @travetto/terminal
9
13
  ```
14
+
15
+ This module provides basic support for interacting with the terminal, and provides the basis for output colorization and the basic command line interactions. The functionality can be broken down into:
16
+
17
+
18
+ * Output Colorization
19
+ * Terminal Interactions
20
+
21
+ ## Output Colorization
22
+
23
+ Oddly enough, colorizing output in a terminal is a fairly complex process. The standards are somewhat inconsistent and detection can be a tricky process. For terminals, [Node](https://nodejs.org) supports 4 different levels of coloring:
24
+
25
+ * 0 - One color, essentially uncolored output
26
+ * 1 - Basic color support, 16 colors
27
+ * 2 - Enhanced color support, 225 colors, providing a fair representation of most colors
28
+ * 3 - True color, 24bit color with R, G, B each getting 8-bits. Can represent any color needed
29
+
30
+ This module provides the ability to define color palettes using RGB or [named colors](https://github.com/travetto/travetto/tree/main/module/terminal/src/named-colors.ts#L1) modeled after the standard HTML color names. The module also provides the ability to specify palettes based on a dark or light background for a given terminal. Support for this is widespread, but when it fails, it will gracefully assume a dark background.
31
+
32
+ These palettes then are usable at runtime, with the module determine light or dark palettes, as well as falling back to the closest color value based on what the existing terminal supports. This means a color like 'olivegreen', will get the proper output in 24bit color support, a close approximation in enhanced color support, fall back to green in basic color support, and will be color less at level 0.
33
+
34
+ **Code: CLI Color Palette**
35
+ ```typescript
36
+ import { Util } from '@travetto/base';
37
+ import { GlobalTerminal } from '@travetto/terminal';
38
+
39
+ const tplFn = GlobalTerminal.templateFunction({
40
+ input: 'oliveDrab',
41
+ output: 'pink',
42
+ path: 'teal',
43
+ success: 'green',
44
+ failure: 'red',
45
+ param: 'yellow',
46
+ type: 'cyan',
47
+ description: 'white',
48
+ title: 'brightWhite',
49
+ identifier: 'dodgerBlue',
50
+ subtitle: 'lightGray',
51
+ subsubtitle: 'darkGray'
52
+ });
53
+
54
+ export const cliTpl = Util.makeTemplate(tplFn);
55
+ ```
56
+
57
+ When the color palette is combined with [Base](https://github.com/travetto/travetto/tree/main/module/base#readme "Environment config and common utilities for travetto applications.")'s Util.makeTemplate, you produce a string template function that will automatically colorize:
58
+
59
+ **Code: Sample Template Usage**
60
+ ```typescript
61
+ cliTpl`Build finished: status=${{success: "complete"}}, output=${{path: "/build.zip"}}`
62
+ ```
63
+
64
+ This would then produce colorized output based on the palette, and the terminal capabilities.
65
+
66
+ This module follows the pattern [Node](https://nodejs.org) follows with respect to the environment variables: `NO_COLOR`, `FORCE_COLOR` and `NODE_DISABLE_COLORS`
67
+
68
+ **Terminal: Node help on colors**
69
+ ```bash
70
+ $ /usr/bin/node -h | grep -i color
71
+
72
+ FORCE_COLOR when set to 'true', 1, 2, 3, or an
73
+ empty string causes NO_COLOR and
74
+ NODE_DISABLE_COLORS to be ignored.
75
+ NO_COLOR Alias for NODE_DISABLE_COLORS
76
+ NODE_DISABLE_COLORS set to 1 to disable colors in the REPL
77
+ ```
78
+
79
+ ## Terminal Interactions
80
+ Within the [Travetto](https://travetto.dev) framework, there are plenty of command line interactions that are enhanced with additional interactivity. This mainly revolves around indicating progress while a program is executing. The module provides support for:
81
+
82
+
83
+ * Progress Bars
84
+ * Waiting Indicators
85
+ * Streaming Content
86
+
87
+ This is generally meant for use within the framework, and so is highly tailored to the specific needs and scenarios. You can see this pattern play out in the [Compiler](https://github.com/travetto/travetto/tree/main/module/compiler#readme "The compiler infrastructure for the Travetto framework") progress output, or in [Pack](https://github.com/travetto/travetto/tree/main/module/pack#readme "Code packing utilities")'s output.
88
+
89
+ In these scenarios, the dynamic behaviors are dependent on having an interactive TTY. When running without access to a proper stdin, the output will default to basic line printing. This dynamic behavior can also be disabled using the environment variable `TRV_QUIET`. When set to `1` will provide a minimal text-based experience.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/terminal",
3
- "version": "3.0.0-rc.10",
3
+ "version": "3.0.0-rc.11",
4
4
  "description": "General terminal support",
5
5
  "keywords": [
6
6
  "terminal",