@travetto/terminal 3.0.0-rc.6 → 3.0.0-rc.7
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 +17 -10
- package/src/terminal.ts +3 -2
package/package.json
CHANGED
package/src/operation.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IterableUtil } from './iterable';
|
|
2
2
|
import { TerminalWriter } from './writer';
|
|
3
|
-
import { Indexed, TerminalProgressRender, TerminalWaitingConfig, TermLinePosition, TermState } from './types';
|
|
3
|
+
import { Indexed, TermCoord, TerminalProgressRender, TerminalWaitingConfig, TermLinePosition, TermState } from './types';
|
|
4
4
|
import { ColorOutputUtil, TermStyleInput } from './color-output';
|
|
5
5
|
|
|
6
6
|
const STD_WAIT_STATES = '⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'.split('');
|
|
@@ -10,8 +10,8 @@ export class TerminalOperation {
|
|
|
10
10
|
/**
|
|
11
11
|
* Allows for writing at top, bottom, or current position while new text is added
|
|
12
12
|
*/
|
|
13
|
-
static async streamToPosition(term: TermState, source: AsyncIterable<string>, pos: TermLinePosition = 'inline'): Promise<void> {
|
|
14
|
-
|
|
13
|
+
static async streamToPosition(term: TermState, source: AsyncIterable<string>, pos: TermLinePosition = 'inline', curPos?: TermCoord): Promise<void> {
|
|
14
|
+
curPos ??= { ...await term.getCursorPosition() };
|
|
15
15
|
const writePos = pos === 'inline' ?
|
|
16
16
|
{ ...curPos, x: 0 } :
|
|
17
17
|
{ x: 0, y: pos === 'top' ? 0 : -1 };
|
|
@@ -59,7 +59,7 @@ export class TerminalOperation {
|
|
|
59
59
|
/**
|
|
60
60
|
* Waiting indicator, streamed to a specific position, can be canceled
|
|
61
61
|
*/
|
|
62
|
-
static streamWaiting(term: TermState, message: string, config: TerminalWaitingConfig = {}): () => Promise<void> {
|
|
62
|
+
static streamWaiting(term: TermState, message: string, config: TerminalWaitingConfig = {}, curPos?: TermCoord): () => Promise<void> {
|
|
63
63
|
const { stop, stream } = IterableUtil.cycle(STD_WAIT_STATES);
|
|
64
64
|
const indicator = IterableUtil.map(
|
|
65
65
|
stream,
|
|
@@ -67,7 +67,7 @@ export class TerminalOperation {
|
|
|
67
67
|
(ch, i) => config.end ? `${message} ${ch}` : (i === 0 ? `${ch} ${message}` : ch)
|
|
68
68
|
);
|
|
69
69
|
|
|
70
|
-
const final = this.streamToPosition(term, indicator, config.position ?? 'inline');
|
|
70
|
+
const final = this.streamToPosition(term, indicator, config.position ?? 'inline', curPos);
|
|
71
71
|
return async () => { stop(); return final; };
|
|
72
72
|
}
|
|
73
73
|
|
|
@@ -103,16 +103,23 @@ export class TerminalOperation {
|
|
|
103
103
|
const commitLine = async (): Promise<void> => {
|
|
104
104
|
await writer?.();
|
|
105
105
|
if (line) {
|
|
106
|
-
|
|
106
|
+
const msg = `${String.fromCharCode(171)} ${line}`;
|
|
107
|
+
if (cfg.position === 'inline') {
|
|
108
|
+
await TerminalWriter.for(term).setPosition({ x: 0 }).changePosition({ y: -1 }).writeLine(msg).commit();
|
|
109
|
+
} else {
|
|
110
|
+
await TerminalWriter.for(term).writeLine(msg).commit();
|
|
111
|
+
}
|
|
107
112
|
}
|
|
108
113
|
};
|
|
109
114
|
|
|
110
|
-
|
|
115
|
+
const pos = await term.getCursorPosition();
|
|
116
|
+
|
|
117
|
+
for await (let msg of lines) {
|
|
111
118
|
await commitLine();
|
|
112
|
-
|
|
113
|
-
writer = this.streamWaiting(term,
|
|
119
|
+
msg = msg.replace(/\n$/, '');
|
|
120
|
+
writer = this.streamWaiting(term, msg, cfg, pos);
|
|
121
|
+
line = msg;
|
|
114
122
|
}
|
|
115
|
-
|
|
116
123
|
await commitLine();
|
|
117
124
|
}
|
|
118
125
|
}
|
package/src/terminal.ts
CHANGED
|
@@ -128,13 +128,14 @@ export class Terminal implements TermState {
|
|
|
128
128
|
* @param config
|
|
129
129
|
* @returns
|
|
130
130
|
*/
|
|
131
|
-
async streamLinesWithWaiting(lines: AsyncIterable<string>, config: TerminalWaitingConfig
|
|
131
|
+
async streamLinesWithWaiting(lines: AsyncIterable<string>, config: TerminalWaitingConfig): Promise<void> {
|
|
132
132
|
if (!this.interactive) {
|
|
133
133
|
for await (const line of lines) {
|
|
134
134
|
await this.writeLines(line);
|
|
135
135
|
}
|
|
136
|
+
} else {
|
|
137
|
+
return TerminalOperation.streamLinesWithWaiting(this, lines, { position: 'bottom', ...config });
|
|
136
138
|
}
|
|
137
|
-
return TerminalOperation.streamLinesWithWaiting(this, lines, config);
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
/**
|