@uniflowed/tui 0.0.0-alpha.18 → 0.15.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/capability.js +15 -12
- package/cells.js +1 -1
- package/clipboard.js +61 -0
- package/components.js +766 -57
- package/index.js +41 -22
- package/internal/hits.js +2 -2
- package/internal/host.js +63 -22
- package/internal/paint.js +43 -2
- package/internal/tree.js +168 -38
- package/internal/widgets.js +771 -0
- package/keys.js +214 -15
- package/layout.js +653 -132
- package/package.json +5 -4
- package/terminal.js +49 -19
- package/widths.js +4 -1
package/capability.js
CHANGED
|
@@ -42,17 +42,20 @@ export type ColorChoice = "auto" | "always" | "never";
|
|
|
42
42
|
|
|
43
43
|
/** The environment variables that influence terminal rendering. */
|
|
44
44
|
export type TerminalEnv = {
|
|
45
|
-
readonly NO_COLOR?: string,
|
|
46
|
-
readonly FORCE_COLOR?: string,
|
|
47
|
-
readonly CLICOLOR?: string,
|
|
48
|
-
readonly CLICOLOR_FORCE?: string,
|
|
49
|
-
readonly TERM?: string,
|
|
50
|
-
readonly COLORTERM?: string,
|
|
51
|
-
readonly COLUMNS?: string,
|
|
52
|
-
readonly LINES?: string,
|
|
53
|
-
readonly LC_ALL?: string,
|
|
54
|
-
readonly LC_CTYPE?: string,
|
|
55
|
-
readonly LANG?: string,
|
|
45
|
+
readonly NO_COLOR?: string | void,
|
|
46
|
+
readonly FORCE_COLOR?: string | void,
|
|
47
|
+
readonly CLICOLOR?: string | void,
|
|
48
|
+
readonly CLICOLOR_FORCE?: string | void,
|
|
49
|
+
readonly TERM?: string | void,
|
|
50
|
+
readonly COLORTERM?: string | void,
|
|
51
|
+
readonly COLUMNS?: string | void,
|
|
52
|
+
readonly LINES?: string | void,
|
|
53
|
+
readonly LC_ALL?: string | void,
|
|
54
|
+
readonly LC_CTYPE?: string | void,
|
|
55
|
+
readonly LANG?: string | void,
|
|
56
|
+
// `process.env` names every variable the process has, and this type
|
|
57
|
+
// only the ones rendering reads.
|
|
58
|
+
...
|
|
56
59
|
};
|
|
57
60
|
|
|
58
61
|
/** The resolved rendering capability of one stream. */
|
|
@@ -263,7 +266,7 @@ const usable = (value: number | void): number | null =>
|
|
|
263
266
|
* Resolve how big the terminal is.
|
|
264
267
|
*
|
|
265
268
|
* Precedence, highest first — this list is `crates/uf_term/src/capability.rs`'s
|
|
266
|
-
* `detect_size`, chain for chain, and `
|
|
269
|
+
* `detect_size`, chain for chain, and `npm/tui/tui.test.js` compares the
|
|
267
270
|
* two rather than believing this sentence:
|
|
268
271
|
*
|
|
269
272
|
* 1. `COLUMNS` and `LINES`, each on its own. POSIX makes them the override,
|
package/cells.js
CHANGED
|
@@ -185,7 +185,7 @@ export type Rect = {
|
|
|
185
185
|
/** A frame of blanks, `width` by `height`. */
|
|
186
186
|
export function createFrame(width: number, height: number): Frame {
|
|
187
187
|
const size = Math.max(0, width * height);
|
|
188
|
-
const chars = new Array(size);
|
|
188
|
+
const chars = new Array<string>(size);
|
|
189
189
|
for (let i = 0; i < size; i += 1) {
|
|
190
190
|
chars[i] = " ";
|
|
191
191
|
}
|
package/clipboard.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
//
|
|
3
|
+
// The terminal clipboard this package implements: OSC 52, write-only.
|
|
4
|
+
//
|
|
5
|
+
// OSC 52 is not a clipboard *service* in the browser sense. It is an escape
|
|
6
|
+
// sequence sent to the terminal emulator, and the emulator may accept it,
|
|
7
|
+
// ignore it, ask the reader, or cap the payload. There is no acknowledgement
|
|
8
|
+
// on the same stream, so `copy()` reports whether uf could ask, not whether a
|
|
9
|
+
// terminal eventually changed its clipboard.
|
|
10
|
+
|
|
11
|
+
/** What `useClipboard()` hands back. */
|
|
12
|
+
export type Clipboard = {
|
|
13
|
+
/** Put text on the terminal clipboard. */
|
|
14
|
+
copy(text: string): boolean,
|
|
15
|
+
/** Whether this renderer has a clipboard transport at all. */
|
|
16
|
+
supported: boolean,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
20
|
+
|
|
21
|
+
/** A clipboard for renderers that have nowhere to send OSC 52. */
|
|
22
|
+
export const unsupportedClipboard: Clipboard = {
|
|
23
|
+
supported: false,
|
|
24
|
+
copy() {
|
|
25
|
+
return false;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** A clipboard that writes OSC 52 to a terminal stream. */
|
|
30
|
+
export function osc52Clipboard(write: (chunk: string) => mixed): Clipboard {
|
|
31
|
+
return {
|
|
32
|
+
supported: true,
|
|
33
|
+
copy(text: string): boolean {
|
|
34
|
+
write(osc52(text));
|
|
35
|
+
return true;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Encode text as the OSC 52 "copy to clipboard" sequence. */
|
|
41
|
+
export function osc52(text: string): string {
|
|
42
|
+
return `\u001b]52;c;${base64Utf8(text)}\u0007`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function base64Utf8(text: string): string {
|
|
46
|
+
return base64Bytes(new TextEncoder().encode(text));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function base64Bytes(bytes: Uint8Array): string {
|
|
50
|
+
let out = "";
|
|
51
|
+
for (let at = 0; at < bytes.length; at += 3) {
|
|
52
|
+
const first = bytes[at];
|
|
53
|
+
const second = bytes[at + 1];
|
|
54
|
+
const third = bytes[at + 2];
|
|
55
|
+
out += ALPHABET[first >> 2];
|
|
56
|
+
out += ALPHABET[((first & 0b00000011) << 4) | ((second ?? 0) >> 4)];
|
|
57
|
+
out += second == null ? "=" : ALPHABET[((second & 0b00001111) << 2) | ((third ?? 0) >> 6)];
|
|
58
|
+
out += third == null ? "=" : ALPHABET[third & 0b00111111];
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|