import { Transform } from "node:stream";
import chalk from "chalk";
export function createPrefixedTransform(options) {
    const maxLen = options.maxPrefixLength ?? 10;
    const paddedName = options.name.padEnd(maxLen);
    const prefix = options.color(paddedName) + chalk.gray(" | ");
    let buffer = "";
    return new Transform({
        transform(chunk, _encoding, callback) {
            const data = buffer + chunk.toString();
            const lines = data.split("\n");
            buffer = lines.pop() ?? "";
            for (const line of lines) {
                if (line.trim()) {
                    this.push(`${prefix}${line}\n`);
                }
            }
            callback();
        },
        flush(callback) {
            if (buffer.trim()) {
                this.push(`${prefix}${buffer}\n`);
            }
            callback();
        },
    });
}
//# sourceMappingURL=prefixed-output.js.map