@mpen/progressbar 0.1.6 → 0.1.8

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
@@ -1,3 +1,48 @@
1
1
  # @mpen/progressbar
2
2
 
3
3
  Terminal progress bar utilities.
4
+
5
+ ## Usage
6
+
7
+ ```ts
8
+ import { setTimeout } from 'node:timers/promises'
9
+ import ProgressBar from '@mpen/progressbar'
10
+
11
+ const progress = new ProgressBar({ max: 100 })
12
+
13
+ for (let i = 0; i < 100; ++i) {
14
+ await setTimeout(25) // Replace with your actual work.
15
+ progress.tick()
16
+ }
17
+
18
+ progress.complete()
19
+ ```
20
+
21
+ The bar starts immediately and writes to stdout. Call `tick()` after each item,
22
+ `tick(count)` after a batch, or `update(count)` to set the absolute completed count.
23
+ Call `complete()` to render 100% and finish with a newline.
24
+
25
+ ## Customization
26
+
27
+ ```ts
28
+ import ProgressBar, { ProgressBarPartialBlocks } from '@mpen/progressbar'
29
+
30
+ const progress = new ProgressBar({
31
+ max: 100,
32
+ width: 40,
33
+ fps: 30,
34
+ partialBlocks: ProgressBarPartialBlocks.shades,
35
+ emptyBlock: '·',
36
+ enableColors: false,
37
+ start: false,
38
+ })
39
+
40
+ progress.start()
41
+ progress.update(25)
42
+ progress.logLine('Finished the first batch')
43
+ progress.tick(75)
44
+ progress.complete()
45
+ ```
46
+
47
+ Use `logLine()` to write messages above the active bar. If work stops early, call
48
+ `interrupt()` to render the current progress and finish with a newline.
package/dist/index.mjs CHANGED
@@ -210,7 +210,15 @@ var ProgressBar = class {
210
210
  const progressRate = this.current / elapsedSeconds;
211
211
  estimatedRemaining = (this.max - this.current) / progressRate;
212
212
  }
213
- if (estimatedRemaining >= 60 || elapsedSeconds >= 60) {
213
+ if (estimatedRemaining >= 6e3 * 60) {
214
+ const days = Math.floor(estimatedRemaining / (1440 * 60));
215
+ const hours = Math.floor(estimatedRemaining / 3600 % 24);
216
+ fullLine += ` ${sectionSeparator} ${days}d${String(hours).padStart(2, "0")}h`;
217
+ } else if (estimatedRemaining >= 6e3) {
218
+ const hours = Math.floor(estimatedRemaining / 3600);
219
+ const minutes = Math.floor(estimatedRemaining / 60 % 60);
220
+ fullLine += ` ${sectionSeparator} ${hours}h${String(minutes).padStart(2, "0")}m`;
221
+ } else if (estimatedRemaining >= 60 || elapsedSeconds >= 60) {
214
222
  const minutes = Math.floor(estimatedRemaining / 60);
215
223
  const seconds = Math.floor(estimatedRemaining % 60);
216
224
  fullLine += ` ${sectionSeparator} ${minutes}m${String(seconds).padStart(2, "0")}s`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpen/progressbar",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Terminal progress bar utilities.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -17,12 +17,12 @@
17
17
  },
18
18
  "types": "./dist/index.d.mts",
19
19
  "dependencies": {
20
- "@mpen/ansi-colors": "0.2.1",
20
+ "@mpen/ansi-colors": "0.3.0",
21
21
  "string-width": "^8.2.0"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/bun": "^1.4",
25
- "tsdown": "^0.21",
25
+ "tsdown": "^0.22",
26
26
  "typescript": "^7"
27
27
  },
28
28
  "scripts": {
@@ -30,8 +30,8 @@
30
30
  "dev": "bun src/dev.ts"
31
31
  },
32
32
  "publishHash": {
33
- "buildDate": "2026-09-07T13:41:34.579-07:00",
34
- "hgChangesetId": "08b0b8569f56+",
35
- "sha256": "ee48ebda7d1b75603b5e7392ec8ef91ecd0f198459b234fbbade56f65fc4147a"
33
+ "buildDate": "2026-10-04T20:49:25.311-07:00",
34
+ "hgChangesetId": "36f79ac2bb8e+",
35
+ "sha256": "7716c28611411cfd7826d4a6e5006281626208711a5de2903b23d39efcc73091"
36
36
  }
37
37
  }