Logger class final
A logger for command-line tools, shaped like mason_logger's Logger.
info, detail and success write to stdout; warn, err and
alert write to stderr. Prompts use dart_tui's prompt helpers
(promptInput, promptConfirm, promptSelect, promptMultiSelect): a
TUI on a terminal, and plain line questions in pipes, CI and with
ACCESSIBLE=1 (see withPlainMode). Colours follow
detectColorProfile, so NO_COLOR and pipes turn them off.
Unlike mason_logger, prompts return a Future. Each one has a blocking
twin (promptSync, promptAnySync, confirmSync, chooseOneSync,
chooseAnySync) for code that is already synchronous.
Sync prompts work in any isolate, but their stdin guard only checks the calling isolate. Do not let another isolate read stdin or change terminal mode at the same time (see promptSelectSync).
Cancelling a prompt (Esc or Ctrl+C in the TUI) exits the process with
code 130, as mason_logger does on Ctrl+C. When input ends in plain
mode, the prompt returns its default instead.
stdout, stderr, stdin and environment replace the real ones, for
tests. A custom stdin is listened to once per prompt, so pass a
broadcast stream to answer several prompts. exit replaces dart:io's
exit for the cancel case.
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- level ↔ Level
-
The lowest level that is written.
getter/setter pair
- progressOptions ↔ ProgressOptions
-
The options progress uses when it gets none.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
alert(
String? message, {String? style(String? message)?}) → void -
Writes
messageto stderr in bold white on red. -
chooseAny<
T extends Object?> (String? message, {required List< T> choices, List<T> ? defaultValues, String display(T choice)?}) → Future<List< T> > -
Asks for any number of
choices, shown withdisplay. The ones indefaultValuesstart checked. -
chooseAnySync<
T extends Object?> (String? message, {required List< T> choices, List<T> ? defaultValues, String display(T choice)?}) → List<T> - Like chooseAny, but blocks and returns the answer.
-
chooseOne<
T extends Object?> (String? message, {required List< T> choices, T? defaultValue, String display(T choice)?}) → Future<T> -
Asks for one of
choices, shown withdisplay(defaulttoString). The cursor starts ondefaultValue, or the first choice. -
chooseOneSync<
T extends Object?> (String? message, {required List< T> choices, T? defaultValue, String display(T choice)?}) → T - Like chooseOne, but blocks and returns the answer.
-
confirm(
String? message, {bool defaultValue = false}) → Future< bool> -
Asks a yes / no question. Enter returns
defaultValue. -
confirmSync(
String? message, {bool defaultValue = false}) → bool - Like confirm, but blocks and returns the answer.
-
delayed(
String? message) → void -
Keeps
messageuntil flush. -
detail(
String? message, {String? style(String? message)?}) → void -
Writes
messageto stdout in dark grey, at Level.debug. -
err(
String? message, {String? style(String? message)?}) → void -
Writes
messageto stderr in red. -
flush(
[void print(String?)?]) → void -
Writes the delayed messages with
print(default info). -
info(
String? message, {String? style(String? message)?}) → void -
Writes
messageto stdout. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
progress(
String message, {ProgressOptions? options}) → Progress -
Starts a spinner line with
message; end it with Progress.complete, Progress.fail or Progress.cancel. -
prompt(
String? message, {Object? defaultValue, }) → Future< String> -
Asks for a line of text. Empty input returns
defaultValue(or an empty string). Withhidden, the answer is not shown. -
promptAny(
String? message, {String separator = ','}) → Future< List< String> > -
Asks for a line of text and splits it on
separator. Items are trimmed, and empty ones dropped. -
promptAnySync(
String? message, {String separator = ','}) → List< String> - Like promptAny, but blocks and returns the answer.
-
promptSync(
String? message, {Object? defaultValue, }) → String -
Like prompt, but blocks and returns the answer, as mason_logger's
promptdoes. For code that is already synchronous; see promptInputSync for what sync prompts can't do. -
success(
String? message, {String? style(String? message)?}) → void -
Writes
messageto stdout in green. -
tasks(
List< Task> tasks, {int concurrency = 1, bool exitOnError = true}) → Future<void> -
Runs
tasksas a live list: a spinner line per task, the last line of each running task's output under it, and logs above it. Nested steps come from TaskContext.tasks. At the end it prints one summary line. -
toString(
) → String -
A string representation of this object.
inherited
-
warn(
String? message, {String tag = 'WARN', String? style(String? message)?}) → void -
Writes
[tag] messageto stderr in bold yellow. An emptytagwrites the message alone. -
write(
String? message) → void -
Writes
messageto stdout as it is, with no newline.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited