42 lines
1,012 B
Dart
42 lines
1,012 B
Dart
import 'dart:io';
|
|
|
|
import 'package:libac_dart/utils/IOTools.dart';
|
|
|
|
void echoMode(bool val) {
|
|
try {
|
|
stdin.echoMode = val;
|
|
stdin.lineMode = val;
|
|
} catch (E) {}
|
|
|
|
try {
|
|
stdin.echoNewlineMode = val;
|
|
} catch (E) {}
|
|
}
|
|
|
|
Future<void> main(List<String> arguments) async {
|
|
await prnt('\rPress any key to continue...');
|
|
|
|
echoMode(false);
|
|
|
|
while (true) {
|
|
int charCode = stdin.readByteSync(); // Read a single byte
|
|
|
|
// Ignore -1 (EOF or invalid input)
|
|
if (charCode == -1) {
|
|
continue;
|
|
}
|
|
|
|
// Check if the input is "Enter" (ASCII 10 or 13) or a valid letter from 'a' to 'z' (ASCII 97-122 or 65-90)
|
|
if (charCode == 10 ||
|
|
charCode == 13 || // Enter key (line feed or carriage return)
|
|
(charCode >= 65 && charCode <= 90) || // Uppercase 'A'-'Z'
|
|
(charCode >= 97 && charCode <= 122)) {
|
|
// Lowercase 'a'-'z'
|
|
break; // Exit loop if valid input is received
|
|
}
|
|
}
|
|
|
|
echoMode(true);
|
|
|
|
await prnt('\r\n'); // Print a newline for formatting
|
|
}
|