@niceties/draftlog-appender 1.2.9 → 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/dist/core.cjs +45 -11
- package/dist/core.mjs +45 -11
- package/dist/details/canvas.d.ts +2 -2
- package/dist/details/split-by-lines.d.ts +1 -0
- package/dist/details/terminal.d.ts +1 -0
- package/package.json +1 -1
package/dist/core.cjs
CHANGED
|
@@ -3,22 +3,61 @@
|
|
|
3
3
|
var draftlog = require('draftlog');
|
|
4
4
|
var list = require('@slimlib/list');
|
|
5
5
|
|
|
6
|
+
const allColumnsListeners = new Set();
|
|
7
|
+
function subscribeToTerminalResize(listener) {
|
|
8
|
+
allColumnsListeners.add(new WeakRef(listener));
|
|
9
|
+
}
|
|
10
|
+
process.stdout.on('resize', () => {
|
|
11
|
+
for (const listener of allColumnsListeners) {
|
|
12
|
+
const realListener = listener.deref();
|
|
13
|
+
if (realListener) {
|
|
14
|
+
realListener();
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
allColumnsListeners.delete(listener);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
function splitByLines(message) {
|
|
23
|
+
var _a;
|
|
24
|
+
return (_a = message
|
|
25
|
+
.match(getSubstringsRegex())) !== null && _a !== void 0 ? _a : [];
|
|
26
|
+
}
|
|
27
|
+
let substringsRegex, substringsColumns;
|
|
28
|
+
function getSubstringsRegex() {
|
|
29
|
+
const newColumns = process.stdout.columns || 80;
|
|
30
|
+
if (substringsColumns !== newColumns) {
|
|
31
|
+
substringsRegex = new RegExp(`.{1,${newColumns}}`, 'g');
|
|
32
|
+
substringsColumns = newColumns;
|
|
33
|
+
}
|
|
34
|
+
return substringsRegex;
|
|
35
|
+
}
|
|
36
|
+
|
|
6
37
|
function createCanvas(spinner, formatter, ident) {
|
|
7
38
|
draftlog(console);
|
|
8
39
|
draftlog.defaults.canReWrite = false;
|
|
9
40
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
41
|
const updaters = [];
|
|
11
|
-
|
|
42
|
+
let lastModel;
|
|
43
|
+
subscribeToTerminalResize(() => {
|
|
44
|
+
if (lastModel) {
|
|
45
|
+
modelFn(lastModel, true);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return modelFn;
|
|
49
|
+
function modelFn(model, dirty = false) {
|
|
50
|
+
lastModel = model;
|
|
12
51
|
if (model.skipLines) {
|
|
13
52
|
updaters.splice(0, model.skipLines);
|
|
14
53
|
model.skipLines = 0;
|
|
15
54
|
}
|
|
16
|
-
let key = 0
|
|
55
|
+
let key = 0;
|
|
17
56
|
const stack = [];
|
|
18
57
|
for (const item of model) {
|
|
19
58
|
if (dirty || item.dirty || item.status) {
|
|
20
59
|
let prefix = getPrefix(item.status, model.tick), prefixUpdated = false;
|
|
21
|
-
const subitems =
|
|
60
|
+
const subitems = splitByLines(item.message);
|
|
22
61
|
for (const message of subitems) {
|
|
23
62
|
let updater = updaters[key++];
|
|
24
63
|
if (!updater) {
|
|
@@ -45,7 +84,7 @@ function createCanvas(spinner, formatter, ident) {
|
|
|
45
84
|
}
|
|
46
85
|
else {
|
|
47
86
|
// iterate
|
|
48
|
-
key +=
|
|
87
|
+
key += splitByLines(item.message).length;
|
|
49
88
|
}
|
|
50
89
|
if (stack[stack.length - 1] === item) {
|
|
51
90
|
stack[stack.length - 1] = null;
|
|
@@ -57,21 +96,16 @@ function createCanvas(spinner, formatter, ident) {
|
|
|
57
96
|
stack.pop();
|
|
58
97
|
}
|
|
59
98
|
}
|
|
60
|
-
while (key
|
|
99
|
+
while (key < updaters.length) {
|
|
61
100
|
updaters[key++]('');
|
|
62
101
|
}
|
|
63
|
-
}
|
|
102
|
+
}
|
|
64
103
|
function getPrefix(status, tick) {
|
|
65
104
|
// status is truthy when it is inprogress
|
|
66
105
|
return status ? spinner.frames[tick] :
|
|
67
106
|
// status not null when it is finished
|
|
68
107
|
status != null;
|
|
69
108
|
}
|
|
70
|
-
}
|
|
71
|
-
function substrings(message) {
|
|
72
|
-
var _a;
|
|
73
|
-
return (_a = message
|
|
74
|
-
.match(/.{1,80}/g)) !== null && _a !== void 0 ? _a : [];
|
|
75
109
|
}
|
|
76
110
|
|
|
77
111
|
/******************************************************************************
|
package/dist/core.mjs
CHANGED
|
@@ -1,22 +1,61 @@
|
|
|
1
1
|
import draftlog from 'draftlog';
|
|
2
2
|
import { List, prepend, append, removeRange, appendRange, remove } from '@slimlib/list';
|
|
3
3
|
|
|
4
|
+
const allColumnsListeners = new Set();
|
|
5
|
+
function subscribeToTerminalResize(listener) {
|
|
6
|
+
allColumnsListeners.add(new WeakRef(listener));
|
|
7
|
+
}
|
|
8
|
+
process.stdout.on('resize', () => {
|
|
9
|
+
for (const listener of allColumnsListeners) {
|
|
10
|
+
const realListener = listener.deref();
|
|
11
|
+
if (realListener) {
|
|
12
|
+
realListener();
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
allColumnsListeners.delete(listener);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
function splitByLines(message) {
|
|
21
|
+
var _a;
|
|
22
|
+
return (_a = message
|
|
23
|
+
.match(getSubstringsRegex())) !== null && _a !== void 0 ? _a : [];
|
|
24
|
+
}
|
|
25
|
+
let substringsRegex, substringsColumns;
|
|
26
|
+
function getSubstringsRegex() {
|
|
27
|
+
const newColumns = process.stdout.columns || 80;
|
|
28
|
+
if (substringsColumns !== newColumns) {
|
|
29
|
+
substringsRegex = new RegExp(`.{1,${newColumns}}`, 'g');
|
|
30
|
+
substringsColumns = newColumns;
|
|
31
|
+
}
|
|
32
|
+
return substringsRegex;
|
|
33
|
+
}
|
|
34
|
+
|
|
4
35
|
function createCanvas(spinner, formatter, ident) {
|
|
5
36
|
draftlog(console);
|
|
6
37
|
draftlog.defaults.canReWrite = false;
|
|
7
38
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
39
|
const updaters = [];
|
|
9
|
-
|
|
40
|
+
let lastModel;
|
|
41
|
+
subscribeToTerminalResize(() => {
|
|
42
|
+
if (lastModel) {
|
|
43
|
+
modelFn(lastModel, true);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return modelFn;
|
|
47
|
+
function modelFn(model, dirty = false) {
|
|
48
|
+
lastModel = model;
|
|
10
49
|
if (model.skipLines) {
|
|
11
50
|
updaters.splice(0, model.skipLines);
|
|
12
51
|
model.skipLines = 0;
|
|
13
52
|
}
|
|
14
|
-
let key = 0
|
|
53
|
+
let key = 0;
|
|
15
54
|
const stack = [];
|
|
16
55
|
for (const item of model) {
|
|
17
56
|
if (dirty || item.dirty || item.status) {
|
|
18
57
|
let prefix = getPrefix(item.status, model.tick), prefixUpdated = false;
|
|
19
|
-
const subitems =
|
|
58
|
+
const subitems = splitByLines(item.message);
|
|
20
59
|
for (const message of subitems) {
|
|
21
60
|
let updater = updaters[key++];
|
|
22
61
|
if (!updater) {
|
|
@@ -43,7 +82,7 @@ function createCanvas(spinner, formatter, ident) {
|
|
|
43
82
|
}
|
|
44
83
|
else {
|
|
45
84
|
// iterate
|
|
46
|
-
key +=
|
|
85
|
+
key += splitByLines(item.message).length;
|
|
47
86
|
}
|
|
48
87
|
if (stack[stack.length - 1] === item) {
|
|
49
88
|
stack[stack.length - 1] = null;
|
|
@@ -55,21 +94,16 @@ function createCanvas(spinner, formatter, ident) {
|
|
|
55
94
|
stack.pop();
|
|
56
95
|
}
|
|
57
96
|
}
|
|
58
|
-
while (key
|
|
97
|
+
while (key < updaters.length) {
|
|
59
98
|
updaters[key++]('');
|
|
60
99
|
}
|
|
61
|
-
}
|
|
100
|
+
}
|
|
62
101
|
function getPrefix(status, tick) {
|
|
63
102
|
// status is truthy when it is inprogress
|
|
64
103
|
return status ? spinner.frames[tick] :
|
|
65
104
|
// status not null when it is finished
|
|
66
105
|
status != null;
|
|
67
106
|
}
|
|
68
|
-
}
|
|
69
|
-
function substrings(message) {
|
|
70
|
-
var _a;
|
|
71
|
-
return (_a = message
|
|
72
|
-
.match(/.{1,80}/g)) !== null && _a !== void 0 ? _a : [];
|
|
73
107
|
}
|
|
74
108
|
|
|
75
109
|
/******************************************************************************
|
package/dist/details/canvas.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Formatter } from '@niceties/logger/types';
|
|
2
|
-
import { Model } from './model';
|
|
3
2
|
import { Spinner } from '../spinners';
|
|
4
|
-
|
|
3
|
+
import { Model } from './model';
|
|
4
|
+
export declare function createCanvas(spinner: Spinner, formatter: Formatter, ident: number): (model: Model, dirty?: boolean) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function splitByLines(message: string): string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function subscribeToTerminalResize(listener: () => void): void;
|
package/package.json
CHANGED