renderCompletionResult method

void renderCompletionResult(
  1. CompletionResult completionResult
)
inherited

Renders a CompletionResult into the current system shell.

This is called after a completion request (sent by a shell function) is parsed and the output is ready to be displayed.

Override this to intercept and customize the general output of the completions.

Implementation

void renderCompletionResult(CompletionResult completionResult) {
  final systemShell = this.systemShell;
  if (systemShell == null) {
    return;
  }

  for (final entry in completionResult.completions.entries) {
    switch (systemShell) {
      case SystemShell.zsh:
        // On zsh, colon acts as delimitation between a suggestion and its
        // description. Any literal colon should be escaped.
        final suggestion = entry.key.replaceAll(':', r'\:');
        final description = entry.value?.replaceAll(':', r'\:');

        completionLogger.info(
          '$suggestion${description != null ? ':$description' : ''}',
        );
      case SystemShell.bash:
        completionLogger.info(entry.key);
    }
  }
}