processPrompt method

  1. @override
Future processPrompt(
  1. String line
)
override

Process a command line as if entered interactively.

This is the primary entry point that routes to all other functionality. Supports all REPL commands and maintains multiline state.

Multiline Support: Multiline mode is tracked in the CLI state. When .start-* is called, subsequent processPrompt() calls accumulate in the multiline buffer until .end is called.

Returns the result of the command, or null for commands with no output. Throws CliException for errors.

Example:

cli.processPrompt('classes');           // Single command
cli.processPrompt('.start-script');     // Enter multiline mode
cli.processPrompt('var x = 1;');        // Accumulates
cli.processPrompt('.end');              // Executes multiline block

Implementation

@override
Future<dynamic> processPrompt(String line) async {
  final trimmed = line.trim();

  // Handle empty lines
  if (trimmed.isEmpty) {
    return null;
  }

  // Handle comments
  if (trimmed.startsWith('#')) {
    return null;
  }

  // Handle multiline mode
  if (_state.isMultilineMode) {
    return _handleMultilineInput(line, trimmed);
  }

  // Handle multiline mode transitions
  if (trimmed == '.start-define') {
    startDefine();
    return null;
  }
  if (trimmed == '.start-script') {
    startScript();
    return null;
  }
  if (trimmed == '.start-file') {
    startFile();
    return null;
  }
  if (trimmed == '.start-execute') {
    startExecute();
    return null;
  }

  // Handle standard commands
  return _handleCommand(trimmed);
}