@mpen/progressbar 0.1.3 → 0.1.5

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/index.d.mts CHANGED
@@ -44,6 +44,10 @@ declare const ProgressBarPartialBlocks: {
44
44
  */
45
45
  readonly thatched: "│║╫█";
46
46
  readonly amstrad: "▘▖▍▚▞▛▙▉";
47
+ /**
48
+ * A thin, horizontally centered continuous bar.
49
+ */
50
+ readonly thin: "━";
47
51
  };
48
52
  /**
49
53
  * Built-in fractional progress bar segment character sets.
@@ -86,6 +90,14 @@ interface ProgressBarOptions {
86
90
  * Characters used for fractional bar segments between whole terminal cells.
87
91
  */
88
92
  partialBlocks?: ProgressBarPartialBlockPreset | string;
93
+ /**
94
+ * Character used for empty bar segments. Defaults to ' ' (space).
95
+ */
96
+ emptyBlock?: string;
97
+ /**
98
+ * Whether to format output with ANSI colors. Defaults to true.
99
+ */
100
+ enableColors?: boolean;
89
101
  }
90
102
  /**
91
103
  * Render an updating progress bar to stdout.
@@ -141,6 +153,10 @@ declare class ProgressBar {
141
153
  * ```
142
154
  */
143
155
  partialBlocks: string;
156
+ /**
157
+ * Character used for empty bar segments.
158
+ */
159
+ emptyBlock: string;
144
160
  private intFmt;
145
161
  private oneDecimalFmt;
146
162
  private twoDecimalFmt;
@@ -148,6 +164,7 @@ declare class ProgressBar {
148
164
  private lastRenderTime?;
149
165
  private lastStrLength?;
150
166
  private startTime;
167
+ private colors;
151
168
  /**
152
169
  * Create a progress bar.
153
170
  *
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import chalk from "chalk";
1
+ import { AnsiColors } from "@mpen/ansi-colors/class";
2
2
  import stringWidth from "string-width";
3
3
  //#region src/index.ts
4
4
  /**
@@ -45,7 +45,11 @@ const ProgressBarPartialBlocks = {
45
45
  * Box-drawing density progression.
46
46
  */
47
47
  thatched: "│║╫█",
48
- amstrad: "▘▖▍▚▞▛▙▉"
48
+ amstrad: "▘▖▍▚▞▛▙▉",
49
+ /**
50
+ * A thin, horizontally centered continuous bar.
51
+ */
52
+ thin: "━"
49
53
  };
50
54
  /**
51
55
  * Render an updating progress bar to stdout.
@@ -101,6 +105,10 @@ var ProgressBar = class {
101
105
  * ```
102
106
  */
103
107
  partialBlocks;
108
+ /**
109
+ * Character used for empty bar segments.
110
+ */
111
+ emptyBlock;
104
112
  intFmt;
105
113
  oneDecimalFmt;
106
114
  twoDecimalFmt;
@@ -108,16 +116,22 @@ var ProgressBar = class {
108
116
  lastRenderTime;
109
117
  lastStrLength;
110
118
  startTime = process.hrtime.bigint();
119
+ colors;
111
120
  constructor(maxOrOptions = 1, width = null, start = true) {
112
121
  const options = typeof maxOrOptions === "object" ? maxOrOptions : {
113
122
  max: maxOrOptions,
114
123
  width,
115
124
  start
116
125
  };
126
+ this.colors = new AnsiColors(options.enableColors);
117
127
  this.max = options.max ?? 1;
118
128
  this.width = options.width || Math.max((process.stdout.columns ?? 80) - 40, 16);
119
129
  this.msPerFrame = 1e3 / (options.fps ?? 30);
120
130
  this.partialBlocks = options.partialBlocks ?? ProgressBarPartialBlocks.smooth;
131
+ const fullBlock = this.partialBlocks.length > 0 ? this.partialBlocks.charAt(this.partialBlocks.length - 1) : "█";
132
+ this.emptyBlock = options.emptyBlock ?? " ";
133
+ if (!this.colors.isColorSupported && this.emptyBlock === fullBlock && this.emptyBlock !== " ") if (this.emptyBlock === "━") this.emptyBlock = "─";
134
+ else this.emptyBlock = " ";
121
135
  this.intFmt = Intl.NumberFormat(void 0, {});
122
136
  this.oneDecimalFmt = Intl.NumberFormat(void 0, {
123
137
  minimumFractionDigits: 1,
@@ -174,14 +188,21 @@ var ProgressBar = class {
174
188
  const frac = barLength - fullBars;
175
189
  const elapsed = process.hrtime.bigint() - this.startTime;
176
190
  const elapsedSeconds = Number(elapsed / 10000n) / 1e5;
177
- const quantStr = this.current === this.max ? chalk.whiteBright(this.intFmt.format(this.max)) : `${chalk.whiteBright(this.intFmt.format(this.current))}/${chalk.whiteBright(this.intFmt.format(this.max))}`;
178
- let filler = "█".repeat(fullBars);
191
+ const quantStr = this.current === this.max ? this.colors.whiteBright(this.intFmt.format(this.max)) : `${this.colors.whiteBright(this.intFmt.format(this.current))}/${this.colors.whiteBright(this.intFmt.format(this.max))}`;
192
+ let filler = (this.partialBlocks.length > 0 ? this.partialBlocks.charAt(this.partialBlocks.length - 1) : "█").repeat(fullBars);
179
193
  if (frac > 0) {
180
194
  const subLen = stringWidth(this.partialBlocks) + 1;
181
195
  const si = Math.floor(frac * subLen);
182
196
  if (si > 0) filler += this.partialBlocks.charAt(si - 1);
183
197
  }
184
- let fullLine = `${percentStr} ${chalk.bgBlackBright[fgColor](filler.padEnd(innerWidth, " "))} ${quantStr}`;
198
+ let barStr;
199
+ if (this.emptyBlock === " ") barStr = this.colors.bgBlackBright(this.colors[fgColor](filler.padEnd(innerWidth, this.emptyBlock)));
200
+ else {
201
+ const emptyStr = this.colors.blackBright(this.emptyBlock.repeat(Math.max(0, innerWidth - stringWidth(filler))));
202
+ barStr = this.colors[fgColor](filler) + emptyStr;
203
+ }
204
+ let fullLine = `${percentStr} ${barStr} ${quantStr}`;
205
+ const sectionSeparator = this.colors.blackBright("│");
185
206
  if (this.current > 0) {
186
207
  let estimatedRemaining = 0;
187
208
  if (this.current === this.max) estimatedRemaining = elapsedSeconds;
@@ -192,14 +213,14 @@ var ProgressBar = class {
192
213
  if (estimatedRemaining >= 60 || elapsedSeconds >= 60) {
193
214
  const minutes = Math.floor(estimatedRemaining / 60);
194
215
  const seconds = Math.floor(estimatedRemaining % 60);
195
- fullLine += ` │ ${minutes}m${String(seconds).padStart(2, "0")}s`;
216
+ fullLine += ` ${sectionSeparator} ${minutes}m${String(seconds).padStart(2, "0")}s`;
196
217
  } else {
197
218
  const secondsFmt = estimatedRemaining < 10 ? this.twoDecimalFmt : this.oneDecimalFmt;
198
- fullLine += ` │ ${secondsFmt.format(estimatedRemaining)}s`;
219
+ fullLine += ` ${sectionSeparator} ${secondsFmt.format(estimatedRemaining)}s`;
199
220
  }
200
221
  const itemsPerSecond = this.current > 0 ? this.current / elapsedSeconds : 0;
201
222
  const rateFmt = itemsPerSecond < 10 ? this.twoDecimalFmt : this.oneDecimalFmt;
202
- fullLine += ` │ ${rateFmt.format(itemsPerSecond)} it/s`;
223
+ fullLine += ` ${sectionSeparator} ${rateFmt.format(itemsPerSecond)} it/s`;
203
224
  }
204
225
  if (fullLine === this.lastLine) return;
205
226
  this.lastLine = fullLine;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpen/progressbar",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Terminal progress bar utilities.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -17,21 +17,21 @@
17
17
  },
18
18
  "types": "./dist/index.d.mts",
19
19
  "dependencies": {
20
- "chalk": "^5",
20
+ "@mpen/ansi-colors": "0.1.3",
21
21
  "string-width": "^8.2.0"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/bun": "latest",
25
25
  "tsdown": "^0.21",
26
- "typescript": "^6"
26
+ "typescript": "^7"
27
27
  },
28
28
  "scripts": {
29
29
  "build": "bun run --bun tsdown",
30
30
  "dev": "bun src/dev.ts"
31
31
  },
32
32
  "publishHash": {
33
- "buildDate": "2026-06-16T22:14:31.531-07:00",
34
- "hgChangesetId": "00400982d9ae+",
35
- "sha256": "61f227820c40ddb16fe2a67a841fe088e7a8bf2dc1341c57767f094eec97e787"
33
+ "buildDate": "2026-07-19T13:11:32.803-07:00",
34
+ "hgChangesetId": "64fa6dfda1bd+",
35
+ "sha256": "78588a8644e866067a2a522ed80f4c692f25c2ae1ae88fb19184512a55c55aac"
36
36
  }
37
37
  }