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 <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2018-11-08 12:34:52 +02:00 committed by Carles Cufí
commit 6c95b555ac
2 changed files with 50 additions and 6 deletions

View file

@ -229,14 +229,11 @@ Simple command handler implementation:
ARG_UNUSED(argc); ARG_UNUSED(argc);
ARG_UNUSED(argv); ARG_UNUSED(argv);
shell_fprintf(shell, SHELL_NORMAL, shell_print(shell, "Print simple text.");
"Print simple text.\n");
shell_fprintf(shell, SHELL_WARNING, shell_warn(shell, "Print warning text.");
"Print warning text.\n");
shell_fprintf(shell, SHELL_ERROR, shell_error(shell, "Print error text.");
"Print error text.\n");
return 0; return 0;
} }

View file

@ -557,6 +557,53 @@ int shell_stop(const struct shell *shell);
void shell_fprintf(const struct shell *shell, enum shell_vt100_color color, void shell_fprintf(const struct shell *shell, enum shell_vt100_color color,
const char *p_fmt, ...); 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 * @brief Process function, which should be executed when data is ready in the
* transport interface. To be used if shell thread is disabled. * transport interface. To be used if shell thread is disabled.