File tree Expand file tree Collapse file tree 5 files changed +37
-17
lines changed Expand file tree Collapse file tree 5 files changed +37
-17
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,6 @@ final class Ask<T> with TerminalTools implements Component<Future<T>> {
27
27
SetStyles (Style .foreground (Color .brightBlack)),
28
28
Print (' ($_defaultValue )' ),
29
29
SetStyles .reset,
30
- Print (' :' ),
31
30
];
32
31
}
33
32
@@ -112,13 +111,16 @@ final class Ask<T> with TerminalTools implements Component<Future<T>> {
112
111
SetStyles (Style .foreground (Color .brightRed)),
113
112
Print (error),
114
113
SetStyles .reset,
114
+ CursorPosition .restore,
115
+ Clear .afterCursor,
115
116
]);
116
117
117
- resetCursor ();
118
-
119
- buffer. writeAnsi (
118
+ buffer. writeAnsiAll ([
119
+ CursorPosition .restore,
120
+ Clear .afterCursor,
120
121
SetStyles (Style .foreground (Color .brightBlack)),
121
- );
122
+ ]);
123
+
122
124
stdout.write (buffer.toString ());
123
125
124
126
stdout.writeAnsiAll ([
@@ -147,16 +149,14 @@ final class Ask<T> with TerminalTools implements Component<Future<T>> {
147
149
Print (_hidden ? '******' : response),
148
150
SetStyles .reset,
149
151
AsciiControl .lineFeed,
152
+ CursorPosition .restore,
153
+ Clear .afterCursor,
150
154
]);
151
155
152
- resetCursor ();
153
156
stdout.write (buffer.toString ());
154
157
155
158
_completer.complete (response as T );
156
159
}
157
-
158
- void resetCursor () {
159
- restoreCursorPosition ();
160
- clearFromCursorToEnd ();
161
- }
162
160
}
161
+
162
+
Original file line number Diff line number Diff line change @@ -54,7 +54,13 @@ final class Checkbox<T>
54
54
_render (isInitialRender: true );
55
55
56
56
while (_keepAlive) {
57
- final key = readKey (_terminal);
57
+ final key = readKey (_terminal, onExit: () {
58
+ stdout.writeAnsiAll ([
59
+ CursorVisibility .show,
60
+ CursorPosition .restore,
61
+ Clear .afterCursor,
62
+ ]);
63
+ });
58
64
59
65
if (key.controlChar == ControlCharacter .arrowUp || key.char == 'k' ) {
60
66
if (_currentIndex != 0 ) {
Original file line number Diff line number Diff line change @@ -52,7 +52,13 @@ final class Select<T> with TerminalTools implements Component<Future<T>> {
52
52
_render (isInitialRender: true );
53
53
54
54
while (_selectedOption == null ) {
55
- final key = readKey (_terminal);
55
+ final key = readKey (_terminal, onExit: () {
56
+ stdout.writeAnsiAll ([
57
+ CursorVisibility .show,
58
+ CursorPosition .restore,
59
+ Clear .afterCursor,
60
+ ]);
61
+ });
56
62
57
63
if (key.controlChar == ControlCharacter .arrowUp || key.char == 'k' ) {
58
64
if (_currentIndex != 0 ) {
@@ -107,7 +113,7 @@ final class Select<T> with TerminalTools implements Component<Future<T>> {
107
113
SetStyles (Style .foreground (Color .yellow)),
108
114
Print ('?' ),
109
115
SetStyles .reset,
110
- Print (' $_message : ' ),
116
+ Print (' $_message ' ),
111
117
SetStyles (Style .foreground (Color .brightBlack)),
112
118
Print (_filter.isEmpty ? _placeholder : _filter),
113
119
SetStyles .reset,
Original file line number Diff line number Diff line change @@ -41,7 +41,13 @@ final class Swap<T> with TerminalTools implements Component<Future<bool>> {
41
41
_render (isInitialRender: true );
42
42
43
43
while (_keepAlive) {
44
- final key = readKey (_terminal);
44
+ final key = readKey (_terminal, onExit: () {
45
+ stdout.writeAnsiAll ([
46
+ CursorVisibility .show,
47
+ CursorPosition .restore,
48
+ Clear .afterCursor,
49
+ ]);
50
+ });
45
51
46
52
if (key.controlChar == ControlCharacter .arrowLeft) {
47
53
_value = true ;
Original file line number Diff line number Diff line change @@ -109,14 +109,16 @@ mixin TerminalTools {
109
109
if (! stdout.hasTerminal) throw NoTerminalAttachedError ();
110
110
}
111
111
112
- KeyStroke readKey (Terminal terminal) {
112
+ KeyStroke readKey (Terminal terminal, { Function () ? onExit} ) {
113
113
_ensureTerminalAttached ();
114
114
terminal.enableRawMode ();
115
115
final key = _readKey ();
116
+ print (key.controlChar);
116
117
terminal.disableRawMode ();
117
118
118
119
if (key.controlChar == ControlCharacter .ctrlC) {
119
- showCursor ();
120
+ stdout.writeAnsi (CursorVisibility .show);
121
+ onExit? .call ();
120
122
exit (130 );
121
123
}
122
124
return key;
You can’t perform that action at this time.
0 commit comments