Rewrite pause.dart
This commit is contained in:
parent
d0494cb6a2
commit
5a7c676185
1 changed files with 12 additions and 37 deletions
|
@ -1,43 +1,18 @@
|
||||||
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:libac_dart/utils/IOTools.dart';
|
|
||||||
|
|
||||||
String getKeyPress() {
|
void main(List<String> arguments) {
|
||||||
bool ret = false;
|
stdout.write('Press any key to continue...');
|
||||||
String str = "";
|
|
||||||
while (!ret) {
|
|
||||||
// Disable line mode to capture a single key press without requiring Enter
|
|
||||||
//stdin.echoMode = false;
|
|
||||||
//stdin.lineMode = false;
|
|
||||||
|
|
||||||
// Read a single byte from stdin
|
while (true) {
|
||||||
int byte = stdin.readByteSync();
|
int charCode = stdin.readByteSync(); // Read a single byte
|
||||||
|
String char = String.fromCharCode(charCode).toLowerCase(); // Convert byte to character and lowercase it
|
||||||
|
|
||||||
// Restore line mode and echo mode to default settings
|
// Check if the input is "Enter" or between 'a' and 'z'
|
||||||
//stdin.echoMode = true;
|
if (charCode == 10 || (char.compareTo('a') >= 0 && char.compareTo('z') <= 0)) {
|
||||||
//stdin.lineMode = true;
|
break; // Exit loop if valid input is received
|
||||||
|
}
|
||||||
// Return the character representation of the byte
|
|
||||||
str = String.fromCharCode(byte);
|
|
||||||
|
|
||||||
if (RegExp(r'^[A-Za-z]$').hasMatch(str)) ret = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
print(''); // Print a newline for formatting
|
||||||
}
|
|
||||||
|
|
||||||
Future<int> main() async {
|
|
||||||
await prnt("\rPress Any Key To Continue...");
|
|
||||||
|
|
||||||
// Listen for a key press
|
|
||||||
String key = getKeyPress();
|
|
||||||
|
|
||||||
// Erase the line by printing a new line
|
|
||||||
await prnt("\r\n");
|
|
||||||
|
|
||||||
// Check if the pressed key is 'Z'
|
|
||||||
if (key.toUpperCase() == 'Z') {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue