@niceties/draftlog-appender 1.2.8 → 1.2.9

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 CHANGED
@@ -3,78 +3,147 @@
3
3
  var draftlog = require('draftlog');
4
4
  var list = require('@slimlib/list');
5
5
 
6
- const createCanvas = (spinner, formatter, ident) => {
6
+ function createCanvas(spinner, formatter, ident) {
7
7
  draftlog(console);
8
8
  draftlog.defaults.canReWrite = false;
9
9
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
10
  const updaters = [];
11
- const getPrefix = (status, tick) => {
12
- // status is truthy when it is inprogress
13
- return status ? spinner.frames[tick] :
14
- // status not null when it is finished
15
- status != null;
16
- };
17
11
  return (model) => {
18
- if (model.skipLines_) {
19
- updaters.splice(0, model.skipLines_);
20
- model.skipLines_ = 0;
12
+ if (model.skipLines) {
13
+ updaters.splice(0, model.skipLines);
14
+ model.skipLines = 0;
21
15
  }
22
16
  let key = 0, dirty = false;
23
17
  const stack = [];
24
18
  for (const item of model) {
25
- let updater = updaters[Number(key)];
26
- if (!updater) {
27
- updater = console.draft(' ');
28
- updaters.push(updater);
29
- }
30
- if (dirty || item.dirty_ || item.status_) {
31
- const prefix = getPrefix(item.status_, model.tick_);
32
- updater(formatter({
33
- loglevel: item.loglevel_,
34
- message: item.text_,
35
- context: item.context_,
36
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
- action: (item.status_ === undefined ? 3 /* log */ : undefined),
38
- tag: item.tag_
39
- }, prefix, ident * stack.length));
40
- if (item.dirty_) {
41
- item.dirty_ = false;
19
+ if (dirty || item.dirty || item.status) {
20
+ let prefix = getPrefix(item.status, model.tick), prefixUpdated = false;
21
+ const subitems = substrings(item.message);
22
+ for (const message of subitems) {
23
+ let updater = updaters[key++];
24
+ if (!updater) {
25
+ updater = console.draft(' ');
26
+ updaters.push(updater);
27
+ }
28
+ updater(formatter({
29
+ loglevel: item.loglevel,
30
+ message,
31
+ context: item.context,
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
+ action: (item.status === undefined ? 3 /* log */ : undefined),
34
+ tag: item.tag
35
+ }, prefix, ident * stack.length));
36
+ if (subitems.length > 1 && typeof prefix === 'string' && !prefixUpdated) {
37
+ prefix = prefix.replaceAll(/./g, ' ');
38
+ prefixUpdated = true;
39
+ }
40
+ }
41
+ if (item.dirty) {
42
+ item.dirty = false;
42
43
  dirty = true;
43
44
  }
44
45
  }
45
- // iterate
46
- ++key;
46
+ else {
47
+ // iterate
48
+ key += substrings(item.message).length;
49
+ }
47
50
  if (stack[stack.length - 1] === item) {
48
51
  stack[stack.length - 1] = null;
49
52
  }
50
- if (item.lastLeaf_) {
51
- stack.push(item.lastLeaf_);
53
+ if (item.lastLeaf) {
54
+ stack.push(item.lastLeaf);
52
55
  }
53
56
  while (stack.length && stack[stack.length - 1] == null) {
54
57
  stack.pop();
55
58
  }
56
59
  }
60
+ while (key !== updaters.length) {
61
+ updaters[key++]('');
62
+ }
57
63
  };
58
- };
64
+ function getPrefix(status, tick) {
65
+ // status is truthy when it is inprogress
66
+ return status ? spinner.frames[tick] :
67
+ // status not null when it is finished
68
+ status != null;
69
+ }
70
+ }
71
+ function substrings(message) {
72
+ var _a;
73
+ return (_a = message
74
+ .match(/.{1,80}/g)) !== null && _a !== void 0 ? _a : [];
75
+ }
76
+
77
+ /******************************************************************************
78
+ Copyright (c) Microsoft Corporation.
79
+
80
+ Permission to use, copy, modify, and/or distribute this software for any
81
+ purpose with or without fee is hereby granted.
82
+
83
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
84
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
85
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
86
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
87
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
88
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
89
+ PERFORMANCE OF THIS SOFTWARE.
90
+ ***************************************************************************** */
91
+
92
+ function __rest(s, e) {
93
+ var t = {};
94
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
95
+ t[p] = s[p];
96
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
97
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
98
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
99
+ t[p[i]] = s[p[i]];
100
+ }
101
+ return t;
102
+ }
59
103
 
60
- const createModel = (logAboveSpinners) => {
104
+ function createModel(logAboveSpinners) {
61
105
  const model = new list.List();
62
106
  const itemById = Object.create(null);
63
- const appendToModel = (item, head) => {
107
+ model.tick = model.skipLines = model.spinning = 0;
108
+ return [(_a) => {
109
+ var { action } = _a, item = __rest(_a, ["action"]);
110
+ // item has status undefined, so it is static by default
111
+ item.dirty = true;
112
+ const { inputId } = item;
113
+ if (action === 0 /* start */) {
114
+ item.status = 1 /* inprogress */;
115
+ }
116
+ if (action === 2 /* finish */) {
117
+ item.status = 0 /* finished */;
118
+ }
119
+ if (action !== 3 /* log */) {
120
+ // if status still empty in the original item or item does not exists it will remain empty and static
121
+ updateModel(inputId, item);
122
+ }
123
+ cleanupModel();
124
+ if (action === 3 /* log */) {
125
+ appendToModel(item, logAboveSpinners);
126
+ }
127
+ return model;
128
+ }, () => {
129
+ cleanupModel();
130
+ return model;
131
+ }];
132
+ function appendToModel(item, head) {
64
133
  if (head) {
65
134
  list.prepend(model, item);
66
135
  }
67
136
  else {
68
137
  list.append(model, item);
69
138
  }
70
- model.spinning_ += (item.status_ || 0);
71
- };
72
- const updateModel = (inputId, options) => {
139
+ model.spinning += (item.status || 0);
140
+ }
141
+ function updateModel(inputId, options) {
73
142
  const modelItem = itemById[inputId];
74
143
  if (!modelItem) {
75
- const item = Object.assign({ inputId_: inputId }, options);
144
+ const item = Object.assign({ inputId: inputId }, options);
76
145
  itemById[inputId] = item;
77
- const itemParentId = item.parentId_;
146
+ const itemParentId = item.parentId;
78
147
  if (itemParentId != null) {
79
148
  putIntoChildren(itemParentId, item, item);
80
149
  }
@@ -83,81 +152,62 @@ const createModel = (logAboveSpinners) => {
83
152
  }
84
153
  }
85
154
  else {
86
- const statusDiff = (options.status_ || 0) - (modelItem.status_ || 0);
87
- const moveIntoParent = options.parentId_ != null && modelItem.parentId_ == null;
155
+ const statusDiff = (options.status || 0) - (modelItem.status || 0);
156
+ const moveIntoParent = options.parentId != null && modelItem.parentId == null;
88
157
  Object.assign(modelItem, options);
89
- model.spinning_ += statusDiff;
158
+ model.spinning += statusDiff;
90
159
  if (moveIntoParent) {
91
160
  const lastLeaf = getLastLeaf(modelItem);
92
- model.spinning_ -= (modelItem.status_ || 0);
93
- modelItem.dirty_ = true;
161
+ model.spinning -= (modelItem.status || 0);
162
+ modelItem.dirty = true;
94
163
  list.removeRange(modelItem, lastLeaf);
95
- putIntoChildren(modelItem.parentId_, modelItem, lastLeaf);
164
+ putIntoChildren(modelItem.parentId, modelItem, lastLeaf);
96
165
  }
97
166
  }
98
- };
99
- const putIntoChildren = (itemParentId, begin, end) => {
167
+ }
168
+ function putIntoChildren(itemParentId, begin, end) {
100
169
  let parent = itemById[itemParentId];
101
170
  if (!parent) {
102
- parent = { inputId_: itemParentId, text_: '', loglevel_: 0, ref_: new WeakRef(model) };
171
+ parent = { inputId: itemParentId, message: '', loglevel: 0, ref: new WeakRef(model) };
103
172
  appendToModel(parent, false);
104
173
  itemById[itemParentId] = parent;
105
174
  }
106
175
  list.appendRange((getLastLeaf(parent)), begin, end);
107
- parent.lastLeaf_ = begin;
108
- model.spinning_ += (begin.status_ || 0);
109
- };
110
- const cleanupModel = () => {
176
+ parent.lastLeaf = begin;
177
+ model.spinning += (begin.status || 0);
178
+ }
179
+ function cleanupModel() {
111
180
  var _a;
112
181
  for (const item of model) {
113
- if (!((_a = item.ref_) === null || _a === void 0 ? void 0 : _a.deref())) {
114
- model.skipLines_ += 1;
115
- item.inputId_ != null && delete itemById[item.inputId_];
182
+ if (!((_a = item.ref) === null || _a === void 0 ? void 0 : _a.deref())) {
183
+ model.skipLines += 1;
184
+ item.inputId != null && delete itemById[item.inputId];
116
185
  list.remove(item);
117
186
  }
118
187
  else {
119
188
  break;
120
189
  }
121
190
  }
122
- };
123
- model.tick_ = model.skipLines_ = model.spinning_ = 0;
124
- return [({ message: text, inputId, action, loglevel, ref, parentId, context, tag }) => {
125
- // item has status undefined, so it is static by default
126
- const item = { text_: text, loglevel_: loglevel, ref_: ref, parentId_: parentId, dirty_: true, context_: context, tag_: tag };
127
- if (action === 0 /* start */) {
128
- item.status_ = 1 /* inprogress */;
129
- }
130
- if (action === 2 /* finish */) {
131
- item.status_ = 0 /* finished */;
132
- }
133
- if (action !== 3 /* log */) {
134
- // if status still empty in the original item or item does not exists it will remain empty and static
135
- updateModel(inputId, item);
136
- }
137
- cleanupModel();
138
- if (action === 3 /* log */) {
139
- appendToModel(item, logAboveSpinners);
140
- }
141
- return model;
142
- }, () => {
143
- cleanupModel();
144
- return model;
145
- }];
146
- };
191
+ }
192
+ }
147
193
  function getLastLeaf(modelItem) {
148
194
  let lastLeaf = modelItem;
149
- while (lastLeaf.lastLeaf_) {
150
- lastLeaf = lastLeaf.lastLeaf_;
195
+ while (lastLeaf.lastLeaf) {
196
+ lastLeaf = lastLeaf.lastLeaf;
151
197
  }
152
198
  return lastLeaf;
153
199
  }
154
200
 
155
- const createDraftlogAppender = (spinner, formatter, logAboveSpinners, ident) => {
201
+ function createDraftlogAppender(spinner, formatter, logAboveSpinners, ident) {
156
202
  let interval;
157
203
  const [updateModel, getModel] = createModel(logAboveSpinners);
158
204
  const renderModel = createCanvas(spinner, formatter, ident);
159
- const checkTimeout = () => {
160
- const spinning = getModel().spinning_;
205
+ return (message) => {
206
+ renderModel(updateModel(message));
207
+ checkTimeout();
208
+ };
209
+ function checkTimeout() {
210
+ const spinning = getModel().spinning;
161
211
  if (spinning && !interval) {
162
212
  interval = setInterval(updateSpinners, spinner.interval);
163
213
  interval.unref(); // unref immidiately just in case
@@ -166,17 +216,13 @@ const createDraftlogAppender = (spinner, formatter, logAboveSpinners, ident) =>
166
216
  clearInterval(interval);
167
217
  interval = undefined;
168
218
  }
169
- };
170
- const updateSpinners = () => {
219
+ }
220
+ function updateSpinners() {
171
221
  const model = getModel();
172
- model.tick_++;
173
- model.tick_ %= spinner.frames.length;
222
+ model.tick++;
223
+ model.tick %= spinner.frames.length;
174
224
  renderModel(model);
175
- };
176
- return (message) => {
177
- renderModel(updateModel(message));
178
- checkTimeout();
179
- };
180
- };
225
+ }
226
+ }
181
227
 
182
228
  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 const createDraftlogAppender: (spinner: Spinner, formatter: Formatter, logAboveSpinners: boolean, ident: number) => (message: LogMessage) => void;
3
+ export declare function createDraftlogAppender(spinner: Spinner, formatter: Formatter, logAboveSpinners: boolean, ident: number): (message: LogMessage) => void;
package/dist/core.mjs CHANGED
@@ -1,78 +1,147 @@
1
1
  import draftlog from 'draftlog';
2
2
  import { List, prepend, append, removeRange, appendRange, remove } from '@slimlib/list';
3
3
 
4
- const createCanvas = (spinner, formatter, ident) => {
4
+ function createCanvas(spinner, formatter, ident) {
5
5
  draftlog(console);
6
6
  draftlog.defaults.canReWrite = false;
7
7
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
8
  const updaters = [];
9
- const getPrefix = (status, tick) => {
10
- // status is truthy when it is inprogress
11
- return status ? spinner.frames[tick] :
12
- // status not null when it is finished
13
- status != null;
14
- };
15
9
  return (model) => {
16
- if (model.skipLines_) {
17
- updaters.splice(0, model.skipLines_);
18
- model.skipLines_ = 0;
10
+ if (model.skipLines) {
11
+ updaters.splice(0, model.skipLines);
12
+ model.skipLines = 0;
19
13
  }
20
14
  let key = 0, dirty = false;
21
15
  const stack = [];
22
16
  for (const item of model) {
23
- let updater = updaters[Number(key)];
24
- if (!updater) {
25
- updater = console.draft(' ');
26
- updaters.push(updater);
27
- }
28
- if (dirty || item.dirty_ || item.status_) {
29
- const prefix = getPrefix(item.status_, model.tick_);
30
- updater(formatter({
31
- loglevel: item.loglevel_,
32
- message: item.text_,
33
- context: item.context_,
34
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
- action: (item.status_ === undefined ? 3 /* log */ : undefined),
36
- tag: item.tag_
37
- }, prefix, ident * stack.length));
38
- if (item.dirty_) {
39
- item.dirty_ = false;
17
+ if (dirty || item.dirty || item.status) {
18
+ let prefix = getPrefix(item.status, model.tick), prefixUpdated = false;
19
+ const subitems = substrings(item.message);
20
+ for (const message of subitems) {
21
+ let updater = updaters[key++];
22
+ if (!updater) {
23
+ updater = console.draft(' ');
24
+ updaters.push(updater);
25
+ }
26
+ updater(formatter({
27
+ loglevel: item.loglevel,
28
+ message,
29
+ context: item.context,
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ action: (item.status === undefined ? 3 /* log */ : undefined),
32
+ tag: item.tag
33
+ }, prefix, ident * stack.length));
34
+ if (subitems.length > 1 && typeof prefix === 'string' && !prefixUpdated) {
35
+ prefix = prefix.replaceAll(/./g, ' ');
36
+ prefixUpdated = true;
37
+ }
38
+ }
39
+ if (item.dirty) {
40
+ item.dirty = false;
40
41
  dirty = true;
41
42
  }
42
43
  }
43
- // iterate
44
- ++key;
44
+ else {
45
+ // iterate
46
+ key += substrings(item.message).length;
47
+ }
45
48
  if (stack[stack.length - 1] === item) {
46
49
  stack[stack.length - 1] = null;
47
50
  }
48
- if (item.lastLeaf_) {
49
- stack.push(item.lastLeaf_);
51
+ if (item.lastLeaf) {
52
+ stack.push(item.lastLeaf);
50
53
  }
51
54
  while (stack.length && stack[stack.length - 1] == null) {
52
55
  stack.pop();
53
56
  }
54
57
  }
58
+ while (key !== updaters.length) {
59
+ updaters[key++]('');
60
+ }
55
61
  };
56
- };
62
+ function getPrefix(status, tick) {
63
+ // status is truthy when it is inprogress
64
+ return status ? spinner.frames[tick] :
65
+ // status not null when it is finished
66
+ status != null;
67
+ }
68
+ }
69
+ function substrings(message) {
70
+ var _a;
71
+ return (_a = message
72
+ .match(/.{1,80}/g)) !== null && _a !== void 0 ? _a : [];
73
+ }
74
+
75
+ /******************************************************************************
76
+ Copyright (c) Microsoft Corporation.
77
+
78
+ Permission to use, copy, modify, and/or distribute this software for any
79
+ purpose with or without fee is hereby granted.
80
+
81
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
82
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
83
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
84
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
85
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
86
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
87
+ PERFORMANCE OF THIS SOFTWARE.
88
+ ***************************************************************************** */
89
+
90
+ function __rest(s, e) {
91
+ var t = {};
92
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
93
+ t[p] = s[p];
94
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
95
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
96
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
97
+ t[p[i]] = s[p[i]];
98
+ }
99
+ return t;
100
+ }
57
101
 
58
- const createModel = (logAboveSpinners) => {
102
+ function createModel(logAboveSpinners) {
59
103
  const model = new List();
60
104
  const itemById = Object.create(null);
61
- const appendToModel = (item, head) => {
105
+ model.tick = model.skipLines = model.spinning = 0;
106
+ return [(_a) => {
107
+ var { action } = _a, item = __rest(_a, ["action"]);
108
+ // item has status undefined, so it is static by default
109
+ item.dirty = true;
110
+ const { inputId } = item;
111
+ if (action === 0 /* start */) {
112
+ item.status = 1 /* inprogress */;
113
+ }
114
+ if (action === 2 /* finish */) {
115
+ item.status = 0 /* finished */;
116
+ }
117
+ if (action !== 3 /* log */) {
118
+ // if status still empty in the original item or item does not exists it will remain empty and static
119
+ updateModel(inputId, item);
120
+ }
121
+ cleanupModel();
122
+ if (action === 3 /* log */) {
123
+ appendToModel(item, logAboveSpinners);
124
+ }
125
+ return model;
126
+ }, () => {
127
+ cleanupModel();
128
+ return model;
129
+ }];
130
+ function appendToModel(item, head) {
62
131
  if (head) {
63
132
  prepend(model, item);
64
133
  }
65
134
  else {
66
135
  append(model, item);
67
136
  }
68
- model.spinning_ += (item.status_ || 0);
69
- };
70
- const updateModel = (inputId, options) => {
137
+ model.spinning += (item.status || 0);
138
+ }
139
+ function updateModel(inputId, options) {
71
140
  const modelItem = itemById[inputId];
72
141
  if (!modelItem) {
73
- const item = Object.assign({ inputId_: inputId }, options);
142
+ const item = Object.assign({ inputId: inputId }, options);
74
143
  itemById[inputId] = item;
75
- const itemParentId = item.parentId_;
144
+ const itemParentId = item.parentId;
76
145
  if (itemParentId != null) {
77
146
  putIntoChildren(itemParentId, item, item);
78
147
  }
@@ -81,81 +150,62 @@ const createModel = (logAboveSpinners) => {
81
150
  }
82
151
  }
83
152
  else {
84
- const statusDiff = (options.status_ || 0) - (modelItem.status_ || 0);
85
- const moveIntoParent = options.parentId_ != null && modelItem.parentId_ == null;
153
+ const statusDiff = (options.status || 0) - (modelItem.status || 0);
154
+ const moveIntoParent = options.parentId != null && modelItem.parentId == null;
86
155
  Object.assign(modelItem, options);
87
- model.spinning_ += statusDiff;
156
+ model.spinning += statusDiff;
88
157
  if (moveIntoParent) {
89
158
  const lastLeaf = getLastLeaf(modelItem);
90
- model.spinning_ -= (modelItem.status_ || 0);
91
- modelItem.dirty_ = true;
159
+ model.spinning -= (modelItem.status || 0);
160
+ modelItem.dirty = true;
92
161
  removeRange(modelItem, lastLeaf);
93
- putIntoChildren(modelItem.parentId_, modelItem, lastLeaf);
162
+ putIntoChildren(modelItem.parentId, modelItem, lastLeaf);
94
163
  }
95
164
  }
96
- };
97
- const putIntoChildren = (itemParentId, begin, end) => {
165
+ }
166
+ function putIntoChildren(itemParentId, begin, end) {
98
167
  let parent = itemById[itemParentId];
99
168
  if (!parent) {
100
- parent = { inputId_: itemParentId, text_: '', loglevel_: 0, ref_: new WeakRef(model) };
169
+ parent = { inputId: itemParentId, message: '', loglevel: 0, ref: new WeakRef(model) };
101
170
  appendToModel(parent, false);
102
171
  itemById[itemParentId] = parent;
103
172
  }
104
173
  appendRange((getLastLeaf(parent)), begin, end);
105
- parent.lastLeaf_ = begin;
106
- model.spinning_ += (begin.status_ || 0);
107
- };
108
- const cleanupModel = () => {
174
+ parent.lastLeaf = begin;
175
+ model.spinning += (begin.status || 0);
176
+ }
177
+ function cleanupModel() {
109
178
  var _a;
110
179
  for (const item of model) {
111
- if (!((_a = item.ref_) === null || _a === void 0 ? void 0 : _a.deref())) {
112
- model.skipLines_ += 1;
113
- item.inputId_ != null && delete itemById[item.inputId_];
180
+ if (!((_a = item.ref) === null || _a === void 0 ? void 0 : _a.deref())) {
181
+ model.skipLines += 1;
182
+ item.inputId != null && delete itemById[item.inputId];
114
183
  remove(item);
115
184
  }
116
185
  else {
117
186
  break;
118
187
  }
119
188
  }
120
- };
121
- model.tick_ = model.skipLines_ = model.spinning_ = 0;
122
- return [({ message: text, inputId, action, loglevel, ref, parentId, context, tag }) => {
123
- // item has status undefined, so it is static by default
124
- const item = { text_: text, loglevel_: loglevel, ref_: ref, parentId_: parentId, dirty_: true, context_: context, tag_: tag };
125
- if (action === 0 /* start */) {
126
- item.status_ = 1 /* inprogress */;
127
- }
128
- if (action === 2 /* finish */) {
129
- item.status_ = 0 /* finished */;
130
- }
131
- if (action !== 3 /* log */) {
132
- // if status still empty in the original item or item does not exists it will remain empty and static
133
- updateModel(inputId, item);
134
- }
135
- cleanupModel();
136
- if (action === 3 /* log */) {
137
- appendToModel(item, logAboveSpinners);
138
- }
139
- return model;
140
- }, () => {
141
- cleanupModel();
142
- return model;
143
- }];
144
- };
189
+ }
190
+ }
145
191
  function getLastLeaf(modelItem) {
146
192
  let lastLeaf = modelItem;
147
- while (lastLeaf.lastLeaf_) {
148
- lastLeaf = lastLeaf.lastLeaf_;
193
+ while (lastLeaf.lastLeaf) {
194
+ lastLeaf = lastLeaf.lastLeaf;
149
195
  }
150
196
  return lastLeaf;
151
197
  }
152
198
 
153
- const createDraftlogAppender = (spinner, formatter, logAboveSpinners, ident) => {
199
+ function createDraftlogAppender(spinner, formatter, logAboveSpinners, ident) {
154
200
  let interval;
155
201
  const [updateModel, getModel] = createModel(logAboveSpinners);
156
202
  const renderModel = createCanvas(spinner, formatter, ident);
157
- const checkTimeout = () => {
158
- const spinning = getModel().spinning_;
203
+ return (message) => {
204
+ renderModel(updateModel(message));
205
+ checkTimeout();
206
+ };
207
+ function checkTimeout() {
208
+ const spinning = getModel().spinning;
159
209
  if (spinning && !interval) {
160
210
  interval = setInterval(updateSpinners, spinner.interval);
161
211
  interval.unref(); // unref immidiately just in case
@@ -164,17 +214,13 @@ const createDraftlogAppender = (spinner, formatter, logAboveSpinners, ident) =>
164
214
  clearInterval(interval);
165
215
  interval = undefined;
166
216
  }
167
- };
168
- const updateSpinners = () => {
217
+ }
218
+ function updateSpinners() {
169
219
  const model = getModel();
170
- model.tick_++;
171
- model.tick_ %= spinner.frames.length;
220
+ model.tick++;
221
+ model.tick %= spinner.frames.length;
172
222
  renderModel(model);
173
- };
174
- return (message) => {
175
- renderModel(updateModel(message));
176
- checkTimeout();
177
- };
178
- };
223
+ }
224
+ }
179
225
 
180
226
  export { createDraftlogAppender };
@@ -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 const createCanvas: (spinner: Spinner, formatter: Formatter, ident: number) => (model: Model) => void;
4
+ export declare function createCanvas(spinner: Spinner, formatter: Formatter, ident: number): (model: Model) => void;
@@ -5,20 +5,20 @@ export declare const enum ItemStatus {
5
5
  inprogress = 1
6
6
  }
7
7
  export interface ModelItem extends Partial<ListNode> {
8
- inputId_?: number;
9
- text_: string;
10
- status_?: ItemStatus;
11
- loglevel_: LogLevel;
12
- ref_?: WeakRef<never>;
13
- parentId_?: number;
14
- dirty_?: boolean;
15
- lastLeaf_?: ModelItem;
16
- tag_?: string;
17
- context_?: any;
8
+ inputId?: number;
9
+ message: string;
10
+ status?: ItemStatus;
11
+ loglevel: LogLevel;
12
+ ref?: WeakRef<never>;
13
+ parentId?: number;
14
+ dirty?: boolean;
15
+ lastLeaf?: ModelItem;
16
+ tag?: string;
17
+ context?: any;
18
18
  }
19
19
  export declare type Model = List<ModelItem> & {
20
- skipLines_: number;
21
- tick_: number;
22
- spinning_: number;
20
+ skipLines: number;
21
+ tick: number;
22
+ spinning: number;
23
23
  };
24
- export declare const createModel: (logAboveSpinners: boolean) => [(logMessage: LogMessage) => Model, () => Model];
24
+ export declare function createModel(logAboveSpinners: boolean): [(logMessage: LogMessage) => Model, () => Model];
package/dist/index.cjs CHANGED
@@ -14,7 +14,7 @@ if (!process.env.CI) {
14
14
  const spinner = supportsUnicode ? spinners.dots : spinners.line;
15
15
  const formatter = formatUtils.createFormatter(defaultFormatting.colors, supportsUnicode ? defaultFormatting.unicodePrefixes : defaultFormatting.asciiPrefixes, defaultFormatting.tagFactory);
16
16
  let minLogLevel = 1 /* info */;
17
- globalAppender.appender(appenderUtils.filterMessages((message) => message.loglevel >= minLogLevel && message.action !== 3 /* log */, core.createDraftlogAppender(spinner, formatter, false, 2), // eslint-disable-line indent
17
+ globalAppender.appender(appenderUtils.filterMessages((message) => message.loglevel >= minLogLevel, core.createDraftlogAppender(spinner, formatter, true, 2), // eslint-disable-line indent
18
18
  { setMinLevel(logLevel) { minLogLevel = logLevel; } } // eslint-disable-line indent
19
19
  ));
20
20
  }
package/dist/index.mjs CHANGED
@@ -12,7 +12,7 @@ if (!process.env.CI) {
12
12
  const spinner = supportsUnicode ? dots : line;
13
13
  const formatter = createFormatter(colors, supportsUnicode ? unicodePrefixes : asciiPrefixes, tagFactory);
14
14
  let minLogLevel = 1 /* info */;
15
- appender(filterMessages((message) => message.loglevel >= minLogLevel && message.action !== 3 /* log */, createDraftlogAppender(spinner, formatter, false, 2), // eslint-disable-line indent
15
+ appender(filterMessages((message) => message.loglevel >= minLogLevel, createDraftlogAppender(spinner, formatter, true, 2), // eslint-disable-line indent
16
16
  { setMinLevel(logLevel) { minLogLevel = logLevel; } } // eslint-disable-line indent
17
17
  ));
18
18
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.2.8",
2
+ "version": "1.2.9",
3
3
  "license": "MIT",
4
4
  "name": "@niceties/draftlog-appender",
5
5
  "author": {