dvReadGraphicsReply function

DVTerminalGraphics? dvReadGraphicsReply(
  1. String reply, {
  2. int id = dvGraphicsQueryId,
})

What a terminal's answer to dvKittyGraphicsQuery means, or null while the answer is still arriving.

Null is the state that matters. Terminal replies arrive in whatever pieces the pty hands over, and treating a partial one as "no acknowledgement" would report every Kitty terminal as an ANSI one — the graphics reply is always mid-flight before the device attributes land.

Anything other than OK from a matching query is read as no support. A terminal that parsed the escape and declined it will not draw the pixels either, and sending them anyway paints the escape sequence across the screen as literal text, which is worse than drawing coarser cells.

Implementation

DVTerminalGraphics? dvReadGraphicsReply(
  String reply, {
  int id = dvGraphicsQueryId,
}) {
  for (final RegExpMatch match in _apcGraphics.allMatches(reply)) {
    final String body = match.group(1) ?? '';
    final int separator = body.indexOf(';');
    if (separator < 0) continue;
    final List<String> keys = body.substring(0, separator).split(',');
    // A reply for another identifier belongs to an earlier query or to another
    // program sharing this terminal. Believing it would report pixel graphics
    // on a terminal that never answered.
    if (!keys.contains('i=$id')) continue;
    return body.substring(separator + 1).trim() == 'OK'
        ? DVTerminalGraphics.kitty
        : DVTerminalGraphics.ansi;
  }
  if (_deviceAttributes.hasMatch(reply)) return DVTerminalGraphics.ansi;
  return null;
}