xprogress 0.19.0 → 0.19.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/README.md CHANGED
@@ -79,6 +79,7 @@ const bar = new ProgressBar(100, [20, 44]);
79
79
  - <a id="globopts:template"></a> `template`: &lt;[string][]|[string][][]&gt; The template to use for the progressbar view. This is parsed by [stringd][]. with [`this.variables`](#globopts:variables) **Default**: `''`.
80
80
  - <a id="globopts:variables"></a> `variables`: &lt;[VariableOpts](#variableopts)&gt; Variables with which to parse [`this.template`](#globopts:template), extended with [`cStringd.raw`][cstringd:raw].
81
81
  - `forceFirst`: &lt;[boolean][]&gt; Whether or not to force a multi-bar progressbar to a single bar (useful either when terminal width is too small or when filled with excess addons). **Default**: `false`.
82
+ - `writeStream`: &lt;[WriteStream][]&gt; The tty-ish writable stream we are writing to. **Default**: [stdout](https://nodejs.org/api/process.html#processstdout).
82
83
 
83
84
  The global options shared by both [ProgressBar](#progressbar) and [ProgressStream](#progressstream).
84
85
 
@@ -134,7 +135,7 @@ npm install
134
135
 
135
136
  ## License
136
137
 
137
- [Apache 2.0][license] © **Miraculous Owonubi** ([@miraclx][author-url]) &lt;omiraculous@gmail.com&gt;
138
+ [Apache 2.0][license] © **Miraculous Owonubi** ([@miraclx][author-url]) &lt;<omiraculous@gmail.com>&gt;
138
139
 
139
140
  [BarOpts]: #globopts
140
141
 
@@ -144,7 +145,6 @@ npm install
144
145
  [stringd]: https://github.com/miraclx/stringd "NodeJS String Variable Parser"
145
146
  [xbytes]: https://github.com/miraclx/xbytes "NodeJS ByteParser"
146
147
  [prettyMs]: https://github.com/sindresorhus/pretty-ms "Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`"
147
- [cstringd]: https://github.com/miraclx/stringd-colors "ANSI colors for stringd formatting"
148
148
  [pad-ratio]: https://github.com/miraclx/pad-ratio "Pad or trim an array to sum up to a maximum value"
149
149
  [hybridinput]: https://github.com/miraclx/pad-ratio#hybridinput
150
150
  [ProgressStreamSlice]: https://github.com/freeall/progress-stream#progress
@@ -152,7 +152,6 @@ npm install
152
152
  [cstringd:raw]: https://github.com/miraclx/stringd-colors#cstringdraw "Raw ANSI codes for stringd-colors"
153
153
 
154
154
  [author-url]: https://github.com/miraclx
155
- [ansi-styles]: https://github.com/chalk/ansi-styles "ANSI escape codes for styling strings in the terminal"
156
155
  [xprogress-result]: screenshots/example.gif "StringD Colors Example"
157
156
 
158
157
  [npm-url]: https://npmjs.org/package/xprogress
@@ -162,8 +161,8 @@ npm install
162
161
  [downloads-image]: https://badgen.net/npm/dm/xprogress
163
162
 
164
163
  [object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
165
- [regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
166
- [function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function
167
164
  [number]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type
168
165
  [string]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type
169
166
  [boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type
167
+
168
+ [WriteStream]: https://nodejs.org/api/tty.html#class-ttywritestream
package/index.d.ts CHANGED
@@ -425,6 +425,7 @@ namespace Core {
425
425
  template: string | string[];
426
426
  variables: ProgressBar.VariableOpts;
427
427
  forceFirst: boolean;
428
+ writeStream: WriteStream;
428
429
  }
429
430
  interface SpecOpts {
430
431
  blot: boolean;
package/index.js CHANGED
@@ -87,16 +87,26 @@ const streamOpts = {
87
87
  * Get a persistent tty output stream
88
88
  * @returns {tty.WriteStream} The writable stream instance similar to `process.stdout`
89
89
  */
90
- function getPersistentStdout() {
90
+ export function getPersistentStdout(device = getPersistentStdout.stdout) {
91
91
  const self = getPersistentStdout;
92
92
  self.stdout =
93
- self.stdout && self.stdout.isTTY
93
+ device && device.isTTY
94
+ ? device
95
+ : self.stdout && self.stdout.isTTY
94
96
  ? self.stdout
95
97
  : process.stdout.isTTY
96
98
  ? process.stdout
97
99
  : process.stderr.isTTY
98
100
  ? process.stderr
99
- : new tty.WriteStream(openSync('/dev/tty', 'w'));
101
+ : null;
102
+ if (!self.stdout) {
103
+ try {
104
+ const fd = openSync('/dev/tty', 'w');
105
+ self.stdout = new tty.WriteStream(fd);
106
+ } catch (e) {
107
+ if (e.code !== 'ENXIO') throw e;
108
+ }
109
+ }
100
110
  return self.stdout;
101
111
  }
102
112
 
@@ -179,7 +189,7 @@ export default class ProgressBar {
179
189
  label: this.opts.label,
180
190
  append: [],
181
191
  length: this.opts.length,
182
- stdout: getPersistentStdout(),
192
+ stdout: getPersistentStdout(this.opts.writeStream),
183
193
  pulsateSlots: [
184
194
  [0, 0],
185
195
  [this.opts.bar.pulsateLength, 100],
@@ -218,7 +228,7 @@ export default class ProgressBar {
218
228
  * @param {number} [value] The value to set the progressBar length to
219
229
  */
220
230
  length(value) {
221
- const len = getPersistentStdout().columns;
231
+ const len = this.cores.stdout.columns;
222
232
  const core = this.cores.length;
223
233
  if (value && ['function', 'number'].includes(typeof value)) {
224
234
  this.cores.length = value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xprogress",
3
- "version": "0.19.0",
3
+ "version": "0.19.2",
4
4
  "description": "Dynamic, Flexible, extensible progressive CLI bar for the terminal built with NodeJS",
5
5
  "exports": "./index.js",
6
6
  "type": "module",
@@ -41,7 +41,6 @@
41
41
  "devDependencies": {
42
42
  "eslint": "8.19.0",
43
43
  "eslint-plugin-prettier": "4.2.1",
44
- "jest": "^28.1.2",
45
44
  "prettier": "2.7.1"
46
45
  },
47
46
  "dependencies": {
@@ -53,10 +52,5 @@
53
52
  "stringd": "^2.2.0",
54
53
  "stringd-colors": "^1.10.0",
55
54
  "xbytes": "^1.6.1"
56
- },
57
- "homepage": "https://github.com/miraclx/xprogress#readme",
58
- "directories": {
59
- "lib": "lib",
60
- "test": "test"
61
55
  }
62
56
  }