Fix logging to wrap text to width of console instead of breaking on words
ernieturner opened this issue · 1 comments
ernieturner commented
When we log long words to stdout or stderr they can end up getting wrapped at non-ideal locations in the middle of words. This is a bigger issue for when we log text in the login process which dumps out quite a bit of text.
The oclif/help-plugin
uses the wrap-ansi
plugin along with the following code to wrap at the window width
function termwidth(stream: any): number {
if (!stream.isTTY) {
return 80;
}
const width = stream.getWindowSize()[0];
if (width < 1) {
return 80;
}
if (width < 40) {
return 40;
}
return width;
}
const columns: number | null = parseInt(process.env.COLUMNS!, 10) || (global as any).columns;
console.log(columns || termwidth(process.stdout));
console.log(columns || termwidth(process.stderr));
ernieturner commented
Closing this as it hasn't come up as an issue anytime recently and is low priority