diff --git a/dart/bin/pause.dart b/dart/bin/pause.dart index 134a14e..253646a 100644 --- a/dart/bin/pause.dart +++ b/dart/bin/pause.dart @@ -1,18 +1,42 @@ - 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 arguments) { - stdout.write('Press any key to continue...'); + prnt('\rPress any key to continue...'); + + echoMode(false); while (true) { 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' - if (charCode == 10 || (char.compareTo('a') >= 0 && char.compareTo('z') <= 0)) { + // 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 } } - print(''); // Print a newline for formatting -} \ No newline at end of file + echoMode(true); + + prnt('\r\n'); // Print a newline for formatting +}