Skip to content

Commit

Permalink
fix(cli): space jump in cli progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ido-pluto committed Sep 22, 2024
1 parent 6b70969 commit d8d504d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export default class BaseTransferCliProgressBar implements TransferCliProgressBa


protected getETA(spacer = " | "): DataLine {
const formatedTimeLeft = this.status.timeLeft < 1_000 ? "0s" : this.status.formatTimeLeft;
const timeLeft = `${formatedTimeLeft.padStart("10s".length)} left`;
if (this.showETA) {
return [{
type: "spacer",
Expand All @@ -103,12 +105,8 @@ export default class BaseTransferCliProgressBar implements TransferCliProgressBa
formatter: (text) => text
}, {
type: "timeLeft",
fullText: this.status.formatTimeLeft,
size: Math.max("100ms".length, this.status.formatTimeLeft.length)
}, {
type: "timeLeft",
fullText: " left",
size: " left".length
fullText: timeLeft,
size: timeLeft.length
}];
}

Expand Down Expand Up @@ -189,7 +187,7 @@ export default class BaseTransferCliProgressBar implements TransferCliProgressBa
{
type: "speed",
fullText: formattedSpeed,
size: "000.00kB/s".length
size: "00.00kB/s".length
},
...this.getETA()
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class FancyTransferCliProgressBar extends BaseTransferCliProgress
}, {
type: "speed",
fullText: formattedSpeed,
size: "000.00kB/s".length
size: "00.00kB/s".length
}, ...this.getETA(" ")]);
}

Expand Down
31 changes: 7 additions & 24 deletions src/download/transfer-visualize/utils/data-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@ export function renderDataPart(dataPart: DataPart) {
let text = dataPart.fullText;

if (dataPart.cropper != null) {
text = padEqually(
dataPart
.cropper(text, dataPart.size)
.slice(0, dataPart.size),
dataPart.size
);
text = dataPart
.cropper(text, dataPart.size)
.slice(0, dataPart.size)
.padEnd(dataPart.size);
} else {
text = padEqually(
text.slice(0, dataPart.size),
dataPart.size
);
text = text
.slice(0, dataPart.size)
.padEnd(dataPart.size);
}

if (dataPart.formatter != null) {
Expand Down Expand Up @@ -96,17 +93,3 @@ export function resizeDataLine(dataLine: DataLine, lineLength: number) {

return res;
}


function padEqually(text: string, size: number) {
const padAmount = Math.max(0, size - text.length);
for (let i = 0; i < padAmount; i++) {
if (i % 2 == 0) {
text = " " + text;
} else {
text = text + " ";
}
}

return text;
}

0 comments on commit d8d504d

Please sign in to comment.