Skip to content

Instantly share code, notes, and snippets.

@ZackDeRose
Created January 26, 2023 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZackDeRose/b8d60c07a1fb8cbc00edda2f1eca72ce to your computer and use it in GitHub Desktop.
Save ZackDeRose/b8d60c07a1fb8cbc00edda2f1eca72ce to your computer and use it in GitHub Desktop.
function prefixTerminalOutput(cp: ChildProcess, prefix: string) {
function logWithPrefix(data: string) {
if (!data) {
return;
}
console.log(
data
.split('\n')
.map((line) => `${prefix} ${line}`)
.join('\n')
);
}
cp.stdout.on('data', logWithPrefix);
cp.stdout.on('error', logWithPrefix);
cp.stderr.on('data', logWithPrefix);
cp.stderr.on('error', logWithPrefix);
}
function padTargetName(name: string, targetSize: number) {
const builder = [`${name}`];
builder.push(' '.repeat(Math.floor((targetSize - name.length) / 2)));
builder.unshift(' '.repeat(Math.ceil((targetSize - name.length) / 2)));
builder.push(' ');
return builder.join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment