Skip to content

Commit

Permalink
Fix: pad the last line of wrapped logs with spaces (#615)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm authored Aug 25, 2023
1 parent b7e4bc2 commit 3903204
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
19 changes: 15 additions & 4 deletions src/console/progressBarCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,22 @@ export default class ProgressBarCLI extends ProgressBar {
await ProgressBarCLI.RENDER_MUTEX.runExclusive(() => {
// Dequeue all log messages
if (ProgressBarCLI.multiBar && ProgressBarCLI.logQueue.length) {
const consoleWidth = ConsolePoly.consoleWidth();
const logMessage = ProgressBarCLI.logQueue
// https://github.com/npkgz/cli-progress/issues/142
.map((msg) => wrapAnsi(msg, ConsolePoly.consoleWidth()))
// If there are leading or trailing newlines, then blank the entire row to overwrite
.map((msg) => msg.replace(/^\n|\n$/g, () => `\n${' '.repeat(ConsolePoly.consoleWidth())}`))
// Wrapping is broken: https://github.com/npkgz/cli-progress/issues/142
.map((msg, msgIdx) => wrapAnsi(msg, consoleWidth)
// ...and if we manually wrap lines, we also need to deal with overwriting existing
// progress bar output.
.split('\n')
.map((line, lineIdx) => {
if (msgIdx === 0 && lineIdx === 0) {
// The very first line shouldn't need padding, the progress bar renderer should
// be calling `process.stdout.clearLine()`.
return line;
}
return line.padEnd(consoleWidth, ' ');
})
.join('\n'))
.join('\n');
ProgressBarCLI.multiBar.log(`${logMessage}\n`);
ProgressBarCLI.logQueue = [];
Expand Down
2 changes: 1 addition & 1 deletion src/modules/candidateGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export default class CandidateGenerator extends Module {
foundRomsWithFiles: ROMWithFiles[],
missingRoms: ROM[],
): void {
let message = `${dat.getNameShort()}: ${game.getName()}: found ${foundRomsWithFiles.length.toLocaleString()} file${missingRoms.length !== 1 ? 's' : ''}, missing ${missingRoms.length.toLocaleString()} file${missingRoms.length !== 1 ? 's' : ''}`;
let message = `${dat.getNameShort()}: ${game.getName()}: found ${foundRomsWithFiles.length.toLocaleString()} file${foundRomsWithFiles.length !== 1 ? 's' : ''}, missing ${missingRoms.length.toLocaleString()} file${missingRoms.length !== 1 ? 's' : ''}`;
if (release?.getRegion()) {
message += ` (${release?.getRegion()})`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/polyfill/consolePoly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import terminalSize from 'term-size';

export default class ConsolePoly {
static consoleWidth(): number {
return process.stdout.isTTY ? terminalSize().columns : Number.MAX_SAFE_INTEGER;
return process.stdout.isTTY ? terminalSize().columns : 65_536;
}
}

0 comments on commit 3903204

Please sign in to comment.