File tree Expand file tree Collapse file tree 6 files changed +74
-1
lines changed Expand file tree Collapse file tree 6 files changed +74
-1
lines changed Original file line number Diff line number Diff line change 1+ ## 1.7.0
2+
3+ - Implement ` alternative screen ` component
4+ - Add ` Table ` component in public export
5+
16## 1.6.0
27
38- Add ` Table ` component
Original file line number Diff line number Diff line change @@ -178,3 +178,26 @@ Future<void> main() async {
178178 );
179179}
180180` ` `
181+
182+ # ## Alternative screen component
183+ A simple example of using Commander to create an alternative screen component :
184+
185+ - ✅ Set title
186+ - ✅ Clear screen on start
187+ - ✅ Restore screen on stop
188+
189+ ` ` ` dart
190+ Future<void> main() async {
191+ final screen = AlternateScreen(title: 'Hello World !');
192+ screen.start();
193+
194+ print('Hello World !');
195+
196+ await wait();
197+ screen.stop();
198+ }
199+
200+
201+ Future<void> wait() =>
202+ Future.delayed(Duration(seconds: Random().nextInt(3) + 1));
203+ ` ` `
Original file line number Diff line number Diff line change 1+ import 'dart:math' ;
2+
3+ import 'package:commander_ui/src/components/alternate_screen.dart' ;
4+
5+ Future <void > main () async {
6+ final screen = AlternateScreen (title: 'Hello World !' );
7+ screen.start ();
8+
9+ print ('Hello World !' );
10+
11+ await wait ();
12+ screen.stop ();
13+ }
14+
15+ Future <void > wait () =>
16+ Future .delayed (Duration (seconds: Random ().nextInt (3 ) + 1 ));
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ export '../src/components/checkbox.dart';
1010export '../src/components/delayed.dart' ;
1111export '../src/components/progress.dart' ;
1212export '../src/components/switch.dart' ;
13+ export '../src/components/table.dart' ;
14+ export '../src/components/alternate_screen.dart' ;
1315
1416export '../src/key_down_event_listener.dart' ;
1517export '../src/result.dart' ;
Original file line number Diff line number Diff line change 1+ import 'dart:io' ;
2+
3+ import 'package:commander_ui/src/commons/cli.dart' ;
4+ import 'package:commander_ui/src/component.dart' ;
5+ import 'package:mansion/mansion.dart' as mansion;
6+
7+ class AlternateScreen with Tools implements Component <void > {
8+ String ? title;
9+
10+ AlternateScreen ({this .title});
11+
12+ void setTitle (String title) {
13+ this .title = title;
14+ stdout.writeAnsi (mansion.SetTitle (title));
15+ }
16+
17+ void start () {
18+ stdout.writeAnsi (mansion.AlternateScreen .enter);
19+ if (title case String title) {
20+ stdout.writeAnsi (mansion.SetTitle (title));
21+ }
22+ }
23+
24+ void stop () {
25+ stdout.writeAnsi (mansion.AlternateScreen .leave);
26+ }
27+ }
Original file line number Diff line number Diff line change 11name : commander_ui
22description : Commander is a Dart library for creating user interfaces within the terminal.
3- version : 1.6 .0
3+ version : 1.7 .0
44repository : https://github.com/LeadcodeDev/commander
55
66topics :
You can’t perform that action at this time.
0 commit comments