You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "eren-terzioglu (via GitHub)" <gi...@apache.org> on 2025/07/11 12:05:16 UTC

[PR] games/snake: Fix terminal issue after returning back from snake game [nuttx-apps]

eren-terzioglu opened a new pull request, #3126:
URL: https://github.com/apache/nuttx-apps/pull/3126

   ## Summary
   When snake game with `GAMES_SNAKE_USE_CONSOLEKEY` option enabled, nsh crashes after returning from the game. This PR fixes the issue
   
   - games/snake: Fix terminal issue after returning back from snake game
   Fix terminal issue after returning back from game
   
   ## Impact
   Snake game
   
   ## Testing
   
   `esp32-devkitc:snake` config with  `GAMES_SNAKE_USE_CONSOLEKEY` and `DEBUG_SNAKE_GAME` options enabled. You can recreate issue by pressing left arrow key at the end of the game. Expected issue is 'nsh' will act weird and echo option would not work.  


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] games/snake: Fix terminal issue after returning back from snake game [nuttx-apps]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #3126:
URL: https://github.com/apache/nuttx-apps/pull/3126#discussion_r2207582383


##########
games/snake/snake_input_console.h:
##########
@@ -63,6 +63,25 @@ void init_termios(int echo)
   fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);  /* set non-blocking mode */
 }
 
+/****************************************************************************
+ * Name: deinit_termios
+ *
+ * Description:
+ *   Restore back g_old terminal I/O settings.
+ *
+ * Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None.
+ *
+ ****************************************************************************/
+
+void deinit_termios(void)

Review Comment:
   yes, @eren-terzioglu could you merge into one



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] games/snake: Fix terminal issue after returning back from snake game [nuttx-apps]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #3126:
URL: https://github.com/apache/nuttx-apps/pull/3126#discussion_r2200558367


##########
games/snake/snake_input_console.h:
##########
@@ -63,6 +63,27 @@ void init_termios(int echo)
   fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);  /* set non-blocking mode */
 }
 
+/****************************************************************************
+ * Name: deinit_termios
+ *
+ * Description:
+ *   Restore back g_old terminal I/O settings.
+ *
+ * Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None.
+ *
+ ****************************************************************************/
+
+void deinit_termios(void)
+{
+  g_old.c_lflag |= ECHO;              /* enable ECHO bit */
+  tcsetattr(0, TCSANOW, &g_old);      /* restore old terminal i/o settings */
+  fcntl(STDIN_FILENO, F_SETFL, 0);    /* restore blocking mode */

Review Comment:
   don't need since the program will exit



##########
games/snake/snake_input_console.h:
##########
@@ -63,6 +63,27 @@ void init_termios(int echo)
   fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);  /* set non-blocking mode */
 }
 
+/****************************************************************************
+ * Name: deinit_termios
+ *
+ * Description:
+ *   Restore back g_old terminal I/O settings.
+ *
+ * Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None.
+ *
+ ****************************************************************************/
+
+void deinit_termios(void)
+{
+  g_old.c_lflag |= ECHO;              /* enable ECHO bit */

Review Comment:
   the previous setting may disable echo too, so it's better to restore g_old directly



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] games/snake: Fix terminal issue after returning back from snake game [nuttx-apps]

Posted by "eren-terzioglu (via GitHub)" <gi...@apache.org>.
eren-terzioglu commented on PR #3126:
URL: https://github.com/apache/nuttx-apps/pull/3126#issuecomment-3062177185

   Thanks @xiaoxiang781216, updated.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] games/snake: Fix terminal issue after returning back from snake game [nuttx-apps]

Posted by "eren-terzioglu (via GitHub)" <gi...@apache.org>.
eren-terzioglu commented on PR #3126:
URL: https://github.com/apache/nuttx-apps/pull/3126#issuecomment-3073953403

   Thanks @acassis @xiaoxiang781216, updated.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] games/snake: Fix terminal issue after returning back from snake game [nuttx-apps]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 merged PR #3126:
URL: https://github.com/apache/nuttx-apps/pull/3126


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] games/snake: Fix terminal issue after returning back from snake game [nuttx-apps]

Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis commented on code in PR #3126:
URL: https://github.com/apache/nuttx-apps/pull/3126#discussion_r2207322483


##########
games/snake/snake_input_console.h:
##########
@@ -63,6 +63,25 @@ void init_termios(int echo)
   fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);  /* set non-blocking mode */
 }
 
+/****************************************************************************
+ * Name: deinit_termios
+ *
+ * Description:
+ *   Restore back g_old terminal I/O settings.
+ *
+ * Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None.
+ *
+ ****************************************************************************/
+
+void deinit_termios(void)

Review Comment:
   Isn't it same as reset_termios() ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org