write static method

void write(
  1. String message, {
  2. ConsoleColor? color,
  3. bool bold = false,
  4. bool newLine = true,
})

Flexible write method with optional color, style, and newline control.

message - The text to write to the console. color - Optional ConsoleColor for the text. bold - Whether to make the text bold (default: false). newLine - Whether to append a newline (default: true).

Example:

MetroConsole.write('Processing...', color: ConsoleColor.cyan, bold: true, newLine: false);
MetroConsole.write(' Done!', color: ConsoleColor.green);

Implementation

static void write(
  String message, {
  ConsoleColor? color,
  bool bold = false,
  bool newLine = true,
}) {
  final buffer = StringBuffer();

  // Apply bold if requested
  if (bold) {
    buffer.write(_bold);
  }

  // Apply color if provided
  if (color != null) {
    buffer.write(color.ansiSetForegroundColorSequence);
  }

  // Write the message
  buffer.write(message);

  // Reset styling
  if (bold || color != null) {
    buffer.write(_reset);
  }

  // Output with or without newline
  if (newLine) {
    stdout.writeln(buffer.toString());
  } else {
    stdout.write(buffer.toString());
  }
}