提交 89999486 编写于 作者: P prife

recover the terminal's behaviour when runing exit in finsh

上级 b8aaa6e7
...@@ -67,6 +67,18 @@ _CRTIMP void __cdecl abort(void); ...@@ -67,6 +67,18 @@ _CRTIMP void __cdecl abort(void);
void rt_hw_exit(void) void rt_hw_exit(void)
{ {
rt_kprintf("RT-Thread, bye\n"); rt_kprintf("RT-Thread, bye\n");
#if !defined(_WIN32) && defined(__GNUC__)
/* *
* getchar reads key from buffer, while finsh need an non-buffer getchar
* in windows, getch is such an function, in linux, we had to change
* the behaviour of terminal to get an non-buffer getchar.
* in usart_sim.c, set_stty is called to do this work
* */
{
extern void restore_stty(void);
restore_stty();
}
#endif
exit(0); exit(0);
} }
FINSH_FUNCTION_EXPORT_ALIAS(rt_hw_exit, exit, exit rt - thread); FINSH_FUNCTION_EXPORT_ALIAS(rt_hw_exit, exit, exit rt - thread);
......
...@@ -129,19 +129,25 @@ static int savekey(unsigned char key) ...@@ -129,19 +129,25 @@ static int savekey(unsigned char key)
static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam) static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam)
#else #else
static struct termios oldt, newt;
/*simulate windows' getch(), it works!!*/ /*simulate windows' getch(), it works!!*/
static void setgetchar(void) void set_stty(void)
{ {
struct termios oldt, newt; /* get terminal input's attribute */
// get terminal input's attribute
tcgetattr(STDIN_FILENO, &oldt); tcgetattr(STDIN_FILENO, &oldt);
newt = oldt; newt = oldt;
//set termios' local mode /* set termios' local mode */
newt.c_lflag &= ~(ECHO|ICANON); newt.c_lflag &= ~(ECHO|ICANON);
tcsetattr(STDIN_FILENO, TCSANOW, &newt); tcsetattr(STDIN_FILENO, TCSANOW, &newt);
} }
void restore_stty(void)
{
/* recover terminal's attribute */
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
}
#define getch getchar #define getch getchar
static void * ThreadforKeyGet(void * lpParam) static void * ThreadforKeyGet(void * lpParam)
...@@ -154,7 +160,7 @@ static void * ThreadforKeyGet(void * lpParam) ...@@ -154,7 +160,7 @@ static void * ThreadforKeyGet(void * lpParam)
/* set the getchar without buffer */ /* set the getchar without buffer */
sigfillset(&sigmask); sigfillset(&sigmask);
pthread_sigmask(SIG_BLOCK, &sigmask, &oldmask); pthread_sigmask(SIG_BLOCK, &sigmask, &oldmask);
setgetchar(); set_stty();
#endif #endif
(void)lpParam; //prevent compiler warnings (void)lpParam; //prevent compiler warnings
for (;;) for (;;)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册