11import 'dart:async' ;
2- import 'dart:io' as io ;
2+ import 'dart:io' ;
33
44import 'package:commander_ui/src/application/components/ask.dart' ;
55import 'package:commander_ui/src/application/components/checkbox.dart' ;
@@ -10,33 +10,54 @@ import 'package:commander_ui/src/application/components/task.dart';
1010import 'package:commander_ui/src/application/components/swap.dart' ;
1111import 'package:commander_ui/src/application/terminals/terminal.dart' ;
1212import 'package:commander_ui/src/application/utils/terminal_tools.dart' ;
13+ import 'package:commander_ui/src/domains/models/commander_theme.dart' ;
1314import 'package:commander_ui/src/level.dart' ;
1415
1516/// Type definition for a function which accepts a log message
1617/// and returns a styled version of that message.
1718///
1819/// Generally, [AnsiCode] values are used to generate a [LogStyle] .
1920///
20- /// ```dart
21- /// final alertStyle = (m) => backgroundRed.wrap(styleBold.wrap(white.wrap(m)));
22- /// ```
23- typedef LogStyle = String ? Function (String ? message);
24-
2521/// A basic Logger which wraps `stdio` and applies various styles.
2622class Commander with TerminalTools {
27- Commander ({
28- this .level = Level .info,
29- });
23+ late final CommanderTheme _theme;
3024
31- /// The current log level for this logger.
3225 Level level;
3326
3427 final _queue = < String ? > [];
3528
3629 final _terminal = Terminal ();
3730
31+ Commander ({
32+ this .level = Level .info,
33+ CommanderTheme ? theme,
34+ }) {
35+ _theme = theme ?? CommanderTheme .initial ();
36+ }
37+
38+ /// Write message via `stdout.write` .
39+ void write (String ? message) => stdout.write (message);
40+
3841 /// Write message via `stdout.write` .
39- void write (String ? message) => io.stdout.write (message);
42+ void writeln (String ? message) => stdout.writeln (message);
43+
44+ /// Write info message to stdout.
45+ void info (String ? message, {StdoutStyle ? style}) => writeln ((style ?? _theme.info)(message));
46+
47+ /// Write success message to stdout.
48+ void success (String ? message, {StdoutStyle ? style}) => writeln ((style ?? _theme.success)(message));
49+
50+ /// Write warning message to stdout.
51+ void warn (String ? message, {StdoutStyle ? style}) => writeln ((style ?? _theme.warn)(message));
52+
53+ /// Write error message to stdout.
54+ void error (String ? message, {StdoutStyle ? style}) => writeln ((style ?? _theme.error)(message));
55+
56+ /// Write alert message to stdout.
57+ void alert (String ? message, {StdoutStyle ? style}) => writeln ((style ?? _theme.alert)(message));
58+
59+ /// Write debug message to stdout.
60+ void debug (String ? message, {StdoutStyle ? style}) => writeln ((style ?? _theme.debug)(message));
4061
4162 /// Writes delayed message to stdout.
4263 void delayed (String ? message) => _queue.add (message);
0 commit comments