diff options
author | Ron Yorston <rmy@pobox.com> | 2024-04-09 08:58:58 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2024-04-09 08:58:58 +0100 |
commit | fcf3ec2877f042c6957d808e562807089e23ebe6 (patch) | |
tree | 02fc4bf8d6fd8284564d3cf27cbd17482b8f5744 | |
parent | 55ecf3a746db5131ca078875168a59feab8b26f1 (diff) | |
download | busybox-w32-fcf3ec2877f042c6957d808e562807089e23ebe6.tar.gz busybox-w32-fcf3ec2877f042c6957d808e562807089e23ebe6.tar.bz2 busybox-w32-fcf3ec2877f042c6957d808e562807089e23ebe6.zip |
ash: add title built-in
Implement a 'title' built-in for ash. It's very simple-minded,
performs almost no error checking and is completely non-portable.
- With no arguments it prints the current console title.
- If arguments are provided the *first only* is set as the console
title.
Costs 88-116 bytes.
(GitHub issue #401)
-rw-r--r-- | include/mingw.h | 1 | ||||
-rw-r--r-- | shell/ash.c | 21 | ||||
-rw-r--r-- | win32/winansi.c | 8 |
3 files changed, 28 insertions, 2 deletions
diff --git a/include/mingw.h b/include/mingw.h index 4abdcf459..41d4cd940 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -158,6 +158,7 @@ BOOL conToCharA(LPSTR d); | |||
158 | BOOL readConsoleInput_utf8(HANDLE h, INPUT_RECORD *r, DWORD len, DWORD *got); | 158 | BOOL readConsoleInput_utf8(HANDLE h, INPUT_RECORD *r, DWORD len, DWORD *got); |
159 | 159 | ||
160 | void set_title(const char *str); | 160 | void set_title(const char *str); |
161 | int get_title(char *buf, int len); | ||
161 | void move_cursor_row(int n); | 162 | void move_cursor_row(int n); |
162 | void reset_screen(void); | 163 | void reset_screen(void); |
163 | int winansi_putchar(int c); | 164 | int winansi_putchar(int c); |
diff --git a/shell/ash.c b/shell/ash.c index d312cb8cd..df27e9c8d 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -11253,6 +11253,9 @@ static int readcmd(int, char **) FAST_FUNC; | |||
11253 | static int setcmd(int, char **) FAST_FUNC; | 11253 | static int setcmd(int, char **) FAST_FUNC; |
11254 | static int shiftcmd(int, char **) FAST_FUNC; | 11254 | static int shiftcmd(int, char **) FAST_FUNC; |
11255 | static int timescmd(int, char **) FAST_FUNC; | 11255 | static int timescmd(int, char **) FAST_FUNC; |
11256 | #if ENABLE_PLATFORM_MINGW32 | ||
11257 | static int titlecmd(int, char **) FAST_FUNC; | ||
11258 | #endif | ||
11256 | static int trapcmd(int, char **) FAST_FUNC; | 11259 | static int trapcmd(int, char **) FAST_FUNC; |
11257 | static int umaskcmd(int, char **) FAST_FUNC; | 11260 | static int umaskcmd(int, char **) FAST_FUNC; |
11258 | static int unsetcmd(int, char **) FAST_FUNC; | 11261 | static int unsetcmd(int, char **) FAST_FUNC; |
@@ -11352,6 +11355,9 @@ static const struct builtincmd builtintab[] = { | |||
11352 | { BUILTIN_REGULAR "test" , testcmd }, | 11355 | { BUILTIN_REGULAR "test" , testcmd }, |
11353 | #endif | 11356 | #endif |
11354 | { BUILTIN_SPEC_REG "times" , timescmd }, | 11357 | { BUILTIN_SPEC_REG "times" , timescmd }, |
11358 | #if ENABLE_PLATFORM_MINGW32 | ||
11359 | { BUILTIN_REGULAR "title" , titlecmd }, | ||
11360 | #endif | ||
11355 | { BUILTIN_SPEC_REG "trap" , trapcmd }, | 11361 | { BUILTIN_SPEC_REG "trap" , trapcmd }, |
11356 | { BUILTIN_REGULAR "true" , truecmd }, | 11362 | { BUILTIN_REGULAR "true" , truecmd }, |
11357 | { BUILTIN_REGULAR "type" , typecmd }, | 11363 | { BUILTIN_REGULAR "type" , typecmd }, |
@@ -15549,6 +15555,21 @@ timescmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
15549 | return 0; | 15555 | return 0; |
15550 | } | 15556 | } |
15551 | 15557 | ||
15558 | #if ENABLE_PLATFORM_MINGW32 | ||
15559 | static int FAST_FUNC | ||
15560 | titlecmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | ||
15561 | { | ||
15562 | if (*argptr == NULL) { | ||
15563 | char buffer[256]; | ||
15564 | if (get_title(buffer, sizeof(buffer))) | ||
15565 | puts(buffer); | ||
15566 | } else { | ||
15567 | set_title(*argptr); | ||
15568 | } | ||
15569 | return 0; | ||
15570 | } | ||
15571 | #endif | ||
15572 | |||
15552 | #if ENABLE_FEATURE_SH_MATH | 15573 | #if ENABLE_FEATURE_SH_MATH |
15553 | /* | 15574 | /* |
15554 | * The let builtin. Partially stolen from GNU Bash, the Bourne Again SHell. | 15575 | * The let builtin. Partially stolen from GNU Bash, the Bourne Again SHell. |
diff --git a/win32/winansi.c b/win32/winansi.c index 0dd2e17f2..3b7744b39 100644 --- a/win32/winansi.c +++ b/win32/winansi.c | |||
@@ -179,8 +179,12 @@ int terminal_mode(int reset) | |||
179 | 179 | ||
180 | void set_title(const char *str) | 180 | void set_title(const char *str) |
181 | { | 181 | { |
182 | if (is_console(STDOUT_FILENO)) | 182 | SetConsoleTitle(str); |
183 | SetConsoleTitle(str); | 183 | } |
184 | |||
185 | int get_title(char *buf, int len) | ||
186 | { | ||
187 | return GetConsoleTitle(buf, len); | ||
184 | } | 188 | } |
185 | 189 | ||
186 | static HANDLE dup_handle(HANDLE h) | 190 | static HANDLE dup_handle(HANDLE h) |