@niceties/draftlog-appender 1.2.7 → 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,77 +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
- let lastLeaf = modelItem;
92
- while (lastLeaf.lastLeaf_) {
93
- lastLeaf = lastLeaf.lastLeaf_;
94
- }
95
- model.spinning_ -= (modelItem.status_ || 0);
96
- modelItem.dirty_ = true;
160
+ const lastLeaf = getLastLeaf(modelItem);
161
+ model.spinning -= (modelItem.status || 0);
162
+ modelItem.dirty = true;
97
163
  list.removeRange(modelItem, lastLeaf);
98
- putIntoChildren(modelItem.parentId_, modelItem, lastLeaf);
164
+ putIntoChildren(modelItem.parentId, modelItem, lastLeaf);
99
165
  }
100
166
  }
101
- };
102
- const putIntoChildren = (itemParentId, begin, end) => {
167
+ }
168
+ function putIntoChildren(itemParentId, begin, end) {
103
169
  let parent = itemById[itemParentId];
104
170
  if (!parent) {
105
- parent = { inputId_: itemParentId, text_: '', loglevel_: 0, ref_: new WeakRef(model) };
171
+ parent = { inputId: itemParentId, message: '', loglevel: 0, ref: new WeakRef(model) };
106
172
  appendToModel(parent, false);
107
173
  itemById[itemParentId] = parent;
108
174
  }
109
- list.appendRange((parent.lastLeaf_ || parent), begin, end);
110
- parent.lastLeaf_ = begin;
111
- model.spinning_ += (begin.status_ || 0);
112
- };
113
- const cleanupModel = () => {
175
+ list.appendRange((getLastLeaf(parent)), begin, end);
176
+ parent.lastLeaf = begin;
177
+ model.spinning += (begin.status || 0);
178
+ }
179
+ function cleanupModel() {
114
180
  var _a;
115
181
  for (const item of model) {
116
- if (!((_a = item.ref_) === null || _a === void 0 ? void 0 : _a.deref())) {
117
- model.skipLines_ += 1;
118
- 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];
119
185
  list.remove(item);
120
186
  }
121
187
  else {
122
188
  break;
123
189
  }
124
190
  }
125
- };
126
- model.tick_ = model.skipLines_ = model.spinning_ = 0;
127
- return [({ message: text, inputId, action, loglevel, ref, parentId, context, tag }) => {
128
- // item has status undefined, so it is static by default
129
- const item = { text_: text, loglevel_: loglevel, ref_: ref, parentId_: parentId, dirty_: true, context_: context, tag_: tag };
130
- if (action === 0 /* start */) {
131
- item.status_ = 1 /* inprogress */;
132
- }
133
- if (action === 2 /* finish */) {
134
- item.status_ = 0 /* finished */;
135
- }
136
- if (action !== 3 /* log */) {
137
- // if status still empty in the original item or item does not exists it will remain empty and static
138
- updateModel(inputId, item);
139
- }
140
- cleanupModel();
141
- if (action === 3 /* log */) {
142
- appendToModel(item, logAboveSpinners);
143
- }
144
- return model;
145
- }, () => {
146
- cleanupModel();
147
- return model;
148
- }];
149
- };
191
+ }
192
+ }
193
+ function getLastLeaf(modelItem) {
194
+ let lastLeaf = modelItem;
195
+ while (lastLeaf.lastLeaf) {
196
+ lastLeaf = lastLeaf.lastLeaf;
197
+ }
198
+ return lastLeaf;
199
+ }
150
200
 
151
- const createDraftlogAppender = (spinner, formatter, logAboveSpinners, ident) => {
201
+ function createDraftlogAppender(spinner, formatter, logAboveSpinners, ident) {
152
202
  let interval;
153
203
  const [updateModel, getModel] = createModel(logAboveSpinners);
154
204
  const renderModel = createCanvas(spinner, formatter, ident);
155
- const checkTimeout = () => {
156
- const spinning = getModel().spinning_;
205
+ return (message) => {
206
+ renderModel(updateModel(message));
207
+ checkTimeout();
208
+ };
209
+ function checkTimeout() {
210
+ const spinning = getModel().spinning;
157
211
  if (spinning && !interval) {
158
212
  interval = setInterval(updateSpinners, spinner.interval);
159
213
  interval.unref(); // unref immidiately just in case
@@ -162,17 +216,13 @@ const createDraftlogAppender = (spinner, formatter, logAboveSpinners, ident) =>
162
216
  clearInterval(interval);
163
217
  interval = undefined;
164
218
  }
165
- };
166
- const updateSpinners = () => {
219
+ }
220
+ function updateSpinners() {
167
221
  const model = getModel();
168
- model.tick_++;
169
- model.tick_ %= spinner.frames.length;
222
+ model.tick++;
223
+ model.tick %= spinner.frames.length;
170
224
  renderModel(model);
171
- };
172
- return (message) => {
173
- renderModel(updateModel(message));
174
- checkTimeout();
175
- };
176
- };
225
+ }
226
+ }
177
227
 
178
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,77 +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
- let lastLeaf = modelItem;
90
- while (lastLeaf.lastLeaf_) {
91
- lastLeaf = lastLeaf.lastLeaf_;
92
- }
93
- model.spinning_ -= (modelItem.status_ || 0);
94
- modelItem.dirty_ = true;
158
+ const lastLeaf = getLastLeaf(modelItem);
159
+ model.spinning -= (modelItem.status || 0);
160
+ modelItem.dirty = true;
95
161
  removeRange(modelItem, lastLeaf);
96
- putIntoChildren(modelItem.parentId_, modelItem, lastLeaf);
162
+ putIntoChildren(modelItem.parentId, modelItem, lastLeaf);
97
163
  }
98
164
  }
99
- };
100
- const putIntoChildren = (itemParentId, begin, end) => {
165
+ }
166
+ function putIntoChildren(itemParentId, begin, end) {
101
167
  let parent = itemById[itemParentId];
102
168
  if (!parent) {
103
- parent = { inputId_: itemParentId, text_: '', loglevel_: 0, ref_: new WeakRef(model) };
169
+ parent = { inputId: itemParentId, message: '', loglevel: 0, ref: new WeakRef(model) };
104
170
  appendToModel(parent, false);
105
171
  itemById[itemParentId] = parent;
106
172
  }
107
- appendRange((parent.lastLeaf_ || parent), begin, end);
108
- parent.lastLeaf_ = begin;
109
- model.spinning_ += (begin.status_ || 0);
110
- };
111
- const cleanupModel = () => {
173
+ appendRange((getLastLeaf(parent)), begin, end);
174
+ parent.lastLeaf = begin;
175
+ model.spinning += (begin.status || 0);
176
+ }
177
+ function cleanupModel() {
112
178
  var _a;
113
179
  for (const item of model) {
114
- if (!((_a = item.ref_) === null || _a === void 0 ? void 0 : _a.deref())) {
115
- model.skipLines_ += 1;
116
- 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];
117
183
  remove(item);
118
184
  }
119
185
  else {
120
186
  break;
121
187
  }
122
188
  }
123
- };
124
- model.tick_ = model.skipLines_ = model.spinning_ = 0;
125
- return [({ message: text, inputId, action, loglevel, ref, parentId, context, tag }) => {
126
- // item has status undefined, so it is static by default
127
- const item = { text_: text, loglevel_: loglevel, ref_: ref, parentId_: parentId, dirty_: true, context_: context, tag_: tag };
128
- if (action === 0 /* start */) {
129
- item.status_ = 1 /* inprogress */;
130
- }
131
- if (action === 2 /* finish */) {
132
- item.status_ = 0 /* finished */;
133
- }
134
- if (action !== 3 /* log */) {
135
- // if status still empty in the original item or item does not exists it will remain empty and static
136
- updateModel(inputId, item);
137
- }
138
- cleanupModel();
139
- if (action === 3 /* log */) {
140
- appendToModel(item, logAboveSpinners);
141
- }
142
- return model;
143
- }, () => {
144
- cleanupModel();
145
- return model;
146
- }];
147
- };
189
+ }
190
+ }
191
+ function getLastLeaf(modelItem) {
192
+ let lastLeaf = modelItem;
193
+ while (lastLeaf.lastLeaf) {
194
+ lastLeaf = lastLeaf.lastLeaf;
195
+ }
196
+ return lastLeaf;
197
+ }
148
198
 
149
- const createDraftlogAppender = (spinner, formatter, logAboveSpinners, ident) => {
199
+ function createDraftlogAppender(spinner, formatter, logAboveSpinners, ident) {
150
200
  let interval;
151
201
  const [updateModel, getModel] = createModel(logAboveSpinners);
152
202
  const renderModel = createCanvas(spinner, formatter, ident);
153
- const checkTimeout = () => {
154
- const spinning = getModel().spinning_;
203
+ return (message) => {
204
+ renderModel(updateModel(message));
205
+ checkTimeout();
206
+ };
207
+ function checkTimeout() {
208
+ const spinning = getModel().spinning;
155
209
  if (spinning && !interval) {
156
210
  interval = setInterval(updateSpinners, spinner.interval);
157
211
  interval.unref(); // unref immidiately just in case
@@ -160,17 +214,13 @@ const createDraftlogAppender = (spinner, formatter, logAboveSpinners, ident) =>
160
214
  clearInterval(interval);
161
215
  interval = undefined;
162
216
  }
163
- };
164
- const updateSpinners = () => {
217
+ }
218
+ function updateSpinners() {
165
219
  const model = getModel();
166
- model.tick_++;
167
- model.tick_ %= spinner.frames.length;
220
+ model.tick++;
221
+ model.tick %= spinner.frames.length;
168
222
  renderModel(model);
169
- };
170
- return (message) => {
171
- renderModel(updateModel(message));
172
- checkTimeout();
173
- };
174
- };
223
+ }
224
+ }
175
225
 
176
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.7",
2
+ "version": "1.2.9",
3
3
  "license": "MIT",
4
4
  "name": "@niceties/draftlog-appender",
5
5
  "author": {
@@ -74,7 +74,7 @@
74
74
  "pkgbld-internal": "1.0.4"
75
75
  },
76
76
  "peerDependencies": {
77
- "@niceties/logger": "^1.1.9"
77
+ "@niceties/logger": "^1.1.10"
78
78
  },
79
79
  "dependencies": {
80
80
  "draftlog": "^1.0.13",