Skip to content

Commit 0bca046

Browse files
asemjonovsnashif
authored andcommitted
shell: Allow extension of shell APIs
Similar to logging module, allow application specific extension of shell fprintf APIs at a macro level. Signed-off-by: Al Semjonovs <[email protected]>
1 parent 30b122b commit 0bca046

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

include/zephyr/shell/shell.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,9 +1008,10 @@ int shell_stop(const struct shell *sh);
10081008
* @param[in] fmt Format string.
10091009
* @param[in] ... List of parameters to print.
10101010
*/
1011-
void __printf_like(3, 4) shell_fprintf(const struct shell *sh,
1012-
enum shell_vt100_color color,
1013-
const char *fmt, ...);
1011+
void __printf_like(3, 4) shell_fprintf_impl(const struct shell *sh, enum shell_vt100_color color,
1012+
const char *fmt, ...);
1013+
1014+
#define shell_fprintf(sh, color, fmt, ...) shell_fprintf_impl(sh, color, fmt, ##__VA_ARGS__)
10141015

10151016
/**
10161017
* @brief vprintf-like function which sends formatted data stream to the shell.
@@ -1277,4 +1278,9 @@ int shell_get_return_value(const struct shell *sh);
12771278
}
12781279
#endif
12791280

1281+
#ifdef CONFIG_SHELL_CUSTOM_HEADER
1282+
/* This include must always be at the end of shell.h */
1283+
#include <zephyr_custom_shell.h>
1284+
#endif
1285+
12801286
#endif /* SHELL_H__ */

subsys/shell/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,14 @@ config SHELL_CMDS_RETURN_VALUE
297297
This option enables the retval command. It is used to retrieve
298298
the return value from the most recently executed command.
299299

300+
config SHELL_CUSTOM_HEADER
301+
bool "Include Custom Shell Header"
302+
help
303+
When enabled, a custom application provided header, named
304+
"zephyr_custom_shell.h", is included at the end of shell.h. This enables
305+
extension of the shell APIs at the macro level. Please use cautiously!
306+
The internal shell API may change in future releases.
307+
300308
source "subsys/shell/modules/Kconfig"
301309

302310
endif # SHELL

subsys/shell/shell.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,7 @@ void shell_vfprintf(const struct shell *sh, enum shell_vt100_color color,
15481548
/* This function mustn't be used from shell context to avoid deadlock.
15491549
* However it can be used in shell command handlers.
15501550
*/
1551-
void shell_fprintf(const struct shell *sh, enum shell_vt100_color color,
1551+
void shell_fprintf_impl(const struct shell *sh, enum shell_vt100_color color,
15521552
const char *fmt, ...)
15531553
{
15541554
va_list args;

0 commit comments

Comments
 (0)