@oclif/core 1.1.1 → 1.3.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/CHANGELOG.md +23 -0
- package/README.md +8 -4
- package/lib/cli-ux/action/base.d.ts +35 -0
- package/lib/cli-ux/action/base.js +166 -0
- package/lib/cli-ux/action/pride-spinner.d.ts +4 -0
- package/lib/cli-ux/action/pride-spinner.js +31 -0
- package/lib/cli-ux/action/simple.d.ts +11 -0
- package/lib/cli-ux/action/simple.js +52 -0
- package/lib/cli-ux/action/spinner.d.ts +16 -0
- package/lib/cli-ux/action/spinner.js +79 -0
- package/lib/cli-ux/action/spinners.d.ts +0 -0
- package/lib/cli-ux/action/spinners.js +373 -0
- package/lib/cli-ux/config.d.ts +20 -0
- package/lib/cli-ux/config.js +45 -0
- package/lib/cli-ux/deps.d.ts +22 -0
- package/lib/cli-ux/deps.js +47 -0
- package/lib/cli-ux/exit.d.ts +8 -0
- package/lib/cli-ux/exit.js +13 -0
- package/lib/cli-ux/index.d.ts +37 -0
- package/lib/cli-ux/index.js +139 -0
- package/lib/cli-ux/list.d.ts +3 -0
- package/lib/cli-ux/list.js +30 -0
- package/lib/cli-ux/open.d.ts +6 -0
- package/lib/cli-ux/open.js +70 -0
- package/lib/cli-ux/prompt.d.ts +29 -0
- package/lib/cli-ux/prompt.js +150 -0
- package/lib/cli-ux/styled/header.d.ts +1 -0
- package/lib/cli-ux/styled/header.js +8 -0
- package/lib/cli-ux/styled/json.d.ts +1 -0
- package/lib/cli-ux/styled/json.js +16 -0
- package/lib/cli-ux/styled/object.d.ts +1 -0
- package/lib/cli-ux/styled/object.js +39 -0
- package/lib/cli-ux/styled/progress.d.ts +1 -0
- package/lib/cli-ux/styled/progress.js +14 -0
- package/lib/cli-ux/styled/table.d.ts +45 -0
- package/lib/cli-ux/styled/table.js +312 -0
- package/lib/cli-ux/styled/tree.d.ts +9 -0
- package/lib/cli-ux/styled/tree.js +40 -0
- package/lib/cli-ux/wait.d.ts +2 -0
- package/lib/cli-ux/wait.js +8 -0
- package/lib/command.js +4 -5
- package/lib/config/config.js +10 -5
- package/lib/config/plugin.js +1 -1
- package/lib/help/util.js +2 -2
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/lib/interfaces/hooks.d.ts +3 -1
- package/lib/interfaces/index.d.ts +1 -0
- package/lib/interfaces/s3-manifest.d.ts +14 -0
- package/lib/interfaces/s3-manifest.js +2 -0
- package/package.json +21 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [1.3.0](https://github.com/oclif/core/compare/v1.2.1...v1.3.0) (2022-02-01)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add S3Manifest ([#354](https://github.com/oclif/core/issues/354)) ([ea5585d](https://github.com/oclif/core/commit/ea5585db6361f12c3c0608b05d1e33e16bc0b4b6))
|
|
11
|
+
|
|
12
|
+
### [1.2.1](https://github.com/oclif/core/compare/v1.2.0...v1.2.1) (2022-01-28)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* module resolution of linked plugins ([#352](https://github.com/oclif/core/issues/352)) ([c7f5d34](https://github.com/oclif/core/commit/c7f5d3439e7e60b6562362c87fe0d16a99a42a08))
|
|
18
|
+
|
|
19
|
+
## [1.2.0](https://github.com/oclif/core/compare/v1.1.2...v1.2.0) (2022-01-26)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* merge cli-ux library with oclif/core ([#345](https://github.com/oclif/core/issues/345)) ([27175d6](https://github.com/oclif/core/commit/27175d6f0693533b7cfbf57de65da626168d872f)), closes [npm/cli#4234](https://github.com/npm/cli/issues/4234)
|
|
25
|
+
|
|
26
|
+
### [1.1.2](https://github.com/oclif/core/compare/v1.1.1...v1.1.2) (2022-01-10)
|
|
27
|
+
|
|
5
28
|
### [1.1.1](https://github.com/oclif/core/compare/v1.1.0...v1.1.1) (2022-01-06)
|
|
6
29
|
|
|
7
30
|
|
package/README.md
CHANGED
|
@@ -14,6 +14,10 @@ Migrating
|
|
|
14
14
|
|
|
15
15
|
If you're migrating from the old oclif libraries (`@oclif/config`, `@oclif/command`, `@oclif/error`, `@oclif/parser`), see the [migration guide](./MIGRATION.md).
|
|
16
16
|
|
|
17
|
+
The `@oclif/core` module now also includes the `cli-ux` module. Merging `cli-ux` into `@oclif/core` resolves a circular dependency between the two modules.
|
|
18
|
+
See the [cli-ux README](./src/cli-ux/README.md) for instructions on how to replace the `cli-ux` module with `@oclif/core`.
|
|
19
|
+
The [cli-ux README](./src/cli-ux/README.md) also contains detailed usage examples.
|
|
20
|
+
|
|
17
21
|
Usage
|
|
18
22
|
=====
|
|
19
23
|
|
|
@@ -24,14 +28,14 @@ Without the generator, you can create a simple CLI like this:
|
|
|
24
28
|
#!/usr/bin/env ts-node
|
|
25
29
|
|
|
26
30
|
import * as fs from 'fs'
|
|
27
|
-
import {Command,
|
|
31
|
+
import {Command, Flags} from '@oclif/core'
|
|
28
32
|
|
|
29
33
|
class LS extends Command {
|
|
30
34
|
static flags = {
|
|
31
|
-
version:
|
|
32
|
-
help:
|
|
35
|
+
version: Flags.version(),
|
|
36
|
+
help: Flags.help(),
|
|
33
37
|
// run with --dir= or -d=
|
|
34
|
-
dir:
|
|
38
|
+
dir: Flags.string({
|
|
35
39
|
char: 'd',
|
|
36
40
|
default: process.cwd(),
|
|
37
41
|
}),
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface ITask {
|
|
2
|
+
action: string;
|
|
3
|
+
status: string | undefined;
|
|
4
|
+
active: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare type ActionType = 'spinner' | 'simple' | 'debug';
|
|
7
|
+
export interface Options {
|
|
8
|
+
stdout?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare class ActionBase {
|
|
11
|
+
type: ActionType;
|
|
12
|
+
std: 'stdout' | 'stderr';
|
|
13
|
+
protected stdmocks?: ['stdout' | 'stderr', string[]][];
|
|
14
|
+
private stdmockOrigs;
|
|
15
|
+
start(action: string, status?: string, opts?: Options): void;
|
|
16
|
+
stop(msg?: string): void;
|
|
17
|
+
private get globals();
|
|
18
|
+
get task(): ITask | undefined;
|
|
19
|
+
set task(task: ITask | undefined);
|
|
20
|
+
protected get output(): string | undefined;
|
|
21
|
+
protected set output(output: string | undefined);
|
|
22
|
+
get running(): boolean;
|
|
23
|
+
get status(): string | undefined;
|
|
24
|
+
set status(status: string | undefined);
|
|
25
|
+
pauseAsync(fn: () => Promise<any>, icon?: string): Promise<any>;
|
|
26
|
+
pause(fn: () => any, icon?: string): any;
|
|
27
|
+
protected _start(): void;
|
|
28
|
+
protected _stop(_: string): void;
|
|
29
|
+
protected _resume(): void;
|
|
30
|
+
protected _pause(_?: string): void;
|
|
31
|
+
protected _updateStatus(_: string | undefined, __?: string): void;
|
|
32
|
+
protected _stdout(toggle: boolean): void;
|
|
33
|
+
protected _flushStdout(): void;
|
|
34
|
+
protected _write(std: 'stdout' | 'stderr', s: string | string[]): void;
|
|
35
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActionBase = void 0;
|
|
4
|
+
const util_1 = require("util");
|
|
5
|
+
const util_2 = require("../../util");
|
|
6
|
+
class ActionBase {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.std = 'stderr';
|
|
9
|
+
this.stdmockOrigs = {
|
|
10
|
+
stdout: process.stdout.write,
|
|
11
|
+
stderr: process.stderr.write,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
start(action, status, opts = {}) {
|
|
15
|
+
this.std = opts.stdout ? 'stdout' : 'stderr';
|
|
16
|
+
const task = { action, status, active: Boolean(this.task && this.task.active) };
|
|
17
|
+
this.task = task;
|
|
18
|
+
this._start();
|
|
19
|
+
task.active = true;
|
|
20
|
+
this._stdout(true);
|
|
21
|
+
}
|
|
22
|
+
stop(msg = 'done') {
|
|
23
|
+
const task = this.task;
|
|
24
|
+
if (!task) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
this._stop(msg);
|
|
28
|
+
task.active = false;
|
|
29
|
+
this.task = undefined;
|
|
30
|
+
this._stdout(false);
|
|
31
|
+
}
|
|
32
|
+
get globals() {
|
|
33
|
+
global['cli-ux'] = global['cli-ux'] || {};
|
|
34
|
+
const globals = global['cli-ux'];
|
|
35
|
+
globals.action = globals.action || {};
|
|
36
|
+
return globals;
|
|
37
|
+
}
|
|
38
|
+
get task() {
|
|
39
|
+
return this.globals.action.task;
|
|
40
|
+
}
|
|
41
|
+
set task(task) {
|
|
42
|
+
this.globals.action.task = task;
|
|
43
|
+
}
|
|
44
|
+
get output() {
|
|
45
|
+
return this.globals.output;
|
|
46
|
+
}
|
|
47
|
+
set output(output) {
|
|
48
|
+
this.globals.output = output;
|
|
49
|
+
}
|
|
50
|
+
get running() {
|
|
51
|
+
return Boolean(this.task);
|
|
52
|
+
}
|
|
53
|
+
get status() {
|
|
54
|
+
return this.task ? this.task.status : undefined;
|
|
55
|
+
}
|
|
56
|
+
set status(status) {
|
|
57
|
+
const task = this.task;
|
|
58
|
+
if (!task) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (task.status === status) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this._updateStatus(status, task.status);
|
|
65
|
+
task.status = status;
|
|
66
|
+
}
|
|
67
|
+
async pauseAsync(fn, icon) {
|
|
68
|
+
const task = this.task;
|
|
69
|
+
const active = task && task.active;
|
|
70
|
+
if (task && active) {
|
|
71
|
+
this._pause(icon);
|
|
72
|
+
this._stdout(false);
|
|
73
|
+
task.active = false;
|
|
74
|
+
}
|
|
75
|
+
const ret = await fn();
|
|
76
|
+
if (task && active) {
|
|
77
|
+
this._resume();
|
|
78
|
+
}
|
|
79
|
+
return ret;
|
|
80
|
+
}
|
|
81
|
+
pause(fn, icon) {
|
|
82
|
+
const task = this.task;
|
|
83
|
+
const active = task && task.active;
|
|
84
|
+
if (task && active) {
|
|
85
|
+
this._pause(icon);
|
|
86
|
+
this._stdout(false);
|
|
87
|
+
task.active = false;
|
|
88
|
+
}
|
|
89
|
+
const ret = fn();
|
|
90
|
+
if (task && active) {
|
|
91
|
+
this._resume();
|
|
92
|
+
}
|
|
93
|
+
return ret;
|
|
94
|
+
}
|
|
95
|
+
_start() {
|
|
96
|
+
throw new Error('not implemented');
|
|
97
|
+
}
|
|
98
|
+
_stop(_) {
|
|
99
|
+
throw new Error('not implemented');
|
|
100
|
+
}
|
|
101
|
+
_resume() {
|
|
102
|
+
if (this.task)
|
|
103
|
+
this.start(this.task.action, this.task.status);
|
|
104
|
+
}
|
|
105
|
+
_pause(_) {
|
|
106
|
+
throw new Error('not implemented');
|
|
107
|
+
}
|
|
108
|
+
_updateStatus(_, __) { }
|
|
109
|
+
// mock out stdout/stderr so it doesn't screw up the rendering
|
|
110
|
+
_stdout(toggle) {
|
|
111
|
+
try {
|
|
112
|
+
const outputs = ['stdout', 'stderr'];
|
|
113
|
+
if (toggle) {
|
|
114
|
+
if (this.stdmocks)
|
|
115
|
+
return;
|
|
116
|
+
this.stdmockOrigs = {
|
|
117
|
+
stdout: process.stdout.write,
|
|
118
|
+
stderr: process.stderr.write,
|
|
119
|
+
};
|
|
120
|
+
this.stdmocks = [];
|
|
121
|
+
for (const std of outputs) {
|
|
122
|
+
process[std].write = (...args) => {
|
|
123
|
+
this.stdmocks.push([std, args]);
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
if (!this.stdmocks)
|
|
129
|
+
return;
|
|
130
|
+
// this._write('stderr', '\nresetstdmock\n\n\n')
|
|
131
|
+
delete this.stdmocks;
|
|
132
|
+
for (const std of outputs)
|
|
133
|
+
process[std].write = this.stdmockOrigs[std];
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
this._write('stderr', (0, util_1.inspect)(error));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// flush mocked stdout/stderr
|
|
141
|
+
_flushStdout() {
|
|
142
|
+
try {
|
|
143
|
+
let output = '';
|
|
144
|
+
let std;
|
|
145
|
+
while (this.stdmocks && this.stdmocks.length > 0) {
|
|
146
|
+
const cur = this.stdmocks.shift();
|
|
147
|
+
std = cur[0];
|
|
148
|
+
this._write(std, cur[1]);
|
|
149
|
+
output += cur[1][0].toString('utf8');
|
|
150
|
+
}
|
|
151
|
+
// add newline if there isn't one already
|
|
152
|
+
// otherwise we'll just overwrite it when we render
|
|
153
|
+
if (output && std && output[output.length - 1] !== '\n') {
|
|
154
|
+
this._write(std, '\n');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
this._write('stderr', (0, util_1.inspect)(error));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// write to the real stdout/stderr
|
|
162
|
+
_write(std, s) {
|
|
163
|
+
this.stdmockOrigs[std].apply(process[std], (0, util_2.castArray)(s));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.ActionBase = ActionBase;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// tslint:disable restrict-plus-operands
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const supportsColor = require("supports-color");
|
|
6
|
+
const spinner_1 = require("./spinner");
|
|
7
|
+
function color(s, frameIndex) {
|
|
8
|
+
const prideColors = [
|
|
9
|
+
chalk.keyword('pink'),
|
|
10
|
+
chalk.red,
|
|
11
|
+
chalk.keyword('orange'),
|
|
12
|
+
chalk.yellow,
|
|
13
|
+
chalk.green,
|
|
14
|
+
chalk.cyan,
|
|
15
|
+
chalk.blue,
|
|
16
|
+
chalk.magenta,
|
|
17
|
+
];
|
|
18
|
+
if (!supportsColor)
|
|
19
|
+
return s;
|
|
20
|
+
const has256 = supportsColor.stdout ? supportsColor.stdout.has256 : (process.env.TERM || '').includes('256');
|
|
21
|
+
const prideColor = prideColors[frameIndex] || prideColors[0];
|
|
22
|
+
return has256 ? prideColor(s) : chalk.magenta(s);
|
|
23
|
+
}
|
|
24
|
+
class PrideSpinnerAction extends spinner_1.default {
|
|
25
|
+
_frame() {
|
|
26
|
+
const frame = this.frames[this.frameIndex];
|
|
27
|
+
this.frameIndex = ++this.frameIndex % this.frames.length;
|
|
28
|
+
return color(frame, this.frameIndex);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.default = PrideSpinnerAction;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ActionBase, ActionType } from './base';
|
|
2
|
+
export default class SimpleAction extends ActionBase {
|
|
3
|
+
type: ActionType;
|
|
4
|
+
protected _start(): void;
|
|
5
|
+
protected _pause(icon?: string): void;
|
|
6
|
+
protected _resume(): void;
|
|
7
|
+
protected _updateStatus(status: string, prevStatus?: string, newline?: boolean): void;
|
|
8
|
+
protected _stop(status: string): void;
|
|
9
|
+
private _render;
|
|
10
|
+
private _flush;
|
|
11
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const base_1 = require("./base");
|
|
4
|
+
class SimpleAction extends base_1.ActionBase {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.type = 'simple';
|
|
8
|
+
}
|
|
9
|
+
_start() {
|
|
10
|
+
const task = this.task;
|
|
11
|
+
if (!task)
|
|
12
|
+
return;
|
|
13
|
+
this._render(task.action, task.status);
|
|
14
|
+
}
|
|
15
|
+
_pause(icon) {
|
|
16
|
+
if (icon)
|
|
17
|
+
this._updateStatus(icon);
|
|
18
|
+
else
|
|
19
|
+
this._flush();
|
|
20
|
+
}
|
|
21
|
+
_resume() { }
|
|
22
|
+
_updateStatus(status, prevStatus, newline = false) {
|
|
23
|
+
const task = this.task;
|
|
24
|
+
if (!task)
|
|
25
|
+
return;
|
|
26
|
+
if (task.active && !prevStatus)
|
|
27
|
+
this._write(this.std, ` ${status}`);
|
|
28
|
+
else
|
|
29
|
+
this._write(this.std, `${task.action}... ${status}`);
|
|
30
|
+
if (newline || !prevStatus)
|
|
31
|
+
this._flush();
|
|
32
|
+
}
|
|
33
|
+
_stop(status) {
|
|
34
|
+
const task = this.task;
|
|
35
|
+
if (!task)
|
|
36
|
+
return;
|
|
37
|
+
this._updateStatus(status, task.status, true);
|
|
38
|
+
}
|
|
39
|
+
_render(action, status) {
|
|
40
|
+
const task = this.task;
|
|
41
|
+
if (!task)
|
|
42
|
+
return;
|
|
43
|
+
if (task.active)
|
|
44
|
+
this._flush();
|
|
45
|
+
this._write(this.std, status ? `${action}... ${status}` : `${action}...`);
|
|
46
|
+
}
|
|
47
|
+
_flush() {
|
|
48
|
+
this._write(this.std, '\n');
|
|
49
|
+
this._flushStdout();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.default = SimpleAction;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ActionBase, ActionType } from './base';
|
|
3
|
+
export default class SpinnerAction extends ActionBase {
|
|
4
|
+
type: ActionType;
|
|
5
|
+
spinner?: NodeJS.Timeout;
|
|
6
|
+
frames: any;
|
|
7
|
+
frameIndex: number;
|
|
8
|
+
constructor();
|
|
9
|
+
protected _start(): void;
|
|
10
|
+
protected _stop(status: string): void;
|
|
11
|
+
protected _pause(icon?: string): void;
|
|
12
|
+
protected _frame(): string;
|
|
13
|
+
private _render;
|
|
14
|
+
private _reset;
|
|
15
|
+
private _lines;
|
|
16
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// tslint:disable restrict-plus-operands
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const supportsColor = require("supports-color");
|
|
6
|
+
const deps_1 = require("../deps");
|
|
7
|
+
const base_1 = require("./base");
|
|
8
|
+
/* eslint-disable-next-line node/no-missing-require */
|
|
9
|
+
const spinners = require('./spinners');
|
|
10
|
+
function color(s) {
|
|
11
|
+
if (!supportsColor)
|
|
12
|
+
return s;
|
|
13
|
+
const has256 = supportsColor.stdout ? supportsColor.stdout.has256 : (process.env.TERM || '').includes('256');
|
|
14
|
+
return has256 ? `\u001B[38;5;104m${s}${deps_1.default.ansiStyles.reset.open}` : chalk.magenta(s);
|
|
15
|
+
}
|
|
16
|
+
class SpinnerAction extends base_1.ActionBase {
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
this.type = 'spinner';
|
|
20
|
+
this.frames = spinners[process.platform === 'win32' ? 'line' : 'dots2'].frames;
|
|
21
|
+
this.frameIndex = 0;
|
|
22
|
+
}
|
|
23
|
+
_start() {
|
|
24
|
+
this._reset();
|
|
25
|
+
if (this.spinner)
|
|
26
|
+
clearInterval(this.spinner);
|
|
27
|
+
this._render();
|
|
28
|
+
this.spinner = setInterval(icon => this._render.bind(this)(icon), process.platform === 'win32' ? 500 : 100, 'spinner');
|
|
29
|
+
const interval = this.spinner;
|
|
30
|
+
interval.unref();
|
|
31
|
+
}
|
|
32
|
+
_stop(status) {
|
|
33
|
+
if (this.task)
|
|
34
|
+
this.task.status = status;
|
|
35
|
+
if (this.spinner)
|
|
36
|
+
clearInterval(this.spinner);
|
|
37
|
+
this._render();
|
|
38
|
+
this.output = undefined;
|
|
39
|
+
}
|
|
40
|
+
_pause(icon) {
|
|
41
|
+
if (this.spinner)
|
|
42
|
+
clearInterval(this.spinner);
|
|
43
|
+
this._reset();
|
|
44
|
+
if (icon)
|
|
45
|
+
this._render(` ${icon}`);
|
|
46
|
+
this.output = undefined;
|
|
47
|
+
}
|
|
48
|
+
_frame() {
|
|
49
|
+
const frame = this.frames[this.frameIndex];
|
|
50
|
+
this.frameIndex = ++this.frameIndex % this.frames.length;
|
|
51
|
+
return color(frame);
|
|
52
|
+
}
|
|
53
|
+
_render(icon) {
|
|
54
|
+
const task = this.task;
|
|
55
|
+
if (!task)
|
|
56
|
+
return;
|
|
57
|
+
this._reset();
|
|
58
|
+
this._flushStdout();
|
|
59
|
+
const frame = icon === 'spinner' ? ` ${this._frame()}` : icon || '';
|
|
60
|
+
const status = task.status ? ` ${task.status}` : '';
|
|
61
|
+
this.output = `${task.action}...${frame}${status}\n`;
|
|
62
|
+
this._write(this.std, this.output);
|
|
63
|
+
}
|
|
64
|
+
_reset() {
|
|
65
|
+
if (!this.output)
|
|
66
|
+
return;
|
|
67
|
+
const lines = this._lines(this.output);
|
|
68
|
+
this._write(this.std, deps_1.default.ansiEscapes.cursorLeft + deps_1.default.ansiEscapes.cursorUp(lines) + deps_1.default.ansiEscapes.eraseDown);
|
|
69
|
+
this.output = undefined;
|
|
70
|
+
}
|
|
71
|
+
_lines(s) {
|
|
72
|
+
return deps_1.default
|
|
73
|
+
.stripAnsi(s)
|
|
74
|
+
.split('\n')
|
|
75
|
+
.map(l => Math.ceil(l.length / deps_1.default.screen.errtermwidth))
|
|
76
|
+
.reduce((c, i) => c + i, 0);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.default = SpinnerAction;
|
|
File without changes
|