shortHelpView method

String shortHelpView(
  1. List<KeyBinding> bindings
)

Renders a short help view from a list of key bindings.

Displays bindings in a single line, truncating with ellipsis if needed.

Implementation

String shortHelpView(List<KeyBinding> bindings) {
  if (bindings.isEmpty) return '';

  final buffer = StringBuffer();
  var totalWidth = 0;
  final separator = styles.renderSep(styles.shortSeparator);
  final sepWidth = Style.visibleLength(styles.shortSeparator);

  for (var i = 0; i < bindings.length; i++) {
    final binding = bindings[i];
    if (!binding.enabled) continue;

    // Add separator if not first item
    String sep = '';
    if (totalWidth > 0) {
      sep = separator;
    }

    // Build item
    final item =
        '${styles.renderKey(binding.help.key)} '
        '${styles.renderDesc(binding.help.desc)}';
    final itemWidth =
        Style.visibleLength(binding.help.key) +
        1 +
        Style.visibleLength(binding.help.desc);

    // Check if we need to truncate
    final addedWidth = (sep.isNotEmpty ? sepWidth : 0) + itemWidth;
    if (width > 0 && totalWidth + addedWidth > width) {
      // Add ellipsis if there's room
      final ellipsis = ' ${styles.renderSep(styles.ellipsis)}';
      if (totalWidth + Style.visibleLength(ellipsis) < width) {
        buffer.write(ellipsis);
      }
      break;
    }

    buffer.write(sep);
    buffer.write(item);
    totalWidth += addedWidth;
  }

  return buffer.toString();
}