@niceties/draftlog-appender 1.1.0 → 1.2.2
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 +87 -86
- package/dist/core.d.ts +1 -1
- package/dist/core.mjs +87 -86
- package/dist/details/canvas.d.ts +1 -1
- package/dist/details/model.d.ts +6 -7
- package/dist/index.cjs +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +20 -26
package/dist/core.cjs
CHANGED
|
@@ -3,28 +3,32 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var draftlog = require('draftlog');
|
|
6
|
+
var list = require('@slimlib/list');
|
|
6
7
|
|
|
7
8
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
9
|
|
|
9
10
|
var draftlog__default = /*#__PURE__*/_interopDefaultLegacy(draftlog);
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
const createCanvas = (spinner, formatter, ident) => {
|
|
12
13
|
draftlog__default["default"](console);
|
|
13
14
|
draftlog__default["default"].defaults.canReWrite = false;
|
|
14
15
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
16
|
const updaters = [];
|
|
17
|
+
const getPrefix = (status, tick) => {
|
|
18
|
+
// status is truthy when it is inprogress
|
|
19
|
+
const prefix = status ? spinner.frames[tick] :
|
|
20
|
+
// status not null when it is finished
|
|
21
|
+
status != null;
|
|
22
|
+
return prefix;
|
|
23
|
+
};
|
|
16
24
|
return (model) => {
|
|
17
25
|
if (model.skipLines_) {
|
|
18
26
|
updaters.splice(0, model.skipLines_);
|
|
19
27
|
model.skipLines_ = 0;
|
|
20
28
|
}
|
|
21
|
-
if (!model.items_.length) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
29
|
let key = 0, dirty = false;
|
|
25
|
-
const stack = [
|
|
26
|
-
|
|
27
|
-
const item = stack[stack.length - 1].shift();
|
|
30
|
+
const stack = [];
|
|
31
|
+
for (const item of model) {
|
|
28
32
|
let updater = updaters[Number(key)];
|
|
29
33
|
if (!updater) {
|
|
30
34
|
updater = console.draft(' ');
|
|
@@ -39,7 +43,7 @@ function createCanvas(spinner, formatter, ident) {
|
|
|
39
43
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
44
|
action: (item.status_ === undefined ? 3 /* log */ : undefined),
|
|
41
45
|
tag: item.tag_
|
|
42
|
-
}, prefix, ident *
|
|
46
|
+
}, prefix, ident * stack.length));
|
|
43
47
|
if (item.dirty_) {
|
|
44
48
|
item.dirty_ = false;
|
|
45
49
|
dirty = true;
|
|
@@ -47,122 +51,115 @@ function createCanvas(spinner, formatter, ident) {
|
|
|
47
51
|
}
|
|
48
52
|
// iterate
|
|
49
53
|
++key;
|
|
50
|
-
if (
|
|
51
|
-
stack
|
|
54
|
+
if (stack[stack.length - 1] === item) {
|
|
55
|
+
stack[stack.length - 1] = null;
|
|
52
56
|
}
|
|
53
|
-
|
|
57
|
+
if (item.lastLeaf_) {
|
|
58
|
+
stack.push(item.lastLeaf_);
|
|
59
|
+
}
|
|
60
|
+
while (stack.length && stack[stack.length - 1] == null) {
|
|
54
61
|
stack.pop();
|
|
55
62
|
}
|
|
56
63
|
}
|
|
57
64
|
};
|
|
58
|
-
|
|
59
|
-
// status is truthy when it is inprogress
|
|
60
|
-
const prefix = status ? spinner.frames[tick] :
|
|
61
|
-
// status not null when it is finished
|
|
62
|
-
status != null;
|
|
63
|
-
return prefix;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
65
|
+
};
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
const model =
|
|
69
|
-
skipLines_: 0,
|
|
70
|
-
tick_: 0,
|
|
71
|
-
spinning_: 0,
|
|
72
|
-
items_: []
|
|
73
|
-
};
|
|
67
|
+
const createModel = (logAboveSpinners) => {
|
|
68
|
+
const model = new list.List();
|
|
74
69
|
const itemById = Object.create(null);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
item.status_ = 0 /* finished */;
|
|
83
|
-
}
|
|
84
|
-
if (action !== 3 /* log */) {
|
|
85
|
-
// if status still empty in the original item or item does not exists it will remain empty and static
|
|
86
|
-
updateModel(inputId, item);
|
|
87
|
-
}
|
|
88
|
-
cleanupModel();
|
|
89
|
-
if (action === 3 /* log */) {
|
|
90
|
-
append(item, logAboveSpinners);
|
|
91
|
-
}
|
|
92
|
-
return model;
|
|
93
|
-
}, () => {
|
|
94
|
-
cleanupModel();
|
|
95
|
-
return model;
|
|
96
|
-
}];
|
|
97
|
-
function append(item, head) {
|
|
98
|
-
model.items_[head ? 'unshift' : 'push'](item);
|
|
70
|
+
const appendToModel = (item, head) => {
|
|
71
|
+
if (head) {
|
|
72
|
+
list.prepend(model, item);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
list.append(model, item);
|
|
76
|
+
}
|
|
99
77
|
model.spinning_ += (item.status_ || 0);
|
|
100
|
-
}
|
|
101
|
-
|
|
78
|
+
};
|
|
79
|
+
const updateModel = (inputId, options) => {
|
|
102
80
|
const modelItem = itemById[inputId];
|
|
103
81
|
if (!modelItem) {
|
|
104
82
|
const item = Object.assign({ inputId_: inputId }, options);
|
|
105
83
|
itemById[inputId] = item;
|
|
106
84
|
const itemParentId = item.parentId_;
|
|
107
85
|
if (itemParentId != null) {
|
|
108
|
-
putIntoChildren(itemParentId, item);
|
|
86
|
+
putIntoChildren(itemParentId, item, item);
|
|
109
87
|
}
|
|
110
88
|
else {
|
|
111
|
-
|
|
89
|
+
appendToModel(item, false);
|
|
112
90
|
}
|
|
113
91
|
}
|
|
114
92
|
else {
|
|
115
93
|
const statusDiff = (options.status_ || 0) - (modelItem.status_ || 0);
|
|
116
|
-
delete options.children_;
|
|
117
94
|
const moveIntoParent = options.parentId_ != null && modelItem.parentId_ == null;
|
|
118
95
|
Object.assign(modelItem, options);
|
|
119
96
|
model.spinning_ += statusDiff;
|
|
120
97
|
if (moveIntoParent) {
|
|
121
|
-
|
|
98
|
+
let lastLeaf = modelItem;
|
|
99
|
+
while (lastLeaf.lastLeaf_) {
|
|
100
|
+
lastLeaf = lastLeaf.lastLeaf_;
|
|
101
|
+
}
|
|
122
102
|
model.spinning_ -= (modelItem.status_ || 0);
|
|
123
103
|
modelItem.dirty_ = true;
|
|
124
|
-
|
|
104
|
+
list.removeRange(modelItem, lastLeaf);
|
|
105
|
+
putIntoChildren(modelItem.parentId_, modelItem, lastLeaf);
|
|
125
106
|
}
|
|
126
107
|
}
|
|
127
|
-
}
|
|
128
|
-
|
|
108
|
+
};
|
|
109
|
+
const putIntoChildren = (itemParentId, begin, end) => {
|
|
129
110
|
let parent = itemById[itemParentId];
|
|
130
111
|
if (!parent) {
|
|
131
|
-
parent = { inputId_: itemParentId, text_: '',
|
|
132
|
-
|
|
112
|
+
parent = { inputId_: itemParentId, text_: '', loglevel_: 0, ref_: new WeakRef(model) };
|
|
113
|
+
appendToModel(parent, false);
|
|
133
114
|
itemById[itemParentId] = parent;
|
|
134
115
|
}
|
|
135
|
-
parent.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
116
|
+
list.appendRange((parent.lastLeaf_ || parent), begin, end);
|
|
117
|
+
parent.lastLeaf_ = begin;
|
|
118
|
+
model.spinning_ += (begin.status_ || 0);
|
|
119
|
+
};
|
|
120
|
+
const cleanupModel = () => {
|
|
139
121
|
var _a;
|
|
140
|
-
for (const item of model
|
|
141
|
-
if (!((_a = item.ref_) === null || _a === void 0 ? void 0 : _a.deref())
|
|
142
|
-
model.skipLines_ += 1
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
do {
|
|
146
|
-
currentItem.inputId_ != null && delete itemById[currentItem.inputId_];
|
|
147
|
-
model.spinning_ -= (currentItem.status_ || 0);
|
|
148
|
-
} while ((currentItem = item.children_.pop()));
|
|
122
|
+
for (const item of model) {
|
|
123
|
+
if (!((_a = item.ref_) === null || _a === void 0 ? void 0 : _a.deref())) {
|
|
124
|
+
model.skipLines_ += 1;
|
|
125
|
+
item.inputId_ != null && delete itemById[item.inputId_];
|
|
126
|
+
list.remove(item);
|
|
149
127
|
}
|
|
150
128
|
else {
|
|
151
129
|
break;
|
|
152
130
|
}
|
|
153
131
|
}
|
|
154
|
-
}
|
|
155
|
-
|
|
132
|
+
};
|
|
133
|
+
model.tick_ = model.skipLines_ = model.spinning_ = 0;
|
|
134
|
+
return [({ message: text, inputId, action, loglevel, ref, parentId, context, tag }) => {
|
|
135
|
+
// item has status undefined, so it is static by default
|
|
136
|
+
const item = { text_: text, loglevel_: loglevel, ref_: ref, parentId_: parentId, dirty_: true, context_: context, tag_: tag };
|
|
137
|
+
if (action === 0 /* start */) {
|
|
138
|
+
item.status_ = 1 /* inprogress */;
|
|
139
|
+
}
|
|
140
|
+
if (action === 2 /* finish */) {
|
|
141
|
+
item.status_ = 0 /* finished */;
|
|
142
|
+
}
|
|
143
|
+
if (action !== 3 /* log */) {
|
|
144
|
+
// if status still empty in the original item or item does not exists it will remain empty and static
|
|
145
|
+
updateModel(inputId, item);
|
|
146
|
+
}
|
|
147
|
+
cleanupModel();
|
|
148
|
+
if (action === 3 /* log */) {
|
|
149
|
+
appendToModel(item, logAboveSpinners);
|
|
150
|
+
}
|
|
151
|
+
return model;
|
|
152
|
+
}, () => {
|
|
153
|
+
cleanupModel();
|
|
154
|
+
return model;
|
|
155
|
+
}];
|
|
156
|
+
};
|
|
156
157
|
|
|
157
|
-
|
|
158
|
+
const createDraftlogAppender = (spinner, formatter, logAboveSpinners, ident) => {
|
|
158
159
|
let interval;
|
|
159
160
|
const [updateModel, getModel] = createModel(logAboveSpinners);
|
|
160
161
|
const renderModel = createCanvas(spinner, formatter, ident);
|
|
161
|
-
|
|
162
|
-
renderModel(updateModel(message));
|
|
163
|
-
checkTimeout();
|
|
164
|
-
};
|
|
165
|
-
function checkTimeout() {
|
|
162
|
+
const checkTimeout = () => {
|
|
166
163
|
const spinning = getModel().spinning_;
|
|
167
164
|
if (spinning && !interval) {
|
|
168
165
|
interval = setInterval(updateSpinners, spinner.interval);
|
|
@@ -172,13 +169,17 @@ function createDraftlogAppender(spinner, formatter, logAboveSpinners, ident) {
|
|
|
172
169
|
clearInterval(interval);
|
|
173
170
|
interval = undefined;
|
|
174
171
|
}
|
|
175
|
-
}
|
|
176
|
-
|
|
172
|
+
};
|
|
173
|
+
const updateSpinners = () => {
|
|
177
174
|
const model = getModel();
|
|
178
175
|
model.tick_++;
|
|
179
176
|
model.tick_ %= spinner.frames.length;
|
|
180
177
|
renderModel(model);
|
|
181
|
-
}
|
|
182
|
-
|
|
178
|
+
};
|
|
179
|
+
return (message) => {
|
|
180
|
+
renderModel(updateModel(message));
|
|
181
|
+
checkTimeout();
|
|
182
|
+
};
|
|
183
|
+
};
|
|
183
184
|
|
|
184
185
|
exports.createDraftlogAppender = createDraftlogAppender;
|
package/dist/core.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Formatter, LogMessage } from '@niceties/logger/types';
|
|
2
2
|
import { Spinner } from './spinners';
|
|
3
|
-
export declare
|
|
3
|
+
export declare const createDraftlogAppender: (spinner: Spinner, formatter: Formatter, logAboveSpinners: boolean, ident: number) => (message: LogMessage) => void;
|
package/dist/core.mjs
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
import draftlog from 'draftlog';
|
|
2
|
+
import { List, prepend, append, removeRange, appendRange, remove } from '@slimlib/list';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
const createCanvas = (spinner, formatter, ident) => {
|
|
4
5
|
draftlog(console);
|
|
5
6
|
draftlog.defaults.canReWrite = false;
|
|
6
7
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
8
|
const updaters = [];
|
|
9
|
+
const getPrefix = (status, tick) => {
|
|
10
|
+
// status is truthy when it is inprogress
|
|
11
|
+
const prefix = status ? spinner.frames[tick] :
|
|
12
|
+
// status not null when it is finished
|
|
13
|
+
status != null;
|
|
14
|
+
return prefix;
|
|
15
|
+
};
|
|
8
16
|
return (model) => {
|
|
9
17
|
if (model.skipLines_) {
|
|
10
18
|
updaters.splice(0, model.skipLines_);
|
|
11
19
|
model.skipLines_ = 0;
|
|
12
20
|
}
|
|
13
|
-
if (!model.items_.length) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
21
|
let key = 0, dirty = false;
|
|
17
|
-
const stack = [
|
|
18
|
-
|
|
19
|
-
const item = stack[stack.length - 1].shift();
|
|
22
|
+
const stack = [];
|
|
23
|
+
for (const item of model) {
|
|
20
24
|
let updater = updaters[Number(key)];
|
|
21
25
|
if (!updater) {
|
|
22
26
|
updater = console.draft(' ');
|
|
@@ -31,7 +35,7 @@ function createCanvas(spinner, formatter, ident) {
|
|
|
31
35
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
36
|
action: (item.status_ === undefined ? 3 /* log */ : undefined),
|
|
33
37
|
tag: item.tag_
|
|
34
|
-
}, prefix, ident *
|
|
38
|
+
}, prefix, ident * stack.length));
|
|
35
39
|
if (item.dirty_) {
|
|
36
40
|
item.dirty_ = false;
|
|
37
41
|
dirty = true;
|
|
@@ -39,122 +43,115 @@ function createCanvas(spinner, formatter, ident) {
|
|
|
39
43
|
}
|
|
40
44
|
// iterate
|
|
41
45
|
++key;
|
|
42
|
-
if (
|
|
43
|
-
stack
|
|
46
|
+
if (stack[stack.length - 1] === item) {
|
|
47
|
+
stack[stack.length - 1] = null;
|
|
44
48
|
}
|
|
45
|
-
|
|
49
|
+
if (item.lastLeaf_) {
|
|
50
|
+
stack.push(item.lastLeaf_);
|
|
51
|
+
}
|
|
52
|
+
while (stack.length && stack[stack.length - 1] == null) {
|
|
46
53
|
stack.pop();
|
|
47
54
|
}
|
|
48
55
|
}
|
|
49
56
|
};
|
|
50
|
-
|
|
51
|
-
// status is truthy when it is inprogress
|
|
52
|
-
const prefix = status ? spinner.frames[tick] :
|
|
53
|
-
// status not null when it is finished
|
|
54
|
-
status != null;
|
|
55
|
-
return prefix;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
57
|
+
};
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
const model =
|
|
61
|
-
skipLines_: 0,
|
|
62
|
-
tick_: 0,
|
|
63
|
-
spinning_: 0,
|
|
64
|
-
items_: []
|
|
65
|
-
};
|
|
59
|
+
const createModel = (logAboveSpinners) => {
|
|
60
|
+
const model = new List();
|
|
66
61
|
const itemById = Object.create(null);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
item.status_ = 0 /* finished */;
|
|
75
|
-
}
|
|
76
|
-
if (action !== 3 /* log */) {
|
|
77
|
-
// if status still empty in the original item or item does not exists it will remain empty and static
|
|
78
|
-
updateModel(inputId, item);
|
|
79
|
-
}
|
|
80
|
-
cleanupModel();
|
|
81
|
-
if (action === 3 /* log */) {
|
|
82
|
-
append(item, logAboveSpinners);
|
|
83
|
-
}
|
|
84
|
-
return model;
|
|
85
|
-
}, () => {
|
|
86
|
-
cleanupModel();
|
|
87
|
-
return model;
|
|
88
|
-
}];
|
|
89
|
-
function append(item, head) {
|
|
90
|
-
model.items_[head ? 'unshift' : 'push'](item);
|
|
62
|
+
const appendToModel = (item, head) => {
|
|
63
|
+
if (head) {
|
|
64
|
+
prepend(model, item);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
append(model, item);
|
|
68
|
+
}
|
|
91
69
|
model.spinning_ += (item.status_ || 0);
|
|
92
|
-
}
|
|
93
|
-
|
|
70
|
+
};
|
|
71
|
+
const updateModel = (inputId, options) => {
|
|
94
72
|
const modelItem = itemById[inputId];
|
|
95
73
|
if (!modelItem) {
|
|
96
74
|
const item = Object.assign({ inputId_: inputId }, options);
|
|
97
75
|
itemById[inputId] = item;
|
|
98
76
|
const itemParentId = item.parentId_;
|
|
99
77
|
if (itemParentId != null) {
|
|
100
|
-
putIntoChildren(itemParentId, item);
|
|
78
|
+
putIntoChildren(itemParentId, item, item);
|
|
101
79
|
}
|
|
102
80
|
else {
|
|
103
|
-
|
|
81
|
+
appendToModel(item, false);
|
|
104
82
|
}
|
|
105
83
|
}
|
|
106
84
|
else {
|
|
107
85
|
const statusDiff = (options.status_ || 0) - (modelItem.status_ || 0);
|
|
108
|
-
delete options.children_;
|
|
109
86
|
const moveIntoParent = options.parentId_ != null && modelItem.parentId_ == null;
|
|
110
87
|
Object.assign(modelItem, options);
|
|
111
88
|
model.spinning_ += statusDiff;
|
|
112
89
|
if (moveIntoParent) {
|
|
113
|
-
|
|
90
|
+
let lastLeaf = modelItem;
|
|
91
|
+
while (lastLeaf.lastLeaf_) {
|
|
92
|
+
lastLeaf = lastLeaf.lastLeaf_;
|
|
93
|
+
}
|
|
114
94
|
model.spinning_ -= (modelItem.status_ || 0);
|
|
115
95
|
modelItem.dirty_ = true;
|
|
116
|
-
|
|
96
|
+
removeRange(modelItem, lastLeaf);
|
|
97
|
+
putIntoChildren(modelItem.parentId_, modelItem, lastLeaf);
|
|
117
98
|
}
|
|
118
99
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
100
|
+
};
|
|
101
|
+
const putIntoChildren = (itemParentId, begin, end) => {
|
|
121
102
|
let parent = itemById[itemParentId];
|
|
122
103
|
if (!parent) {
|
|
123
|
-
parent = { inputId_: itemParentId, text_: '',
|
|
124
|
-
|
|
104
|
+
parent = { inputId_: itemParentId, text_: '', loglevel_: 0, ref_: new WeakRef(model) };
|
|
105
|
+
appendToModel(parent, false);
|
|
125
106
|
itemById[itemParentId] = parent;
|
|
126
107
|
}
|
|
127
|
-
parent.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
108
|
+
appendRange((parent.lastLeaf_ || parent), begin, end);
|
|
109
|
+
parent.lastLeaf_ = begin;
|
|
110
|
+
model.spinning_ += (begin.status_ || 0);
|
|
111
|
+
};
|
|
112
|
+
const cleanupModel = () => {
|
|
131
113
|
var _a;
|
|
132
|
-
for (const item of model
|
|
133
|
-
if (!((_a = item.ref_) === null || _a === void 0 ? void 0 : _a.deref())
|
|
134
|
-
model.skipLines_ += 1
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
do {
|
|
138
|
-
currentItem.inputId_ != null && delete itemById[currentItem.inputId_];
|
|
139
|
-
model.spinning_ -= (currentItem.status_ || 0);
|
|
140
|
-
} while ((currentItem = item.children_.pop()));
|
|
114
|
+
for (const item of model) {
|
|
115
|
+
if (!((_a = item.ref_) === null || _a === void 0 ? void 0 : _a.deref())) {
|
|
116
|
+
model.skipLines_ += 1;
|
|
117
|
+
item.inputId_ != null && delete itemById[item.inputId_];
|
|
118
|
+
remove(item);
|
|
141
119
|
}
|
|
142
120
|
else {
|
|
143
121
|
break;
|
|
144
122
|
}
|
|
145
123
|
}
|
|
146
|
-
}
|
|
147
|
-
|
|
124
|
+
};
|
|
125
|
+
model.tick_ = model.skipLines_ = model.spinning_ = 0;
|
|
126
|
+
return [({ message: text, inputId, action, loglevel, ref, parentId, context, tag }) => {
|
|
127
|
+
// item has status undefined, so it is static by default
|
|
128
|
+
const item = { text_: text, loglevel_: loglevel, ref_: ref, parentId_: parentId, dirty_: true, context_: context, tag_: tag };
|
|
129
|
+
if (action === 0 /* start */) {
|
|
130
|
+
item.status_ = 1 /* inprogress */;
|
|
131
|
+
}
|
|
132
|
+
if (action === 2 /* finish */) {
|
|
133
|
+
item.status_ = 0 /* finished */;
|
|
134
|
+
}
|
|
135
|
+
if (action !== 3 /* log */) {
|
|
136
|
+
// if status still empty in the original item or item does not exists it will remain empty and static
|
|
137
|
+
updateModel(inputId, item);
|
|
138
|
+
}
|
|
139
|
+
cleanupModel();
|
|
140
|
+
if (action === 3 /* log */) {
|
|
141
|
+
appendToModel(item, logAboveSpinners);
|
|
142
|
+
}
|
|
143
|
+
return model;
|
|
144
|
+
}, () => {
|
|
145
|
+
cleanupModel();
|
|
146
|
+
return model;
|
|
147
|
+
}];
|
|
148
|
+
};
|
|
148
149
|
|
|
149
|
-
|
|
150
|
+
const createDraftlogAppender = (spinner, formatter, logAboveSpinners, ident) => {
|
|
150
151
|
let interval;
|
|
151
152
|
const [updateModel, getModel] = createModel(logAboveSpinners);
|
|
152
153
|
const renderModel = createCanvas(spinner, formatter, ident);
|
|
153
|
-
|
|
154
|
-
renderModel(updateModel(message));
|
|
155
|
-
checkTimeout();
|
|
156
|
-
};
|
|
157
|
-
function checkTimeout() {
|
|
154
|
+
const checkTimeout = () => {
|
|
158
155
|
const spinning = getModel().spinning_;
|
|
159
156
|
if (spinning && !interval) {
|
|
160
157
|
interval = setInterval(updateSpinners, spinner.interval);
|
|
@@ -164,13 +161,17 @@ function createDraftlogAppender(spinner, formatter, logAboveSpinners, ident) {
|
|
|
164
161
|
clearInterval(interval);
|
|
165
162
|
interval = undefined;
|
|
166
163
|
}
|
|
167
|
-
}
|
|
168
|
-
|
|
164
|
+
};
|
|
165
|
+
const updateSpinners = () => {
|
|
169
166
|
const model = getModel();
|
|
170
167
|
model.tick_++;
|
|
171
168
|
model.tick_ %= spinner.frames.length;
|
|
172
169
|
renderModel(model);
|
|
173
|
-
}
|
|
174
|
-
|
|
170
|
+
};
|
|
171
|
+
return (message) => {
|
|
172
|
+
renderModel(updateModel(message));
|
|
173
|
+
checkTimeout();
|
|
174
|
+
};
|
|
175
|
+
};
|
|
175
176
|
|
|
176
177
|
export { createDraftlogAppender };
|
package/dist/details/canvas.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Formatter } from '@niceties/logger/types';
|
|
2
2
|
import { Model } from './model';
|
|
3
3
|
import { Spinner } from '../spinners';
|
|
4
|
-
export declare
|
|
4
|
+
export declare const createCanvas: (spinner: Spinner, formatter: Formatter, ident: number) => (model: Model) => void;
|
package/dist/details/model.d.ts
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { LogLevel, LogMessage } from '@niceties/logger/types';
|
|
2
|
+
import { List, ListNode } from '@slimlib/list';
|
|
2
3
|
export declare const enum ItemStatus {
|
|
3
4
|
finished = 0,
|
|
4
5
|
inprogress = 1
|
|
5
6
|
}
|
|
6
|
-
export interface ModelItem {
|
|
7
|
+
export interface ModelItem extends Partial<ListNode> {
|
|
7
8
|
inputId_?: number;
|
|
8
9
|
text_: string;
|
|
9
10
|
status_?: ItemStatus;
|
|
10
11
|
loglevel_: LogLevel;
|
|
11
12
|
ref_?: WeakRef<never>;
|
|
12
13
|
parentId_?: number;
|
|
13
|
-
tag_?: string;
|
|
14
|
-
next_?: ModelItem;
|
|
15
|
-
children_: ModelItem[];
|
|
16
14
|
dirty_?: boolean;
|
|
15
|
+
lastLeaf_?: ModelItem;
|
|
16
|
+
tag_?: string;
|
|
17
17
|
context_?: any;
|
|
18
18
|
}
|
|
19
|
-
export declare type Model = {
|
|
20
|
-
items_: ModelItem[];
|
|
19
|
+
export declare type Model = List<ModelItem> & {
|
|
21
20
|
skipLines_: number;
|
|
22
21
|
tick_: number;
|
|
23
22
|
spinning_: number;
|
|
24
23
|
};
|
|
25
|
-
export declare
|
|
24
|
+
export declare const createModel: (logAboveSpinners: boolean) => [(logMessage: LogMessage) => Model, () => Model];
|
package/dist/index.cjs
CHANGED
|
@@ -7,6 +7,7 @@ var defaultFormatting = require('@niceties/logger/default-formatting');
|
|
|
7
7
|
var core = require('./core.cjs');
|
|
8
8
|
var spinners = require('./spinners.cjs');
|
|
9
9
|
require('draftlog');
|
|
10
|
+
require('@slimlib/list');
|
|
10
11
|
|
|
11
12
|
const supportsUnicode = formatUtils.terminalSupportsUnicode();
|
|
12
13
|
const spinner = supportsUnicode ? spinners.dots : spinners.line;
|
package/dist/index.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { colors, unicodePrefixes, asciiPrefixes, tagFactory } from '@niceties/lo
|
|
|
5
5
|
import { createDraftlogAppender } from './core.mjs';
|
|
6
6
|
import { dots, line } from './spinners.mjs';
|
|
7
7
|
import 'draftlog';
|
|
8
|
+
import '@slimlib/list';
|
|
8
9
|
|
|
9
10
|
const supportsUnicode = terminalSupportsUnicode();
|
|
10
11
|
const spinner = supportsUnicode ? dots : line;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.2.2",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "@niceties/draftlog-appender",
|
|
5
5
|
"author": {
|
|
@@ -17,9 +17,10 @@
|
|
|
17
17
|
"default": "./dist/core.mjs"
|
|
18
18
|
},
|
|
19
19
|
"./spinners": {
|
|
20
|
-
"require": "./
|
|
21
|
-
"default": "./
|
|
22
|
-
}
|
|
20
|
+
"require": "./dist/spinners.cjs",
|
|
21
|
+
"default": "./dist/spinners.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./package.json": "./package.json"
|
|
23
24
|
},
|
|
24
25
|
"main": "./dist/index.cjs",
|
|
25
26
|
"module": "./dist/index.mjs",
|
|
@@ -41,44 +42,37 @@
|
|
|
41
42
|
},
|
|
42
43
|
"homepage": "https://github.com/kshutkin/niceties/blob/main/draftlog-appender/README.md",
|
|
43
44
|
"readme": "README.md",
|
|
45
|
+
"description": "Appender for '@niceites/logger' implemented using draftlog package.",
|
|
44
46
|
"scripts": {
|
|
45
|
-
"build": "
|
|
46
|
-
"dev": "rimraf ./dist && rollup -c -w",
|
|
47
|
+
"build": "pkgbld",
|
|
47
48
|
"test": "node --expose-gc ../node_modules/jest-cli/bin/jest.js --collectCoverage",
|
|
48
49
|
"lint": "eslint ./src",
|
|
49
50
|
"semantic-release": "npx semantic-release"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
|
-
"@rollup/plugin-commonjs": "21.0.1",
|
|
53
|
-
"@rollup/plugin-node-resolve": "13.0.6",
|
|
54
53
|
"@semantic-release/changelog": "6.0.1",
|
|
55
54
|
"@semantic-release/commit-analyzer": "9.0.1",
|
|
56
55
|
"@semantic-release/git": "10.0.1",
|
|
57
56
|
"@semantic-release/npm": "8.0.2",
|
|
58
57
|
"@semantic-release/release-notes-generator": "10.0.2",
|
|
59
|
-
"@types/jest": "27.0
|
|
60
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
61
|
-
"@typescript-eslint/parser": "5.
|
|
58
|
+
"@types/jest": "27.4.0",
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "5.11.0",
|
|
60
|
+
"@typescript-eslint/parser": "5.11.0",
|
|
62
61
|
"conventional-changelog-angular": "5.0.13",
|
|
63
|
-
"eslint": "8.
|
|
64
|
-
"jest": "27.
|
|
65
|
-
"lodash": "4.17.21",
|
|
66
|
-
"rimraf": "3.0.2",
|
|
67
|
-
"rollup": "2.60.1",
|
|
68
|
-
"rollup-plugin-terser": "7.0.2",
|
|
69
|
-
"rollup-plugin-typescript2": "0.31.1",
|
|
70
|
-
"rollup-plugin-preprocess": "0.0.4",
|
|
62
|
+
"eslint": "8.8.0",
|
|
63
|
+
"jest": "27.5.1",
|
|
71
64
|
"semantic-release": "18.0.0",
|
|
72
65
|
"semantic-release-monorepo": "7.0.5",
|
|
73
|
-
"ts-jest": "27.
|
|
74
|
-
"typescript": "4.
|
|
75
|
-
"update-monorepo-package-json": "0.2.0"
|
|
66
|
+
"ts-jest": "27.1.3",
|
|
67
|
+
"typescript": "4.6.x",
|
|
68
|
+
"update-monorepo-package-json": "0.2.0",
|
|
69
|
+
"pkgbld": "1.2.1"
|
|
76
70
|
},
|
|
77
71
|
"peerDependencies": {
|
|
78
|
-
"@niceties/logger": "^1.1.
|
|
72
|
+
"@niceties/logger": "^1.1.3"
|
|
79
73
|
},
|
|
80
74
|
"dependencies": {
|
|
81
|
-
"draftlog": "^1.0.13"
|
|
82
|
-
|
|
83
|
-
|
|
75
|
+
"draftlog": "^1.0.13",
|
|
76
|
+
"@slimlib/list": "^1.0.3"
|
|
77
|
+
}
|
|
84
78
|
}
|