1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.MultiProgress = void 0;
|
4 | const log_1 = require("builder-util/out/log");
|
5 | const progress_1 = require("./progress");
|
6 | class MultiProgress {
|
7 | constructor() {
|
8 | this.stream = process.stdout;
|
9 | this.cursor = 0;
|
10 | this.totalLines = 0;
|
11 | this.isLogListenerAdded = false;
|
12 | this.barCount = 0;
|
13 | }
|
14 | createBar(format, options) {
|
15 | options.stream = this.stream;
|
16 |
|
17 | const manager = this;
|
18 | class MultiProgressBar extends progress_1.ProgressBar {
|
19 | constructor(format, options) {
|
20 | super(format, options);
|
21 | this.index = -1;
|
22 | }
|
23 | render() {
|
24 | if (this.index === -1) {
|
25 | this.index = manager.totalLines;
|
26 | manager.allocateLines(1);
|
27 | }
|
28 | else {
|
29 | manager.moveCursor(this.index);
|
30 | }
|
31 | super.render();
|
32 | if (!manager.isLogListenerAdded) {
|
33 | manager.isLogListenerAdded = true;
|
34 | log_1.setPrinter(message => {
|
35 | let newLineCount = 0;
|
36 | let newLineIndex = message.indexOf("\n");
|
37 | while (newLineIndex > -1) {
|
38 | newLineCount++;
|
39 | newLineIndex = message.indexOf("\n", ++newLineIndex);
|
40 | }
|
41 | manager.allocateLines(newLineCount + 1);
|
42 | manager.stream.write(message);
|
43 | });
|
44 | }
|
45 | }
|
46 | terminate() {
|
47 | manager.barCount--;
|
48 | if (manager.barCount === 0 && manager.totalLines > 0) {
|
49 | manager.allocateLines(1);
|
50 | manager.totalLines = 0;
|
51 | manager.cursor = 0;
|
52 | log_1.setPrinter(null);
|
53 | manager.isLogListenerAdded = false;
|
54 | }
|
55 | }
|
56 | }
|
57 | const bar = new MultiProgressBar(format, options);
|
58 | this.barCount++;
|
59 | return bar;
|
60 | }
|
61 | allocateLines(count) {
|
62 | this.stream.moveCursor(0, this.totalLines - 1);
|
63 |
|
64 | this.stream.write("\n");
|
65 | this.totalLines += count;
|
66 | this.cursor = this.totalLines - 1;
|
67 | }
|
68 | moveCursor(index) {
|
69 | this.stream.moveCursor(0, index - this.cursor);
|
70 | this.cursor = index;
|
71 | }
|
72 | terminate() {
|
73 | this.moveCursor(this.totalLines);
|
74 | this.stream.clearLine();
|
75 | this.stream.cursorTo(0);
|
76 | }
|
77 | }
|
78 | exports.MultiProgress = MultiProgress;
|
79 |
|
\ | No newline at end of file |