prnt function

Future<void> prnt(
  1. String text
)

Implementation

Future<void> prnt(String text) async {
  // Convert the string to a list of runes to handle escape sequences properly.
  final runes = text.runes.toList();

  for (var i = 0; i < runes.length; i++) {
    final char = runes[i];

    // Check for escape sequences
    final charStr = String.fromCharCode(char);
    if (charStr == '\r') {
      // 'r' character in UTF-16
      // Handle '\r' escape sequence
      stdout.write('\r'); // Move the cursor back to the beginning of the line
      stdout.write(' '.padLeft(
          stdout.terminalColumns - 1)); // Erase the entire line with spaces
      stdout.write(
          '\r'); // Move the cursor back to the start of the line again after clearing
      continue;
    }

    // Write the character as-is
    stdout.write(String.fromCharCode(char));
  }

  await stdout.flush();
}