run method

Future<T?> run({
  1. bool? clear,
  2. bool? throwOnError,
  3. dynamic onError(
    1. Object
    )?,
  4. StyleFunction? prompt,
  5. StyleFunction? successHint,
  6. StyleFunction? failedHint,
  7. StyleFunction? successTag,
  8. StyleFunction? failedTag,
})

Runs the task with optional parameters for customization.

Implementation

Future<T?> run({
  bool? clear,
  bool? throwOnError,
  Function(Object)? onError,
  StyleFunction? prompt,
  StyleFunction? successHint,
  StyleFunction? failedHint,
  StyleFunction? successTag,
  StyleFunction? failedTag,
}) async {
  // Apply custom styles
  final sPrompt = _style(this.prompt, prompt);
  final sSuccessHint = _style(this.successHint?.cGray ?? '', successHint);
  final sFailedHint = _style(this.failedHint?.cGray ?? '', failedHint);
  final sSuccessTag = _style(this.successTag.dim(), successTag);
  final sFailedTag = _style(this.failedTag.dim(), failedTag);

  T? result;

  await task(
    sPrompt,
    successMessage: _buildSuccessMsg(sPrompt, sSuccessHint, sSuccessTag),
    failedMessage: _buildFailedMsg(sPrompt, sFailedHint, sFailedTag),
    clear: clear ?? this.clear,
    throwOnError: throwOnError ?? false,
    onError: onError,
    task: (state) async {
      result = await execute(state);
    },
  );

  return result;
}