File tree Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ import 'package:commander_ui/src/commander.dart' ;
2+ import 'package:commander_ui/src/level.dart' ;
3+
4+ Future <void > sleep (int value) => Future .delayed (Duration (seconds: value));
5+
6+ Future <void > main () async {
7+ final commander = Commander (level: Level .verbose);
8+ print ('Hello World !' );
9+
10+ final screen = commander.screen (title: 'First screen' );
11+
12+ screen.enter ();
13+ print ('Hello screen !' );
14+ screen.leave ();
15+
16+ print ('Goodbye screen !' );
17+ }
Original file line number Diff line number Diff line change 1+ import 'dart:io' ;
2+
3+ import 'package:commander_ui/src/domains/models/component.dart' ;
4+ import 'package:mansion/mansion.dart' ;
5+
6+ final class Screen implements Component <ScreenManager > {
7+ String ? _title;
8+
9+ Screen ({String ? title}) {
10+ _title = title;
11+ }
12+
13+ @override
14+ ScreenManager handle () => ScreenManager (this );
15+ }
16+
17+ final class ScreenManager {
18+ final Screen _screen;
19+
20+ ScreenManager (this ._screen);
21+
22+ void setTitle (String title) {
23+ _screen._title = title;
24+ stdout.writeAnsi (SetTitle (title));
25+ }
26+
27+ void enter () {
28+ stdout.writeAnsi (AlternateScreen .enter);
29+ if (_screen._title case String title) {
30+ stdout.writeAnsi (SetTitle (title));
31+ }
32+ }
33+
34+ void leave () {
35+ stdout.writeAnsi (AlternateScreen .leave);
36+ }
37+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import 'dart:io' as io;
33
44import 'package:commander_ui/src/application/components/ask.dart' ;
55import 'package:commander_ui/src/application/components/checkbox.dart' ;
6+ import 'package:commander_ui/src/application/components/screen.dart' ;
67import 'package:commander_ui/src/application/components/select.dart' ;
78import 'package:commander_ui/src/application/components/table.dart' ;
89import 'package:commander_ui/src/application/components/task.dart' ;
@@ -92,4 +93,6 @@ class Commander with TerminalTools {
9293 lineSeparator: lineSeparator,
9394 columnSeparator: columnSeparator)
9495 .handle ();
96+
97+ ScreenManager screen ({String ? title}) => Screen (title: title).handle ();
9598}
You can’t perform that action at this time.
0 commit comments