Created
January 26, 2023 05:29
-
-
Save ZackDeRose/b8d60c07a1fb8cbc00edda2f1eca72ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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