1
1
import 'dart:async' ;
2
- import 'dart:io' as io ;
2
+ import 'dart:io' ;
3
3
4
4
import 'package:commander_ui/src/application/components/ask.dart' ;
5
5
import 'package:commander_ui/src/application/components/checkbox.dart' ;
@@ -10,33 +10,54 @@ import 'package:commander_ui/src/application/components/task.dart';
10
10
import 'package:commander_ui/src/application/components/swap.dart' ;
11
11
import 'package:commander_ui/src/application/terminals/terminal.dart' ;
12
12
import 'package:commander_ui/src/application/utils/terminal_tools.dart' ;
13
+ import 'package:commander_ui/src/domains/models/commander_theme.dart' ;
13
14
import 'package:commander_ui/src/level.dart' ;
14
15
15
16
/// Type definition for a function which accepts a log message
16
17
/// and returns a styled version of that message.
17
18
///
18
19
/// Generally, [AnsiCode] values are used to generate a [LogStyle] .
19
20
///
20
- /// ```dart
21
- /// final alertStyle = (m) => backgroundRed.wrap(styleBold.wrap(white.wrap(m)));
22
- /// ```
23
- typedef LogStyle = String ? Function (String ? message);
24
-
25
21
/// A basic Logger which wraps `stdio` and applies various styles.
26
22
class Commander with TerminalTools {
27
- Commander ({
28
- this .level = Level .info,
29
- });
23
+ late final CommanderTheme _theme;
30
24
31
- /// The current log level for this logger.
32
25
Level level;
33
26
34
27
final _queue = < String ? > [];
35
28
36
29
final _terminal = Terminal ();
37
30
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
+
38
41
/// 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));
40
61
41
62
/// Writes delayed message to stdout.
42
63
void delayed (String ? message) => _queue.add (message);
0 commit comments