From a1ccb78df0a218d8fa760015f82bca6b7939b95b Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 1 Jun 2023 13:52:33 +0100 Subject: ash: enable 'set -/+o noconsole' Previously the 'noconsole' shell option could only be set as a shell command line option. Allow it to be changed from within the shell by 'set -o noconsole' or 'set +o noconsole'. The console window is now minimised rather than hidden. This makes it easier for the user to access the console when 'noconsole' is in effect. Adds 8-32 bytes. (GitHub issue #325) --- include/mingw.h | 2 +- shell/ash.c | 8 +++----- win32/mingw.c | 14 ++++++-------- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/include/mingw.h b/include/mingw.h index 13adf9017..e937a9e3c 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -577,7 +577,7 @@ ULONGLONG CompatGetTickCount64(void); ssize_t get_random_bytes(void *buf, ssize_t count); int enumerate_links(const char *file, char *name); -void hide_console(void); +void hide_console(int); int unc_root_len(const char *dir); int root_len(const char *path); diff --git a/shell/ash.c b/shell/ash.c index 09e8725bf..fda4541b4 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -10789,6 +10789,9 @@ optschanged(void) #else viflag = 0; /* forcibly keep the option off */ #endif +#if ENABLE_ASH_NOCONSOLE + hide_console(noconsole); +#endif } struct localvar_list { @@ -16075,11 +16078,6 @@ int ash_main(int argc UNUSED_PARAM, char **argv) trace_puts_args(argv); #endif -#if ENABLE_ASH_NOCONSOLE - if (noconsole) - hide_console(); -#endif - #if ENABLE_PLATFORM_MINGW32 if (dirarg) { chdir(dirarg); diff --git a/win32/mingw.c b/win32/mingw.c index be4fc7aa1..2cf4a45a2 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -2185,17 +2185,15 @@ int enumerate_links(const char *file, char *name) #endif #if ENABLE_ASH_NOCONSOLE -void hide_console(void) +void hide_console(int hide) { - DWORD dummy; - DECLARE_PROC_ADDR(DWORD, GetConsoleProcessList, LPDWORD, DWORD); DECLARE_PROC_ADDR(BOOL, ShowWindow, HWND, int); + DECLARE_PROC_ADDR(BOOL, IsIconic, HWND); - if (INIT_PROC_ADDR(kernel32.dll, GetConsoleProcessList) && - INIT_PROC_ADDR(user32.dll, ShowWindow)) { - if (GetConsoleProcessList(&dummy, 1) == 1) { - ShowWindow(GetConsoleWindow(), SW_HIDE); - } + if (INIT_PROC_ADDR(user32.dll, ShowWindow) && + INIT_PROC_ADDR(user32.dll, IsIconic)) { + if (IsIconic(GetConsoleWindow()) == !hide) + ShowWindow(GetConsoleWindow(), hide ? SW_MINIMIZE : SW_NORMAL); } } #endif -- cgit v1.2.3-55-g6feb