talented-args 0.2.5-beta → 0.3.0-beta
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/README.md +485 -14
- package/dist/clipboard.d.ts +10 -0
- package/dist/clipboard.js +79 -0
- package/dist/clipboard.js.map +1 -0
- package/dist/compile.d.ts +67 -0
- package/dist/compile.js +188 -0
- package/dist/compile.js.map +1 -0
- package/dist/descriptors.d.ts +322 -0
- package/dist/descriptors.js +362 -0
- package/dist/descriptors.js.map +1 -0
- package/dist/display.d.ts +31 -0
- package/dist/display.js +235 -0
- package/dist/display.js.map +1 -0
- package/dist/errors.d.ts +34 -17
- package/dist/errors.js +61 -75
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +10 -6
- package/dist/index.js +8 -9
- package/dist/index.js.map +1 -1
- package/dist/options.d.ts +69 -41
- package/dist/options.js +198 -31
- package/dist/options.js.map +1 -1
- package/dist/parse.d.ts +70 -0
- package/dist/parse.js +551 -0
- package/dist/parse.js.map +1 -0
- package/dist/program.d.ts +125 -0
- package/dist/program.js +337 -0
- package/dist/program.js.map +1 -0
- package/dist/remember.d.ts +71 -0
- package/dist/remember.js +216 -0
- package/dist/remember.js.map +1 -0
- package/dist/styling.d.ts +38 -9
- package/dist/styling.js +155 -75
- package/dist/styling.js.map +1 -1
- package/dist/terminal.d.ts +205 -0
- package/dist/terminal.js +152 -0
- package/dist/terminal.js.map +1 -0
- package/dist/tools.d.ts +35 -31
- package/dist/tools.js +68 -140
- package/dist/tools.js.map +1 -1
- package/dist/tui.d.ts +96 -0
- package/dist/tui.js +397 -0
- package/dist/tui.js.map +1 -0
- package/dist/tui_layout.d.ts +152 -0
- package/dist/tui_layout.js +554 -0
- package/dist/tui_layout.js.map +1 -0
- package/dist/tui_model.d.ts +149 -0
- package/dist/tui_model.js +666 -0
- package/dist/tui_model.js.map +1 -0
- package/package.json +18 -14
- package/.eslintrc.js +0 -24
- package/.idea/codeStyles/Project.xml +0 -364
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/compiler.xml +0 -7
- package/.idea/encodings.xml +0 -6
- package/.idea/inspectionProfiles/Project_Default.xml +0 -12
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/prettier.xml +0 -8
- package/.idea/talented-args.iml +0 -11
- package/.idea/vcs.xml +0 -6
- package/.prettierrc.yaml +0 -4
- package/dist/definitions.d.ts +0 -70
- package/dist/definitions.js +0 -38
- package/dist/definitions.js.map +0 -1
- package/dist/main.d.ts +0 -33
- package/dist/main.js +0 -313
- package/dist/main.js.map +0 -1
- package/jest.config.js +0 -4
- package/tsconfig.json +0 -18
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { IAttrColor, IAttrFlag, IPaint, ITextAttr } from './styling';
|
|
2
|
+
import { ITextTools } from './tools';
|
|
3
|
+
/**
|
|
4
|
+
* Adapter for terminal-kit, loaded only when rendering or editing is needed.
|
|
5
|
+
* Define and validate the subset of its untyped API used by this library.
|
|
6
|
+
*/
|
|
7
|
+
type ICapitalized<TColor extends string> = TColor extends `${infer TFirst}${infer TRest}` ? `${Uppercase<TFirst>}${TRest}` : never;
|
|
8
|
+
type IChainColor = Exclude<IAttrColor, 'default'>;
|
|
9
|
+
type IChainName = IAttrFlag | IChainColor | `bg${ICapitalized<IChainColor>}` | 'noFormat' | 'str';
|
|
10
|
+
/** Callable terminal style chain, such as `terminal.str.bold.cyan('text')`. */
|
|
11
|
+
export type IStyleChain = ((text: string) => string) & {
|
|
12
|
+
readonly [name in IChainName]: IStyleChain;
|
|
13
|
+
};
|
|
14
|
+
/** Input stream used to read terminal keys. */
|
|
15
|
+
export interface ITerminalInput extends NodeJS.ReadableStream {
|
|
16
|
+
isTTY?: boolean;
|
|
17
|
+
setRawMode?(mode: boolean): unknown;
|
|
18
|
+
}
|
|
19
|
+
/** Output stream used to render terminal content. */
|
|
20
|
+
export interface ITerminalOutput extends NodeJS.WritableStream {
|
|
21
|
+
isTTY?: boolean;
|
|
22
|
+
columns?: number;
|
|
23
|
+
rows?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface ICreateTerminalOptions {
|
|
26
|
+
stdin: ITerminalInput;
|
|
27
|
+
stdout: ITerminalOutput;
|
|
28
|
+
stderr: ITerminalOutput;
|
|
29
|
+
generic: string;
|
|
30
|
+
appId: string;
|
|
31
|
+
isTTY: boolean;
|
|
32
|
+
isSSH: boolean;
|
|
33
|
+
processSigwinch: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** Key event details accompanying the key name. */
|
|
36
|
+
export interface IKeyData {
|
|
37
|
+
readonly isCharacter: boolean;
|
|
38
|
+
}
|
|
39
|
+
export type IKeyListener = (key: string, altKeys: readonly string[], data: IKeyData) => void;
|
|
40
|
+
export type IResizeListener = (width: number, height: number) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Mutable cell attributes accepted by terminal-kit.
|
|
43
|
+
* Terminal-kit replaces color names with numbers in these objects.
|
|
44
|
+
* Use `toKitAttr()` to give each widget a fresh copy rather than sharing theme attributes.
|
|
45
|
+
*/
|
|
46
|
+
export type IKitAttr = {
|
|
47
|
+
-readonly [K in keyof ITextAttr]: ITextAttr[K] | number;
|
|
48
|
+
} & {
|
|
49
|
+
defaultColor?: boolean;
|
|
50
|
+
bgDefaultColor?: boolean;
|
|
51
|
+
readonly [KIT_ATTR]: true;
|
|
52
|
+
};
|
|
53
|
+
declare const KIT_ATTR: unique symbol;
|
|
54
|
+
export declare function toKitAttr(attr: ITextAttr): IKitAttr;
|
|
55
|
+
export interface IScreenCell {
|
|
56
|
+
readonly char: string;
|
|
57
|
+
readonly attr: Readonly<Record<string, unknown>>;
|
|
58
|
+
}
|
|
59
|
+
export interface IScreenBuffer {
|
|
60
|
+
readonly width: number;
|
|
61
|
+
readonly height: number;
|
|
62
|
+
readonly cx: number;
|
|
63
|
+
readonly cy: number;
|
|
64
|
+
get(position: {
|
|
65
|
+
x: number;
|
|
66
|
+
y: number;
|
|
67
|
+
}): IScreenCell | null;
|
|
68
|
+
}
|
|
69
|
+
export interface IElement {
|
|
70
|
+
readonly hasFocus: boolean;
|
|
71
|
+
draw(): unknown;
|
|
72
|
+
drawCursor(): unknown;
|
|
73
|
+
/** Set `noDraw` to skip redrawing the document after destruction. */
|
|
74
|
+
destroy(isSubDestroy?: boolean, noDraw?: boolean): void;
|
|
75
|
+
}
|
|
76
|
+
/** Text widget whose content can be updated in place. */
|
|
77
|
+
export interface ITextElement extends IElement {
|
|
78
|
+
attr: IKitAttr;
|
|
79
|
+
readonly outputWidth: number;
|
|
80
|
+
/** One string per line. Set `dontDraw` to defer drawing. */
|
|
81
|
+
setContent(content: readonly string[], hasMarkup: false, dontDraw: boolean): unknown;
|
|
82
|
+
}
|
|
83
|
+
export interface IElementOptions {
|
|
84
|
+
parent: IElement;
|
|
85
|
+
x: number;
|
|
86
|
+
y: number;
|
|
87
|
+
width: number;
|
|
88
|
+
height: number;
|
|
89
|
+
/** Defer drawing until all widgets have been created and the document can be drawn once. */
|
|
90
|
+
noDraw: true;
|
|
91
|
+
}
|
|
92
|
+
export interface ITextOptions extends IElementOptions {
|
|
93
|
+
/** One string per displayed line. */
|
|
94
|
+
content: readonly string[];
|
|
95
|
+
attr: IKitAttr;
|
|
96
|
+
}
|
|
97
|
+
export interface IButtonOptions extends IElementOptions {
|
|
98
|
+
content: string;
|
|
99
|
+
blurContent: string;
|
|
100
|
+
focusContent: string;
|
|
101
|
+
blurAttr: IKitAttr;
|
|
102
|
+
focusAttr: IKitAttr;
|
|
103
|
+
/** Widget key bindings. Empty because the model handles button navigation and actions. */
|
|
104
|
+
keyBindings: Readonly<Record<string, string>>;
|
|
105
|
+
}
|
|
106
|
+
export interface IEditableTextBoxOptions extends IElementOptions {
|
|
107
|
+
content: string;
|
|
108
|
+
textAttr: IKitAttr;
|
|
109
|
+
voidAttr: IKitAttr;
|
|
110
|
+
/** Replacement character used to mask text. */
|
|
111
|
+
hiddenContent?: string;
|
|
112
|
+
/** Widget text editing actions. The model handles keys not listed here. */
|
|
113
|
+
keyBindings: Readonly<Record<string, string>>;
|
|
114
|
+
/** Redraw delay after a key press, in milliseconds. Zero redraws immediately. */
|
|
115
|
+
debounceTimeout: number;
|
|
116
|
+
}
|
|
117
|
+
export interface IEditableTextBox extends IElement {
|
|
118
|
+
readonly textBuffer: {
|
|
119
|
+
moveToEndOfBuffer(): void;
|
|
120
|
+
};
|
|
121
|
+
getValue(): string;
|
|
122
|
+
on(event: 'change', listener: () => void): unknown;
|
|
123
|
+
}
|
|
124
|
+
export interface IDocument extends IElement {
|
|
125
|
+
/** Rendered screen cells, available for inspection. */
|
|
126
|
+
readonly inputDst: IScreenBuffer;
|
|
127
|
+
/**
|
|
128
|
+
* Forward a terminal key to the focused widget.
|
|
129
|
+
* Emit a document key event if the widget does not handle it.
|
|
130
|
+
*/
|
|
131
|
+
readonly onEventSourceKey: IKeyListener;
|
|
132
|
+
/** Resize the document and redraw its widgets to match the terminal dimensions. */
|
|
133
|
+
readonly onEventSourceResize: IResizeListener;
|
|
134
|
+
giveFocusTo(element: IElement): unknown;
|
|
135
|
+
on(event: 'key', listener: IKeyListener): unknown;
|
|
136
|
+
}
|
|
137
|
+
export interface IDocumentOptions {
|
|
138
|
+
/** Document key bindings. Empty because the model handles navigation. */
|
|
139
|
+
keyBindings: Readonly<Record<string, string>>;
|
|
140
|
+
backgroundAttr: IKitAttr;
|
|
141
|
+
/**
|
|
142
|
+
* Preserve the terminal's existing input setup.
|
|
143
|
+
* Without this option, document creation enables mouse tracking.
|
|
144
|
+
*/
|
|
145
|
+
noInput: true;
|
|
146
|
+
}
|
|
147
|
+
export interface ITerminal {
|
|
148
|
+
width: number;
|
|
149
|
+
height: number;
|
|
150
|
+
/** Whether terminal-kit has shut down and should stop using its streams. */
|
|
151
|
+
shutdown: boolean;
|
|
152
|
+
readonly str: IStyleChain;
|
|
153
|
+
/** Enter the alternate screen with `true`, or restore the original screen with `false`. */
|
|
154
|
+
fullscreen(options: boolean): unknown;
|
|
155
|
+
/** Start reading keys with `{}`, or stop with `false`. */
|
|
156
|
+
grabInput(options: false | Record<string, never>): unknown;
|
|
157
|
+
hideCursor(hide?: boolean): unknown;
|
|
158
|
+
styleReset(): unknown;
|
|
159
|
+
createDocument(options: IDocumentOptions): IDocument;
|
|
160
|
+
on(event: 'resize', listener: IResizeListener): unknown;
|
|
161
|
+
on(event: 'key', listener: IKeyListener): unknown;
|
|
162
|
+
off(event: 'resize', listener: IResizeListener): unknown;
|
|
163
|
+
off(event: 'key', listener: IKeyListener): unknown;
|
|
164
|
+
emit(event: 'key', key: string, altKeys: readonly string[], data: IKeyData): unknown;
|
|
165
|
+
}
|
|
166
|
+
export interface ITerminalGuess {
|
|
167
|
+
readonly isSSH: boolean;
|
|
168
|
+
readonly appId: string;
|
|
169
|
+
readonly generic: string;
|
|
170
|
+
}
|
|
171
|
+
export interface ITerminalKit {
|
|
172
|
+
createTerminal(options: ICreateTerminalOptions): ITerminal;
|
|
173
|
+
/**
|
|
174
|
+
* Detect terminal capabilities from the environment.
|
|
175
|
+
* Set `unpipe` to detect capabilities even when process stdout is redirected,
|
|
176
|
+
* because the editor may use a different terminal output stream.
|
|
177
|
+
*/
|
|
178
|
+
guessTerminal(unpipe: boolean): ITerminalGuess;
|
|
179
|
+
stringWidth(text: string): number;
|
|
180
|
+
truncateString(text: string, maxWidth: number): string;
|
|
181
|
+
wordWrapAnsi(text: string, width: number): string[];
|
|
182
|
+
Text: new (options: ITextOptions) => ITextElement;
|
|
183
|
+
Button: new (options: IButtonOptions) => IElement;
|
|
184
|
+
EditableTextBox: new (options: IEditableTextBoxOptions) => IEditableTextBox;
|
|
185
|
+
}
|
|
186
|
+
export declare function loadTerminalKit(): ITerminalKit;
|
|
187
|
+
export declare function createTextTools(kit?: ITerminalKit,
|
|
188
|
+
/** Suffix added when text is truncated. */
|
|
189
|
+
ellipsis?: string): ITextTools;
|
|
190
|
+
/** Create a painter using the terminal's styling escape sequences. */
|
|
191
|
+
export declare function createPaint(terminal: ITerminal): IPaint;
|
|
192
|
+
export interface ITerminalSession {
|
|
193
|
+
readonly kit: ITerminalKit;
|
|
194
|
+
readonly terminal: ITerminal;
|
|
195
|
+
/**
|
|
196
|
+
* Stop terminal-kit from using the streams and remove session listeners.
|
|
197
|
+
* The caller must restore any screen or input mode changes before releasing the session.
|
|
198
|
+
*/
|
|
199
|
+
release(): void;
|
|
200
|
+
}
|
|
201
|
+
/** Create a separate terminal instance for a session on the supplied streams. */
|
|
202
|
+
export declare function openTerminal(stdin: ITerminalInput, stdout: ITerminalOutput, kit?: ITerminalKit,
|
|
203
|
+
/** Use fallback styling capabilities if terminal detection reports an incapable terminal. */
|
|
204
|
+
forceCapable?: boolean): ITerminalSession;
|
|
205
|
+
export {};
|
package/dist/terminal.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toKitAttr = toKitAttr;
|
|
4
|
+
exports.loadTerminalKit = loadTerminalKit;
|
|
5
|
+
exports.createTextTools = createTextTools;
|
|
6
|
+
exports.createPaint = createPaint;
|
|
7
|
+
exports.openTerminal = openTerminal;
|
|
8
|
+
const styling_1 = require("./styling");
|
|
9
|
+
function toKitAttr(attr) {
|
|
10
|
+
// The brand is type-only; copying the attributes supplies the runtime object.
|
|
11
|
+
return { ...attr };
|
|
12
|
+
}
|
|
13
|
+
const KIT_MEMBERS = [
|
|
14
|
+
'createTerminal',
|
|
15
|
+
'guessTerminal',
|
|
16
|
+
'stringWidth',
|
|
17
|
+
'truncateString',
|
|
18
|
+
'wordWrapAnsi',
|
|
19
|
+
'Text',
|
|
20
|
+
'Button',
|
|
21
|
+
'EditableTextBox',
|
|
22
|
+
];
|
|
23
|
+
function isTerminalKit(value) {
|
|
24
|
+
if (typeof value !== 'object' || value === null) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const candidate = value;
|
|
28
|
+
return KIT_MEMBERS.every(member => typeof candidate[member] === 'function');
|
|
29
|
+
}
|
|
30
|
+
let loadedKit;
|
|
31
|
+
function loadTerminalKit() {
|
|
32
|
+
if (!loadedKit) {
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
34
|
+
const kit = require('terminal-kit');
|
|
35
|
+
if (!isTerminalKit(kit)) {
|
|
36
|
+
throw new TypeError('terminal-kit is installed in a version this library does not know how to use');
|
|
37
|
+
}
|
|
38
|
+
loadedKit = kit;
|
|
39
|
+
}
|
|
40
|
+
return loadedKit;
|
|
41
|
+
}
|
|
42
|
+
// *********************************************************************************************************************
|
|
43
|
+
function createTextTools(kit = loadTerminalKit(),
|
|
44
|
+
/** Suffix added when text is truncated. */
|
|
45
|
+
ellipsis = '…') {
|
|
46
|
+
const ellipsisWidth = kit.stringWidth(ellipsis);
|
|
47
|
+
return {
|
|
48
|
+
width: text => kit.stringWidth(text),
|
|
49
|
+
// Trim padding added by terminal-kit, which can extend wrapped lines past the requested width.
|
|
50
|
+
wrap: (text, width) => text
|
|
51
|
+
.split('\n')
|
|
52
|
+
.flatMap(line => (line ? kit.wordWrapAnsi(line, Math.max(1, width)) : ['']))
|
|
53
|
+
.map(line => line.trimEnd()),
|
|
54
|
+
truncate: (text, width) => {
|
|
55
|
+
if (kit.stringWidth(text) <= width) {
|
|
56
|
+
return text;
|
|
57
|
+
}
|
|
58
|
+
return width <= ellipsisWidth
|
|
59
|
+
? kit.truncateString(text, Math.max(0, width))
|
|
60
|
+
: kit.truncateString(text, width - ellipsisWidth) + ellipsis;
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function capitalize(color) {
|
|
65
|
+
return color.charAt(0).toUpperCase() + color.slice(1);
|
|
66
|
+
}
|
|
67
|
+
/** Create a painter using the terminal's styling escape sequences. */
|
|
68
|
+
function createPaint(terminal) {
|
|
69
|
+
return (rawText, attr) => {
|
|
70
|
+
// Disable format interpretation so literal % and ^ characters are preserved.
|
|
71
|
+
let chain = terminal.str.noFormat;
|
|
72
|
+
if (attr.color !== 'default') {
|
|
73
|
+
chain = chain[attr.color];
|
|
74
|
+
}
|
|
75
|
+
if (attr.bgColor !== 'default') {
|
|
76
|
+
chain = chain[`bg${capitalize(attr.bgColor)}`];
|
|
77
|
+
}
|
|
78
|
+
for (const flag of (0, styling_1.attrFlags)(attr)) {
|
|
79
|
+
chain = chain[flag];
|
|
80
|
+
}
|
|
81
|
+
return chain(rawText);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
// *********************************************************************************************************************
|
|
85
|
+
/** Fallback dimensions when the terminal does not report a valid size. */
|
|
86
|
+
const FALLBACK_SIZE = { width: 80, height: 24 };
|
|
87
|
+
/** Fallback terminal capabilities when styling is explicitly requested without a capable terminal. */
|
|
88
|
+
const FALLBACK_TERMINAL = 'xterm-256color';
|
|
89
|
+
/** Process events that terminal-kit subscribes to and the session must later release. */
|
|
90
|
+
const HOOKED_PROCESS_EVENTS = ['exit', 'asyncExit', 'beforeExit', 'SIGWINCH'];
|
|
91
|
+
function isListener(value) {
|
|
92
|
+
return typeof value === 'function';
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Run a callback and track the listeners it adds.
|
|
96
|
+
* Return a cleanup function that removes only those listeners, preserving listeners added later.
|
|
97
|
+
*/
|
|
98
|
+
function trackAddedListeners(source, events, add) {
|
|
99
|
+
const before = new Map(events.map(event => [event, new Set(source.listeners(event))]));
|
|
100
|
+
const result = add();
|
|
101
|
+
const added = events.flatMap(event => source
|
|
102
|
+
.listeners(event)
|
|
103
|
+
.filter(listener => !before.get(event)?.has(listener))
|
|
104
|
+
.filter(isListener)
|
|
105
|
+
.map(listener => ({ event, listener })));
|
|
106
|
+
return {
|
|
107
|
+
result,
|
|
108
|
+
remove: () => {
|
|
109
|
+
for (const { event, listener } of added) {
|
|
110
|
+
source.removeListener(event, listener);
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** Create a separate terminal instance for a session on the supplied streams. */
|
|
116
|
+
function openTerminal(stdin, stdout, kit = loadTerminalKit(),
|
|
117
|
+
/** Use fallback styling capabilities if terminal detection reports an incapable terminal. */
|
|
118
|
+
forceCapable = false) {
|
|
119
|
+
const guess = kit.guessTerminal(true);
|
|
120
|
+
const incapable = guess.generic === 'none' || guess.generic === 'dumb';
|
|
121
|
+
// Track terminal-kit's process and output listeners so release removes only this session's listeners.
|
|
122
|
+
const onProcess = trackAddedListeners(process, HOOKED_PROCESS_EVENTS, () => trackAddedListeners(stdout, ['resize'], () => kit.createTerminal({
|
|
123
|
+
stdin,
|
|
124
|
+
stdout,
|
|
125
|
+
stderr: stdout,
|
|
126
|
+
generic: forceCapable && incapable ? FALLBACK_TERMINAL : guess.generic,
|
|
127
|
+
appId: forceCapable && incapable ? FALLBACK_TERMINAL : guess.appId,
|
|
128
|
+
isTTY: true,
|
|
129
|
+
isSSH: guess.isSSH,
|
|
130
|
+
processSigwinch: false,
|
|
131
|
+
})));
|
|
132
|
+
const onOutput = onProcess.result;
|
|
133
|
+
const terminal = onOutput.result;
|
|
134
|
+
if (!(terminal.width > 0 &&
|
|
135
|
+
terminal.height > 0 &&
|
|
136
|
+
Number.isFinite(terminal.width + terminal.height))) {
|
|
137
|
+
// Use stream dimensions or fallback values when terminal-kit cannot determine the size,
|
|
138
|
+
// as can happen with redirected streams or terminals that omit their dimensions.
|
|
139
|
+
terminal.width = stdout.columns || FALLBACK_SIZE.width;
|
|
140
|
+
terminal.height = stdout.rows || FALLBACK_SIZE.height;
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
kit,
|
|
144
|
+
terminal,
|
|
145
|
+
release: () => {
|
|
146
|
+
terminal.shutdown = true;
|
|
147
|
+
onProcess.remove();
|
|
148
|
+
onOutput.remove();
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=terminal.js.map
|
|
@@ -0,0 +1 @@
|
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CAAC,KAAK;QAClE,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,eAAe,EAAE,KAAK;KACvB,CAAC,CACH,CACF,CAAC;IACF,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC;IAClC,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC;IAEjC,IACE,CAAC,CACC,QAAQ,CAAC,KAAK,GAAG,CAAC;QAClB,QAAQ,CAAC,MAAM,GAAG,CAAC;QACnB,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAClD,EACD,CAAC;QACD,wFAAwF;QACxF,iFAAiF;QACjF,QAAQ,CAAC,KAAK,GAAG,MAAM,CAAC,OAAO,IAAI,aAAa,CAAC,KAAK,CAAC;QACvD,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI,IAAI,aAAa,CAAC,MAAM,CAAC;IACxD,CAAC;IAED,OAAO;QACL,GAAG;QACH,QAAQ;QACR,OAAO,EAAE,GAAG,EAAE;YACZ,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAAC;YACzB,SAAS,CAAC,MAAM,EAAE,CAAC;YACnB,QAAQ,CAAC,MAAM,EAAE,CAAC;QACpB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/tools.d.ts
CHANGED
|
@@ -1,35 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare function
|
|
8
|
-
|
|
9
|
-
declare
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export declare
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* - Merge constructed objects which have static type deepMerge
|
|
19
|
-
* - Arrays are not merged, new array overwrites the old one (unless MERGE_ARRAYS is set on constructor)
|
|
20
|
-
* - Undefineds are ignored
|
|
21
|
-
*/
|
|
22
|
-
export declare function deepMerge<TObject extends AnyRecord>(target: Partial<TObject>, ...sources: Partial<TObject>[]): TObject;
|
|
23
|
-
export declare namespace deepMerge {
|
|
24
|
-
var FORCE_CLEAN_MERGE: string;
|
|
25
|
-
var MERGE_ARRAYS: string;
|
|
1
|
+
/** Expand an intersection into one object type for readable editor tooltips. */
|
|
2
|
+
export type ISimplify<T> = {
|
|
3
|
+
[K in keyof T]: T[K];
|
|
4
|
+
} & {};
|
|
5
|
+
/** Object with string keys and unknown value types. */
|
|
6
|
+
export type IUnknownRecord = Record<string, unknown>;
|
|
7
|
+
export declare function isPlainObject(value: unknown): value is IUnknownRecord;
|
|
8
|
+
/** Create an object with the supplied keys, using the callback to produce each value. */
|
|
9
|
+
export declare function fromKeys<TKey extends string, TValue>(keys: readonly TKey[], create: (key: TKey) => TValue): {
|
|
10
|
+
[key in TKey]: TValue;
|
|
11
|
+
};
|
|
12
|
+
/** Return a map's existing non-undefined value, or create and store one with the callback. */
|
|
13
|
+
export declare function getOrCreate<TKey, TValue>(map: Map<TKey, TValue>, key: TKey, create: () => TValue): TValue;
|
|
14
|
+
export interface IDeferred<TValue> {
|
|
15
|
+
readonly promise: Promise<TValue>;
|
|
16
|
+
resolve(value: TValue): void;
|
|
17
|
+
reject(reason: unknown): void;
|
|
26
18
|
}
|
|
19
|
+
/** Create a promise with externally accessible `resolve` and `reject` functions. */
|
|
20
|
+
export declare function createDeferred<TValue>(): IDeferred<TValue>;
|
|
21
|
+
/** Format a quoted list for a sentence: `"a", "b" and "c"`. */
|
|
22
|
+
export declare function quoteList(items: readonly string[], conjunction?: string): string;
|
|
23
|
+
export declare function isThenable(value: unknown): value is PromiseLike<unknown>;
|
|
24
|
+
/** Extract a string message from a thrown value, or convert the value to a string. */
|
|
25
|
+
export declare function describeThrown(thrown: unknown): string;
|
|
27
26
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
27
|
+
* Measure, wrap, and truncate text by terminal cell width.
|
|
28
|
+
* Accounts for wide characters such as CJK characters and emoji.
|
|
30
29
|
*/
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
export interface ITextTools {
|
|
31
|
+
/** Text width in terminal cells. */
|
|
32
|
+
width(text: string): number;
|
|
33
|
+
/** Wrap text to the specified cell width, preserving existing line breaks. */
|
|
34
|
+
wrap(text: string, width: number): string[];
|
|
35
|
+
/** Truncate text to the specified cell width, adding an ellipsis when text is removed. */
|
|
36
|
+
truncate(text: string, width: number): string;
|
|
34
37
|
}
|
|
35
|
-
|
|
38
|
+
/** Pad text on the right with spaces to the specified terminal cell width. */
|
|
39
|
+
export declare function padEnd(text: string, width: number, tools: ITextTools): string;
|