start method

  1. @override
Future<void> start(
  1. StartupProbeContext ctx
)
override

Starts the width probe by querying the terminal.

Implementation

@override
Future<void> start(StartupProbeContext ctx) async {
  if (_active) return;
  if (!ctx.terminal.supportsAnsi || !ctx.terminal.isTerminal) return;
  _active = true;

  final term = ctx.terminal;

  // Save cursor position and move to the last row so probing happens in an
  // area the user won't notice (the content is already rendered above).
  // We do NOT enter alt screen — the renderer has already done that.
  term.saveCursor();

  // Move to the bottom-left of the screen and clear that line so the probe
  // emoji doesn't visually collide with rendered content.
  final (width: _, height: h) = term.size;
  term.write('\x1b[$h;1H'); // Move to last row, col 1
  term.write(Ansi.clearLine);

  // Request cursor position to establish the baseline column.
  term.write(Ansi.requestExtendedCursorPosition);
  await term.flush();

  try {
    await _done.future.timeout(timeout);
  } on TimeoutException {
    // Best-effort: leave defaults.
  } finally {
    _active = false;
    // Erase probe artifacts on the last row and restore cursor.
    term.write('\x1b[$h;1H');
    term.write(Ansi.clearLine);
    term.restoreCursor();
    await term.flush();
  }
}