Console class Core

The main I/O helper for Artisanal-style console output.

Console provides a high-level API for building polished CLI tools. It handles verbosity levels, ANSI styling, and interactive components.

The Console class is the primary entry point for high-level CLI output. It supports:

  • Writing styled text with verbosity awareness.
  • Rendering DisplayComponents (tables, lists, panels).
  • Interactive prompts (confirm, select, input).
  • Task tracking with spinners and progress bars. Verbosity levels allow users to control the amount of output produced by your CLI.
  • quiet: Only essential output.
  • normal: Standard output (default).
  • verbose: Detailed information for debugging.
  • debug: Maximum detail, including internal state.

Features

Usage

final console = Console();
console.title('My CLI Tool');

if (console.confirm('Do you want to continue?')) {
  console.task('Processing...', () async {
    await Future.delayed(Duration(seconds: 1));
    return TaskResult.success;
  });
}

Constructors

Console({WriteLine? out, WriteLine? err, WriteRaw? outRaw, WriteRaw? errRaw, ReadLine? readLine, SecretReader? secretReader, Stdin? stdin, Stdout? stdout, bool interactive = true, Verbosity verbosity = Verbosity.normal, int? terminalWidth, Renderer? renderer})
Creates a new I/O helper.

Properties

components Components
Access to higher-level console components (Laravel-style).
no setter
hashCode int
The hash code for this object.
no setterinherited
interactive bool
Whether interactive prompts are enabled.
final
promptTerminal StdioTerminal
Terminal instance used for inline prompts and animations.
no setter
quiet bool
Whether output is suppressed (quiet mode).
no setter
renderConfig RenderConfig
Rendering configuration for bubble-style display components.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
style Style
The ANSI style configuration.
no setter
styleNames Iterable<String>
Returns all registered style names.
no setter
terminalWidth int
The terminal width for formatting.
final
verbosity Verbosity
The current verbosity level.
final

Methods

alert(Object message, {Verbosity? verbosity}) → void
Outputs an alert box.
ask(String question, {String? defaultValue, String? validator(String value)?, int attempts = 3}) String
Prompts for text input.
caution(Object message, {Verbosity? verbosity}) → void
Outputs a caution message.
choice(String question, {required List<String> choices, int? defaultIndex, bool multiSelect = false}) Object
Prompts for a choice from a list (basic numbered selection).
comment(Object message, {Verbosity? verbosity}) → void
Outputs a comment message (Laravel-style).
confirm(String question, {bool defaultValue = true}) bool
Prompts for a yes/no confirmation.
countdown(String message, {required int seconds, FutureOr<void> onComplete()?}) Future<bool>
Displays a countdown timer.
debug(Object message, {Verbosity? verbosity}) → void
Outputs a debug message (only if verbosity >= debug).
dispose() → void
Disposes of console resources, including any active terminal.
error(Object message, {Verbosity? verbosity}) → void
Outputs an error message (Laravel-style).
getStyle(String name) Style?
Gets a registered style by name, or null if not found.
info(Object message, {Verbosity? verbosity}) → void
Outputs an info message (Laravel-style).
line(Object message, {String? style, Verbosity? verbosity}) → void
Outputs a plain line (Laravel-style).
listing(Iterable<Object> items) → void
Outputs a bulleted list.
Displays an ASCII art logo.
Displays a persistent menu and returns the selected choice.
multiSelectChoice<T>(String question, {required List<T> choices, List<int> defaultSelected = const [], String display(T)?}) Future<List<T>>
Interactive multi-select with arrow-key navigation.
newLine([int count = 1]) → void
Outputs one or more blank lines.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
note(Object message, {Verbosity? verbosity}) → void
Outputs a note message.
progress<T>(String message, {required FutureOr<T> run(void setProgress(double)), bool clearOnDone = false, String? doneMessage}) Future<T>
Runs an async task with a progress callback.
progressIterate<T>(Iterable<T> iterable, {int? max, bool clearOnDone = false}) Iterable<T>
Iterates over items while showing a progress bar.
question(Object message, {Verbosity? verbosity}) → void
Outputs a question message (Laravel-style).
registerStyle(String name, Style style) → void
Registers a custom named style for console tags.
Interactive search/filter prompt with fuzzy matching.
secret(String question, {String? fallback}) Future<String>
Prompts for secret/password input (no echo).
section(String message) → void
Outputs a section header with underline.
selectChoice<T>(String question, {required List<T> choices, int? defaultIndex, String display(T)?}) Future<T?>
Interactive single-select with arrow-key navigation.
spin<T>(String message, {required FutureOr<T> run(), Spinner spinner = Spinners.miniDot, bool clearOnDone = false, String? doneMessage}) Future<T>
Runs an async task while displaying an animated spinner.
steps({String? title, required List<(String, FutureOr<void> Function())> steps, bool continueOnError = false}) Future<StepsResult>
Displays a multi-step workflow with sequential steps.
success(Object message, {Verbosity? verbosity}) → void
Outputs a success message (Laravel-style extension).
table({required List<String> headers, required List<List<Object?>> rows}) → void
Outputs a formatted table.
task(String description, {FutureOr<TaskResult> run()?, bool clearOnDone = false}) Future<TaskResult>
Displays a task with status indicator (DONE/FAIL/SKIPPED).
taskGroup({String? title, required List<(String, FutureOr<void> Function())> tasks, bool showProgress = true, bool continueOnError = false, Spinner spinner = Spinners.miniDot}) Future<TaskGroupResult>
Runs a group of tasks with an overall progress indicator.
text(Object message) → void
Outputs indented text.
title(String message) → void
Outputs a title with underline.
toString() String
A string representation of this object.
inherited
tree(Map<String, dynamic> data, {String? root, TreeStyle style = TreeStyle.normal}) → void
Displays a tree structure.
twoColumnDetail(String first, [String? second]) → void
Outputs a two-column detail line.
unregisterStyle(String name) → void
Removes a registered custom style.
verbose(Object message, {Verbosity? verbosity}) → void
Outputs a verbose message (only if verbosity >= verbose).
warn(Object message, {Verbosity? verbosity}) → void
Outputs a warning message (Laravel-style).
write(String text) → void
Writes raw text to stdout (no newline).
writeErr(String text) → void
Writes raw text to stderr.
writeln([String line = '']) → void
Writes a line to stdout.
writelnErr([String line = '']) → void
Writes a line to stderr.

Operators

operator ==(Object other) bool
The equality operator.
inherited