Skip to content

Commit f628fa9

Browse files
committed
shrink progress bar to fit
1 parent 553bb96 commit f628fa9

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

.changeset/sour-rooms-visit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bluecadet/launchpad-content": patch
3+
---
4+
5+
Fix progress bars wrapping on small terminals

packages/content/src/plugins/contentPluginHelpers.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,14 @@ export class CacheProgressLogger extends FixedConsoleLogger {
8787
this.update();
8888
}
8989

90-
#renderProgressBar() {
90+
protected renderProgressBar(additionalCharCount = 0): string {
9191
const total = this.#total;
9292
const fresh = this.#fresh;
9393
const cached = this.#cached;
94-
const BAR_LENGTH = 60;
94+
const BAR_LENGTH = Math.min(
95+
60,
96+
process.stdout.columns ? Math.floor(process.stdout.columns - additionalCharCount) : 60,
97+
);
9598

9699
// Calculate exact segments
97100
const freshLength = Math.round((fresh / total) * BAR_LENGTH);
@@ -107,6 +110,6 @@ export class CacheProgressLogger extends FixedConsoleLogger {
107110
}
108111

109112
override getFixedConsoleMessage(): string {
110-
return `${this.#renderProgressBar()}`;
113+
return `${this.renderProgressBar()}`;
111114
}
112115
}

packages/content/src/plugins/media-downloader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,9 @@ class QueueError extends MediaDownloaderError {
481481

482482
class MediaDownloaderProgressLogger extends CacheProgressLogger {
483483
override getFixedConsoleMessage(): string {
484+
const prefix = "Syncing Media: ";
484485
return (
485-
`Syncing Media: ${super.getFixedConsoleMessage()}\n` +
486+
`${prefix}${super.renderProgressBar(prefix.length)}\n` +
486487
`Fetched: ${chalk.green(this.fresh)}, Cached: ${chalk.yellow(this.cached)}, Remaining: ${this.total - this.fresh - this.cached} \n`
487488
);
488489
}

packages/content/src/plugins/sharp.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,9 @@ function getOutputFilename(inputPath: string, sharpTransform: Sharp.Sharp) {
285285

286286
class SharpProgressLogger extends CacheProgressLogger {
287287
override getFixedConsoleMessage(): string {
288+
const prefix = "Transforming Images: ";
288289
return (
289-
`Transforming Images: ${super.getFixedConsoleMessage()}\n` +
290+
`${prefix}${super.renderProgressBar(prefix.length)}\n` +
290291
`Transformed: ${chalk.green(this.fresh)}, Cached: ${chalk.yellow(this.cached)}, Remaining: ${this.total - this.fresh - this.cached} \n`
291292
);
292293
}

0 commit comments

Comments
 (0)