From 6c95b555acfb124aa2f4a3d53acb731ac0a7e93b Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Thu, 8 Nov 2018 12:34:52 +0200 Subject: [PATCH] shell: Add macros to print messages This adds macros for printing info, normal, warning and error messages including line termination. Signed-off-by: Luiz Augusto von Dentz --- doc/subsystems/shell/shell.rst | 9 +++---- include/shell/shell.h | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/doc/subsystems/shell/shell.rst b/doc/subsystems/shell/shell.rst index 008f0238eed..2eaec87bd46 100644 --- a/doc/subsystems/shell/shell.rst +++ b/doc/subsystems/shell/shell.rst @@ -229,14 +229,11 @@ Simple command handler implementation: ARG_UNUSED(argc); ARG_UNUSED(argv); - shell_fprintf(shell, SHELL_NORMAL, - "Print simple text.\n"); + shell_print(shell, "Print simple text."); - shell_fprintf(shell, SHELL_WARNING, - "Print warning text.\n"); + shell_warn(shell, "Print warning text."); - shell_fprintf(shell, SHELL_ERROR, - "Print error text.\n"); + shell_error(shell, "Print error text."); return 0; } diff --git a/include/shell/shell.h b/include/shell/shell.h index 78a46af734c..fb278b826d6 100644 --- a/include/shell/shell.h +++ b/include/shell/shell.h @@ -557,6 +557,53 @@ int shell_stop(const struct shell *shell); void shell_fprintf(const struct shell *shell, enum shell_vt100_color color, const char *p_fmt, ...); +/** + * @brief Print info message to the shell. + * + * This function shall not be used outside of the shell command context. + * + * @param[in] _sh Pointer to the shell instance. + * @param[in] _ft Format string. + * @param[in] ... List of parameters to print. + */ +#define shell_info(_sh, _ft, ...) \ + shell_fprintf(_sh, SHELL_NORMAL, _ft "\n", ##__VA_ARGS__) + +/** + * @brief Print normal message to the shell. + * + * This function shall not be used outside of the shell command context. + * + * @param[in] _sh Pointer to the shell instance. + * @param[in] _ft Format string. + * @param[in] ... List of parameters to print. + */ +#define shell_print(_sh, _ft, ...) \ + shell_fprintf(_sh, SHELL_NORMAL, _ft "\n", ##__VA_ARGS__) + +/** + * @brief Print warning message to the shell. + * + * This function shall not be used outside of the shell command context. + * + * @param[in] _sh Pointer to the shell instance. + * @param[in] _ft Format string. + * @param[in] ... List of parameters to print. + */ +#define shell_warn(_sh, _ft, ...) \ + shell_fprintf(_sh, SHELL_ERROR, _ft "\n", ##__VA_ARGS__) + +/** + * @brief Print error message to the shell. + * + * This function shall not be used outside of the shell command context. + * @param[in] _sh Pointer to the shell instance. + * @param[in] _ft Format string. + * @param[in] ... List of parameters to print. + */ +#define shell_error(_sh, _ft, ...) \ + shell_fprintf(_sh, SHELL_ERROR, _ft "\n", ##__VA_ARGS__) + /** * @brief Process function, which should be executed when data is ready in the * transport interface. To be used if shell thread is disabled.