From 4a94af55a106bd84bd72be6700f813411eb7dd48 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Tue, 21 Sep 2010 18:26:46 +1000 Subject: win32: lineedit: fallback to fgets if a tty is not found --- libbb/lineedit.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'libbb') diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 3af9f4e64..1b88a7141 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -1914,10 +1914,13 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li INIT_S(); -#if !ENABLE_PLATFORM_MINGW32 +#if ENABLE_PLATFORM_MINGW32 + if (!isatty(0) || !isatty(1)) { +#else if (tcgetattr(STDIN_FILENO, &initial_settings) < 0 || !(initial_settings.c_lflag & ECHO) ) { +#endif /* Happens when e.g. stty -echo was run before */ parse_and_put_prompt(prompt); /* fflush_all(); - done by parse_and_put_prompt */ @@ -1928,7 +1931,6 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li DEINIT_S(); return len; } -#endif init_unicode(); -- cgit v1.2.3-55-g6feb From 1245a2ba817045d0a33baa5c86b69e54596b9199 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Wed, 22 Sep 2010 09:23:57 +1000 Subject: win32: lineedit: initialize initial_settings initial_settings.c_cc[] is used to detect Ctrl-C, Ctrl-D. Don't let garbage drive read_line_input() --- libbb/lineedit.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libbb') diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 1b88a7141..413782d06 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -1915,6 +1915,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li INIT_S(); #if ENABLE_PLATFORM_MINGW32 + memset(initial_settings.c_cc, sizeof(initial_settings.c_cc), 0); if (!isatty(0) || !isatty(1)) { #else if (tcgetattr(STDIN_FILENO, &initial_settings) < 0 -- cgit v1.2.3-55-g6feb From 6e1050c254353471131672c0e8383c9e906d6fb5 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Wed, 22 Sep 2010 09:43:03 +1000 Subject: win32: lineedit: make read_key() pass Ctrl+ to read_line_input This makes ^C and ^D work properly regarding ash input handling (i.e. does not crash ash). Pressing ^C in ash does not stop running programs though. --- libbb/lineedit.c | 2 ++ win32/termios.c | 6 ++++++ 2 files changed, 8 insertions(+) (limited to 'libbb') diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 413782d06..182dfac13 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -1916,6 +1916,8 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li #if ENABLE_PLATFORM_MINGW32 memset(initial_settings.c_cc, sizeof(initial_settings.c_cc), 0); + initial_settings.c_cc[VINTR] = CTRL('C'); + initial_settings.c_cc[VEOF] = CTRL('D'); if (!isatty(0) || !isatty(1)) { #else if (tcgetattr(STDIN_FILENO, &initial_settings) < 0 diff --git a/win32/termios.c b/win32/termios.c index e2dc96361..34a17bbfd 100644 --- a/win32/termios.c +++ b/win32/termios.c @@ -31,6 +31,12 @@ int64_t FAST_FUNC read_key(int fd, char *buf, int timeout UNUSED_PARAM) continue; if (!record.Event.KeyEvent.uChar.AsciiChar) { DWORD state = record.Event.KeyEvent.dwControlKeyState; + + if (state & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED) && + (record.Event.KeyEvent.wVirtualKeyCode >= 'A' && + record.Event.KeyEvent.wVirtualKeyCode <= 'Z')) + return record.Event.KeyEvent.wVirtualKeyCode & ~0x40; + switch (record.Event.KeyEvent.wVirtualKeyCode) { case VK_DELETE: return KEYCODE_DELETE; case VK_INSERT: return KEYCODE_INSERT; -- cgit v1.2.3-55-g6feb