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;
|