All files / kernel-agents-repl/src/strategies/repl printer.ts

0% Statements 0/13
0% Branches 0/10
0% Functions 0/3
0% Lines 0/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36                                                                       
import type { Logger } from '@metamask/logger';
 
import { ResultMessage } from './messages.ts';
import type { ReplTranscript, StatementMessage } from './messages.ts';
 
export const makePrinter = ({
  history,
  logger,
}: {
  history: ReplTranscript;
  logger?: Logger;
}) => {
  // Render initial state
  for (const message of history) {
    if (message instanceof ResultMessage) {
      const lines = message
        .toReplString()
        .split('\n')
        .filter(
          (line) => line.trim() === line || line.startsWith('  "description"'),
        );
      if (lines && lines?.length > 0) {
        logger?.info(lines?.join('\n'));
      }
      continue;
    }
    logger?.info(message.toReplString());
  }
  return (statement: StatementMessage, result: ResultMessage | null) => {
    logger?.info(statement.toReplString());
    if (result) {
      logger?.info(result.toReplString());
    }
  };
};