@@ -77,17 +77,15 @@ public static void initialize() {
7777 saveOriginalTerminalSettings ();
7878
7979 // Register shutdown hook to restore terminal
80- Runtime .getRuntime ().addShutdownHook (new Thread (() -> {
81- restoreTerminalMode ();
82- }));
80+ Runtime .getRuntime ().addShutdownHook (new Thread (TermReadKey ::restoreTerminalMode ));
8381 }
8482
8583 /**
8684 * Sets the terminal input mode.
8785 * ReadMode(mode, [filehandle])
8886 */
8987 public static RuntimeList readMode (RuntimeArray args , int ctx ) {
90- if (args .size () == 0 ) {
88+ if (args .isEmpty () ) {
9189 return new RuntimeList (scalarUndef );
9290 }
9391
@@ -115,7 +113,7 @@ public static RuntimeList readMode(RuntimeArray args, int ctx) {
115113 public static RuntimeList readKey (RuntimeArray args , int ctx ) {
116114 int timeout = -1 ; // -1 means no timeout
117115
118- if (args .size () > 0 && args .get (0 ).getDefinedBoolean ()) {
116+ if (! args .isEmpty () && args .get (0 ).getDefinedBoolean ()) {
119117 timeout = args .get (0 ).getInt ();
120118 }
121119
@@ -140,7 +138,7 @@ public static RuntimeList readKey(RuntimeArray args, int ctx) {
140138 public static RuntimeList readLine (RuntimeArray args , int ctx ) {
141139 int timeout = -1 ;
142140
143- if (args .size () > 0 && args .get (0 ).getDefinedBoolean ()) {
141+ if (! args .isEmpty () && args .get (0 ).getDefinedBoolean ()) {
144142 timeout = args .get (0 ).getInt ();
145143 }
146144
@@ -325,7 +323,7 @@ private static char readSingleCharWindows(int timeoutSeconds) throws IOException
325323 // Simple timeout implementation - not perfect but functional
326324 long startTime = System .currentTimeMillis ();
327325 while (!reader .ready ()) {
328- if (System .currentTimeMillis () - startTime > timeoutSeconds * 1000 ) {
326+ if (System .currentTimeMillis () - startTime > timeoutSeconds * 1000L ) {
329327 return 0 ; // timeout
330328 }
331329 try {
@@ -347,7 +345,7 @@ private static char readSingleCharUnix(int timeoutSeconds) throws IOException {
347345 if (timeoutSeconds > 0 ) {
348346 long startTime = System .currentTimeMillis ();
349347 while (in .available () == 0 ) {
350- if (System .currentTimeMillis () - startTime > timeoutSeconds * 1000 ) {
348+ if (System .currentTimeMillis () - startTime > timeoutSeconds * 1000L ) {
351349 return 0 ; // timeout
352350 }
353351 try {
@@ -368,7 +366,7 @@ private static String readLineWithTimeout(int timeoutSeconds) throws IOException
368366 if (timeoutSeconds > 0 ) {
369367 long startTime = System .currentTimeMillis ();
370368 while (!reader .ready ()) {
371- if (System .currentTimeMillis () - startTime > timeoutSeconds * 1000 ) {
369+ if (System .currentTimeMillis () - startTime > timeoutSeconds * 1000L ) {
372370 return null ; // timeout
373371 }
374372 try {
0 commit comments