MCPcopy Index your code
hub / github.com/open-cli-tools/concurrently / LoggerPadding

Class LoggerPadding

lib/flow-control/logger-padding.ts:9–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7}
8
9export 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…