@niceties/draftlog-appender 1.0.6 → 1.0.7

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
@@ -9,7 +9,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
9
9
  var draftlog__default = /*#__PURE__*/_interopDefaultLegacy(draftlog);
10
10
 
11
11
  function createCanvas(spinner, formatter, ident) {
12
- draftlog__default["default"](console).addLineListener(process.stdin);
12
+ draftlog__default["default"](console);
13
13
  draftlog__default["default"].defaults.canReWrite = false;
14
14
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
15
  const updaters = [];
@@ -21,7 +21,7 @@ function createCanvas(spinner, formatter, ident) {
21
21
  if (!model.items_.length) {
22
22
  return;
23
23
  }
24
- let key = 0;
24
+ let key = 0, dirty = false;
25
25
  const stack = [[...model.items_]];
26
26
  while (stack.length) {
27
27
  const item = stack[stack.length - 1].shift();
@@ -30,8 +30,14 @@ function createCanvas(spinner, formatter, ident) {
30
30
  updater = console.draft(' ');
31
31
  updaters.push(updater);
32
32
  }
33
- const prefix = getMessageFormat(item.status_, model.tick_);
34
- updater(formatter(item.text_, item.loglevel_, prefix, ident * (stack.length - 1)));
33
+ if (dirty || item.dirty_ || item.status_) {
34
+ const prefix = getMessageFormat(item.status_, model.tick_);
35
+ updater(formatter(item.text_, item.loglevel_, prefix, ident * (stack.length - 1)));
36
+ if (item.dirty_) {
37
+ item.dirty_ = false;
38
+ dirty = true;
39
+ }
40
+ }
35
41
  // iterate
36
42
  ++key;
37
43
  if (item.children_.length) {
@@ -61,7 +67,7 @@ function createModel(logAboveSpinners) {
61
67
  const itemById = Object.create(null);
62
68
  return [({ message: text, inputId, action, loglevel, ref, parentId }) => {
63
69
  // item has status undefined, so it is static by default
64
- const item = { text_: text, loglevel_: loglevel, ref_: ref, parentId_: parentId, children_: [] };
70
+ const item = { text_: text, loglevel_: loglevel, ref_: ref, parentId_: parentId, children_: [], dirty_: true };
65
71
  if (action === 0 /* start */) {
66
72
  item.status_ = 1 /* inprogress */;
67
73
  }
@@ -107,6 +113,7 @@ function createModel(logAboveSpinners) {
107
113
  if (moveIntoParent) {
108
114
  model.items_ = model.items_.filter(item => item !== modelItem);
109
115
  model.spinning_ -= (modelItem.status_ || 0);
116
+ modelItem.dirty_ = true;
110
117
  putIntoChildren(modelItem.parentId_, modelItem);
111
118
  }
112
119
  }
package/dist/core.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import draftlog from 'draftlog';
2
2
 
3
3
  function createCanvas(spinner, formatter, ident) {
4
- draftlog(console).addLineListener(process.stdin);
4
+ draftlog(console);
5
5
  draftlog.defaults.canReWrite = false;
6
6
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
7
  const updaters = [];
@@ -13,7 +13,7 @@ function createCanvas(spinner, formatter, ident) {
13
13
  if (!model.items_.length) {
14
14
  return;
15
15
  }
16
- let key = 0;
16
+ let key = 0, dirty = false;
17
17
  const stack = [[...model.items_]];
18
18
  while (stack.length) {
19
19
  const item = stack[stack.length - 1].shift();
@@ -22,8 +22,14 @@ function createCanvas(spinner, formatter, ident) {
22
22
  updater = console.draft(' ');
23
23
  updaters.push(updater);
24
24
  }
25
- const prefix = getMessageFormat(item.status_, model.tick_);
26
- updater(formatter(item.text_, item.loglevel_, prefix, ident * (stack.length - 1)));
25
+ if (dirty || item.dirty_ || item.status_) {
26
+ const prefix = getMessageFormat(item.status_, model.tick_);
27
+ updater(formatter(item.text_, item.loglevel_, prefix, ident * (stack.length - 1)));
28
+ if (item.dirty_) {
29
+ item.dirty_ = false;
30
+ dirty = true;
31
+ }
32
+ }
27
33
  // iterate
28
34
  ++key;
29
35
  if (item.children_.length) {
@@ -53,7 +59,7 @@ function createModel(logAboveSpinners) {
53
59
  const itemById = Object.create(null);
54
60
  return [({ message: text, inputId, action, loglevel, ref, parentId }) => {
55
61
  // item has status undefined, so it is static by default
56
- const item = { text_: text, loglevel_: loglevel, ref_: ref, parentId_: parentId, children_: [] };
62
+ const item = { text_: text, loglevel_: loglevel, ref_: ref, parentId_: parentId, children_: [], dirty_: true };
57
63
  if (action === 0 /* start */) {
58
64
  item.status_ = 1 /* inprogress */;
59
65
  }
@@ -99,6 +105,7 @@ function createModel(logAboveSpinners) {
99
105
  if (moveIntoParent) {
100
106
  model.items_ = model.items_.filter(item => item !== modelItem);
101
107
  model.spinning_ -= (modelItem.status_ || 0);
108
+ modelItem.dirty_ = true;
102
109
  putIntoChildren(modelItem.parentId_, modelItem);
103
110
  }
104
111
  }
@@ -12,6 +12,7 @@ export interface ModelItem {
12
12
  parentId_?: number;
13
13
  next_?: ModelItem;
14
14
  children_: ModelItem[];
15
+ dirty_?: boolean;
15
16
  }
16
17
  export declare type Model = {
17
18
  items_: ModelItem[];
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.6",
2
+ "version": "1.0.7",
3
3
  "license": "MIT",
4
4
  "name": "@niceties/draftlog-appender",
5
5
  "author": {