| 7 | } |
| 8 | |
| 9 | export class LoggerPadding implements FlowController { |
| 10 | private readonly logger: Logger; |
| 11 | |
| 12 | constructor({ logger }: { logger: Logger }) { |
| 13 | this.logger = logger; |
| 14 | } |
| 15 | |
| 16 | handle(commands: Command[]): { commands: Command[]; onFinish: () => void } { |
| 17 | // Sometimes there's limited concurrency, so not all commands will spawn straight away. |
| 18 | // Compute the prefix length now, which works for all styles but those with a PID. |
| 19 | let length = commands.reduce((length, command) => { |
| 20 | const content = this.logger.getPrefixContent(command); |
| 21 | return Math.max(length, visibleLength(content?.value)); |
| 22 | }, 0); |
| 23 | this.logger.setPrefixLength(length); |
| 24 | |
| 25 | // The length of prefixes is somewhat stable, except for PIDs, which might change when a |
| 26 | // process spawns (e.g. PIDs might look like 1, 10 or 100), therefore listen to command starts |
| 27 | // and update the prefix length when this happens. |
| 28 | const subs = commands.map((command) => |
| 29 | command.timer.subscribe((event) => { |
| 30 | if (!event.endDate) { |
| 31 | const content = this.logger.getPrefixContent(command); |
| 32 | length = Math.max(length, visibleLength(content?.value)); |
| 33 | this.logger.setPrefixLength(length); |
| 34 | } |
| 35 | }), |
| 36 | ); |
| 37 | |
| 38 | return { |
| 39 | commands, |
| 40 | onFinish() { |
| 41 | subs.forEach((sub) => sub.unsubscribe()); |
| 42 | }, |
| 43 | }; |
| 44 | } |
| 45 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…