ghosttyTerminalPrintableText function

String ghosttyTerminalPrintableText(
  1. KeyEvent event, {
  2. required GhosttyTerminalModifierState modifiers,
})

Resolves printable terminal text for a Flutter key event.

This prefers the platform-provided character, but falls back to logical-key-based punctuation inference when the event omitted character metadata for shifted symbol keys.

Implementation

String ghosttyTerminalPrintableText(
  KeyEvent event, {
  required GhosttyTerminalModifierState modifiers,
}) {
  final character = event.character ?? '';

  if (modifiers.blocksPrintableText) {
    return '';
  }

  if (modifiers.shiftPressed) {
    final shifted =
        _shiftedPhysicalPrintableFallbacks[event.physicalKey] ??
        _shiftedPrintableFallbacks[event.logicalKey];
    if (shifted != null) {
      return shifted;
    }
  }
  if (character.isNotEmpty) {
    return character;
  }
  final fallback =
      _printablePhysicalFallbacks[event.physicalKey] ??
      _printableFallbacks[event.logicalKey];
  if (fallback != null) {
    return fallback;
  }
  if (modifiers.shiftPressed) {
    final shifted =
        _shiftedPhysicalPrintableFallbacks[event.physicalKey] ??
        _shiftedPrintableFallbacks[event.logicalKey];
    if (shifted != null) {
      return shifted;
    }
  }
  final keyLabel = event.logicalKey.keyLabel;
  if (keyLabel.runes.length == 1 &&
      !ghosttyTerminalLogicalKeyMap.containsKey(event.logicalKey)) {
    return keyLabel;
  }
  return '';
}