From c47500e8780023b036cfdfef5b866dc89ccede31 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 31 Aug 2024 00:56:39 -0700 Subject: [PATCH] Adjust pause binary --- dart/bin/pause.dart | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/dart/bin/pause.dart b/dart/bin/pause.dart index 0e9d7cd..0e7ee79 100644 --- a/dart/bin/pause.dart +++ b/dart/bin/pause.dart @@ -2,29 +2,37 @@ import 'dart:io'; import 'package:libac_dart/utils/IOTools.dart'; String getKeyPress() { - // Disable line mode to capture a single key press without requiring Enter - stdin.echoMode = false; - stdin.lineMode = false; + bool ret = false; + 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 - int byte = stdin.readByteSync(); + // Read a single byte from stdin + int byte = stdin.readByteSync(); - // Restore line mode and echo mode to default settings - stdin.echoMode = true; - stdin.lineMode = true; + // Restore line mode and echo mode to default settings + stdin.echoMode = true; + stdin.lineMode = true; - // Return the character representation of the byte - return String.fromCharCode(byte); + // Return the character representation of the byte + str = String.fromCharCode(byte); + + if (RegExp(r'^[A-Za-z]$').hasMatch(str)) ret = true; + } + + return str; } -int main() { - prnt("\rPress Any Key To Continue..."); +Future 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 - prnt("\r\n"); + await prnt("\r\n"); // Check if the pressed key is 'Z' if (key.toUpperCase() == 'Z') {