Handle -1 in pause
This commit is contained in:
parent
5a7c676185
commit
c4d167b978
1 changed files with 31 additions and 7 deletions
|
@ -1,18 +1,42 @@
|
||||||
|
|
||||||
import 'dart:io';
|
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) {}
|
||||||
|
}
|
||||||
|
|
||||||
void main(List<String> arguments) {
|
void main(List<String> arguments) {
|
||||||
stdout.write('Press any key to continue...');
|
prnt('\rPress any key to continue...');
|
||||||
|
|
||||||
|
echoMode(false);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int charCode = stdin.readByteSync(); // Read a single byte
|
int charCode = stdin.readByteSync(); // Read a single byte
|
||||||
String char = String.fromCharCode(charCode).toLowerCase(); // Convert byte to character and lowercase it
|
|
||||||
|
|
||||||
// Check if the input is "Enter" or between 'a' and 'z'
|
// Ignore -1 (EOF or invalid input)
|
||||||
if (charCode == 10 || (char.compareTo('a') >= 0 && char.compareTo('z') <= 0)) {
|
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
|
break; // Exit loop if valid input is received
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print(''); // Print a newline for formatting
|
echoMode(true);
|
||||||
|
|
||||||
|
prnt('\r\n'); // Print a newline for formatting
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue