@travetto/terminal 3.0.0-rc.7 → 3.0.0-rc.9
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/package.json +1 -1
- package/src/operation.ts +8 -5
- package/src/query.ts +17 -1
- package/src/terminal.ts +5 -2
- package/src/types.ts +1 -1
package/package.json
CHANGED
package/src/operation.ts
CHANGED
|
@@ -96,19 +96,20 @@ export class TerminalOperation {
|
|
|
96
96
|
/**
|
|
97
97
|
* Stream lines with a waiting indicator
|
|
98
98
|
*/
|
|
99
|
-
static async streamLinesWithWaiting(term: TermState, lines: AsyncIterable<string>, cfg: TerminalWaitingConfig = {}): Promise<void> {
|
|
99
|
+
static async streamLinesWithWaiting(term: TermState, lines: AsyncIterable<string | undefined>, cfg: TerminalWaitingConfig = {}): Promise<void> {
|
|
100
100
|
let writer: (() => Promise<unknown>) | undefined;
|
|
101
101
|
let line: string | undefined;
|
|
102
102
|
|
|
103
103
|
const commitLine = async (): Promise<void> => {
|
|
104
104
|
await writer?.();
|
|
105
105
|
if (line) {
|
|
106
|
-
const msg = `${
|
|
106
|
+
const msg = cfg.committedPrefix ? `${cfg.committedPrefix} ${line}` : line;
|
|
107
107
|
if (cfg.position === 'inline') {
|
|
108
108
|
await TerminalWriter.for(term).setPosition({ x: 0 }).changePosition({ y: -1 }).writeLine(msg).commit();
|
|
109
109
|
} else {
|
|
110
110
|
await TerminalWriter.for(term).writeLine(msg).commit();
|
|
111
111
|
}
|
|
112
|
+
line = undefined;
|
|
112
113
|
}
|
|
113
114
|
};
|
|
114
115
|
|
|
@@ -116,9 +117,11 @@ export class TerminalOperation {
|
|
|
116
117
|
|
|
117
118
|
for await (let msg of lines) {
|
|
118
119
|
await commitLine();
|
|
119
|
-
msg
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
if (msg !== undefined) {
|
|
121
|
+
msg = msg.replace(/\n$/, '');
|
|
122
|
+
writer = this.streamWaiting(term, msg, cfg, pos);
|
|
123
|
+
line = msg;
|
|
124
|
+
}
|
|
122
125
|
}
|
|
123
126
|
await commitLine();
|
|
124
127
|
}
|
package/src/query.ts
CHANGED
|
@@ -50,7 +50,16 @@ export class TerminalQuerier {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
async #readInput(query: string): Promise<Buffer> {
|
|
53
|
+
const isRaw = this.#input.isRaw;
|
|
54
|
+
const isPaused = this.#input.isPaused();
|
|
55
|
+
const data = this.#input.listeners('data');
|
|
53
56
|
try {
|
|
57
|
+
this.#input.removeAllListeners('data');
|
|
58
|
+
|
|
59
|
+
if (isPaused) {
|
|
60
|
+
this.#input.resume();
|
|
61
|
+
}
|
|
62
|
+
|
|
54
63
|
this.#input.setRawMode(true);
|
|
55
64
|
// Send data, but do not wait on it
|
|
56
65
|
this.#output.write(query);
|
|
@@ -58,7 +67,14 @@ export class TerminalQuerier {
|
|
|
58
67
|
const val: Buffer | string = this.#input.read();
|
|
59
68
|
return typeof val === 'string' ? Buffer.from(val, 'utf8') : val;
|
|
60
69
|
} finally {
|
|
61
|
-
|
|
70
|
+
if (isPaused) {
|
|
71
|
+
this.#input.pause();
|
|
72
|
+
}
|
|
73
|
+
this.#input.setRawMode(isRaw);
|
|
74
|
+
for (const fn of data) {
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
this.#input.on('data', fn);
|
|
77
|
+
}
|
|
62
78
|
}
|
|
63
79
|
}
|
|
64
80
|
|
package/src/terminal.ts
CHANGED
|
@@ -128,10 +128,13 @@ export class Terminal implements TermState {
|
|
|
128
128
|
* @param config
|
|
129
129
|
* @returns
|
|
130
130
|
*/
|
|
131
|
-
async streamLinesWithWaiting(lines: AsyncIterable<string>, config: TerminalWaitingConfig): Promise<void> {
|
|
131
|
+
async streamLinesWithWaiting(lines: AsyncIterable<string | undefined>, config: TerminalWaitingConfig): Promise<void> {
|
|
132
132
|
if (!this.interactive) {
|
|
133
133
|
for await (const line of lines) {
|
|
134
|
-
|
|
134
|
+
if (line !== undefined) {
|
|
135
|
+
const out = config.committedPrefix ? `${config.committedPrefix} ${line}` : line;
|
|
136
|
+
await this.writeLines(out);
|
|
137
|
+
}
|
|
135
138
|
}
|
|
136
139
|
} else {
|
|
137
140
|
return TerminalOperation.streamLinesWithWaiting(this, lines, { position: 'bottom', ...config });
|
package/src/types.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type TerminalTableEvent = { idx: number, text: string, done?: boolean };
|
|
|
13
13
|
export type TerminalTableConfig = { header?: string[], forceNonInteractiveOrder?: boolean };
|
|
14
14
|
export type TerminalProgressEvent = { idx: number, total?: number, text?: string };
|
|
15
15
|
export type TerminalProgressRender = (ev: TerminalProgressEvent) => string;
|
|
16
|
-
export type TerminalWaitingConfig = { position?: TermLinePosition, end?: boolean } & DelayedConfig;
|
|
16
|
+
export type TerminalWaitingConfig = { position?: TermLinePosition, end?: boolean, committedPrefix?: string } & DelayedConfig;
|
|
17
17
|
|
|
18
18
|
export type TermColorLevel = 0 | 1 | 2 | 3;
|
|
19
19
|
export type TermColorScheme = 'dark' | 'light';
|