Skip to content

Commit 5ef1a69

Browse files
committed
docs(components): add docs
1 parent 08de983 commit 5ef1a69

File tree

9 files changed

+26
-13
lines changed

9 files changed

+26
-13
lines changed

lib/src/application/components/ask.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:commander_ui/src/application/utils/terminal_tools.dart';
66
import 'package:commander_ui/src/domains/models/component.dart';
77
import 'package:mansion/mansion.dart';
88

9+
/// A component that asks the user for input.
910
final class Ask with TerminalTools implements Component<Future<String?>> {
1011
final _completer = Completer<String?>();
1112

@@ -16,11 +17,12 @@ final class Ask with TerminalTools implements Component<Future<String?>> {
1617
late final bool _hidden;
1718
late final String? Function(String value)? _validate;
1819

19-
bool get hasDefault => _defaultValue != null && '$_defaultValue'.isNotEmpty;
20+
/// Creates a new instance of [Ask].
21+
bool get _hasDefault => _defaultValue != null && '$_defaultValue'.isNotEmpty;
2022

21-
String get resolvedDefaultValue => hasDefault ? '$_defaultValue' : '';
23+
String get _resolvedDefaultValue => _hasDefault ? '$_defaultValue' : '';
2224

23-
List<Sequence> get baseDefaultSequence {
25+
List<Sequence> get _baseDefaultSequence {
2426
return [
2527
SetStyles(Style.foreground(Color.brightBlack)),
2628
Print(' ($_defaultValue)'),
@@ -55,7 +57,7 @@ final class Ask with TerminalTools implements Component<Future<String?>> {
5557
void _waitResponse() {
5658
final input = _hidden ? readLineHiddenSync() : readLineSync();
5759
final response =
58-
input == null || input.isEmpty ? resolvedDefaultValue : input;
60+
input == null || input.isEmpty ? _resolvedDefaultValue : input;
5961

6062
if (_validate != null) {
6163
final result = _validate!(response);
@@ -81,7 +83,7 @@ final class Ask with TerminalTools implements Component<Future<String?>> {
8183
buffer.writeAnsiAll([
8284
...askSequence,
8385
Print(_message),
84-
if (hasDefault) ...baseDefaultSequence,
86+
if (_hasDefault) ..._baseDefaultSequence,
8587
const CursorPosition.moveRight(1),
8688
SetStyles(Style.foreground(Color.brightBlack)),
8789
]);
@@ -101,7 +103,7 @@ final class Ask with TerminalTools implements Component<Future<String?>> {
101103
buffer.writeAnsiAll([
102104
...errorSequence,
103105
Print(_message),
104-
if (hasDefault) ...baseDefaultSequence,
106+
if (_hasDefault) ..._baseDefaultSequence,
105107
const CursorPosition.moveRight(1),
106108
]);
107109

lib/src/application/components/checkbox.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:commander_ui/src/domains/models/component.dart';
77
import 'package:commander_ui/src/io.dart';
88
import 'package:mansion/mansion.dart';
99

10+
/// A component that asks the user to select one or more options.
1011
final class Checkbox<T>
1112
with TerminalTools
1213
implements Component<Future<List<T>>> {

lib/src/application/components/screen.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:io';
33
import 'package:commander_ui/src/domains/models/component.dart';
44
import 'package:mansion/mansion.dart';
55

6+
/// A component that represents an alternate screen.
67
final class Screen implements Component<ScreenManager> {
78
String? _title;
89

lib/src/application/components/select.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:commander_ui/src/domains/models/component.dart';
77
import 'package:commander_ui/src/io.dart';
88
import 'package:mansion/mansion.dart';
99

10+
/// A component that asks the user to select one option.
1011
final class Select<T> with TerminalTools implements Component<Future<T>> {
1112
final _completer = Completer<T>();
1213

lib/src/application/components/swap.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:commander_ui/src/domains/models/component.dart';
77
import 'package:commander_ui/src/io.dart';
88
import 'package:mansion/mansion.dart';
99

10+
/// A component that asks the user to swap between two options.
1011
final class Swap<T> with TerminalTools implements Component<Future<bool>> {
1112
final _completer = Completer<bool>();
1213

lib/src/application/components/table.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:commander_ui/src/application/utils/terminal_tools.dart';
55
import 'package:commander_ui/src/domains/models/component.dart';
66
import 'package:mansion/mansion.dart';
77

8+
/// A component that renders a table.
89
final class Table with TerminalTools implements Component<void> {
910
final List<List<String>> data;
1011
final List<String> columns;

lib/src/application/components/task.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ final List<String> _loadingSteps = [
1919
'⠏'
2020
];
2121

22+
/// A component that represents a task.
2223
final class Task with TerminalTools implements Component<Future<StepManager>> {
2324
final Terminal _terminal;
2425
final bool _colored;
@@ -31,6 +32,7 @@ final class Task with TerminalTools implements Component<Future<StepManager>> {
3132
}
3233
}
3334

35+
/// A manager that handles the steps of a task.
3436
final class StepManager with TerminalTools {
3537
final Terminal _terminal;
3638
(int, int)? _position;
@@ -41,6 +43,7 @@ final class StepManager with TerminalTools {
4143

4244
StepManager(this._terminal, this._colored);
4345

46+
/// Add new step to the task.
4447
Future<T> step<T>(String message, {FutureOr<T> Function()? callback}) {
4548
if (isInitialStep) {
4649
createSpace(_terminal, 1);
@@ -66,13 +69,14 @@ final class StepManager with TerminalTools {
6669
SetStyles.reset
6770
]);
6871

69-
task.render(buffer);
72+
task._render(buffer);
7073
});
7174
});
7275

73-
return task.start();
76+
return task._start();
7477
}
7578

79+
/// Finishes the task with a success message.
7680
void success(String message) {
7781
final buffer = StringBuffer();
7882

@@ -88,6 +92,7 @@ final class StepManager with TerminalTools {
8892
stdout.write(buffer.toString());
8993
}
9094

95+
/// Finishes the task with an error message.
9196
void warn(String message) {
9297
final buffer = StringBuffer();
9398

@@ -103,6 +108,7 @@ final class StepManager with TerminalTools {
103108
stdout.write(buffer.toString());
104109
}
105110

111+
/// Finishes the task with an error message.
106112
void error(String message) {
107113
final buffer = StringBuffer();
108114

@@ -132,6 +138,7 @@ final class StepManager with TerminalTools {
132138
}
133139
}
134140

141+
/// A task step.
135142
final class StepTask<T> {
136143
final _completer = Completer<T>();
137144

@@ -140,7 +147,7 @@ final class StepTask<T> {
140147

141148
StepTask(this._message, this._callback);
142149

143-
Future<T> start() async {
150+
Future<T> _start() async {
144151
if (_callback case Future<void> Function() callback) {
145152
callback().then((value) {
146153
_completer.complete(value as T);
@@ -152,7 +159,7 @@ final class StepTask<T> {
152159
return _completer.future;
153160
}
154161

155-
void render(StringBuffer buffer) {
162+
void _render(StringBuffer buffer) {
156163
buffer.writeAnsiAll([
157164
SetStyles(Style.foreground(Color.brightBlack)),
158165
Print(' $_message'),

lib/src/domains/models/component.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// The component contract.
12
abstract interface class Component<T> {
3+
/// Handles the component.
24
T handle();
35
}

lib/src/io.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
export 'package:io/io.dart' show ExitCode;
2-
31
/// Non-printable characters that can be entered from the keyboard.
4-
///
52
enum ControlCharacter {
63
/// null
74
none,

0 commit comments

Comments
 (0)