shell: static functions cleanup
Removed shell_ prefix from static functions in .c files. Added static functions for setting and getting shell internal flags. Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
This commit is contained in:
parent
4d491b283b
commit
f7f4fe33a1
6 changed files with 531 additions and 479 deletions
File diff suppressed because it is too large
Load diff
|
@ -197,7 +197,7 @@ static int cmd_bacskpace_mode_backspace(const struct shell *shell, size_t argc,
|
|||
ARG_UNUSED(argc);
|
||||
ARG_UNUSED(argv);
|
||||
|
||||
shell->ctx->internal.flags.mode_delete = 0;
|
||||
flag_mode_delete_set(shell, false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ static int cmd_bacskpace_mode_delete(const struct shell *shell, size_t argc,
|
|||
ARG_UNUSED(argc);
|
||||
ARG_UNUSED(argv);
|
||||
|
||||
shell->ctx->internal.flags.mode_delete = 1;
|
||||
flag_mode_delete_set(shell, true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ static int cmd_colors_off(const struct shell *shell, size_t argc, char **argv)
|
|||
ARG_UNUSED(argc);
|
||||
ARG_UNUSED(argv);
|
||||
|
||||
shell->ctx->internal.flags.use_colors = 0;
|
||||
flag_use_colors_set(shell, false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ static int cmd_colors_on(const struct shell *shell, size_t argc, char **argv)
|
|||
ARG_UNUSED(argv);
|
||||
ARG_UNUSED(argv);
|
||||
|
||||
shell->ctx->internal.flags.use_colors = 1;
|
||||
flag_use_colors_set(shell, true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ static int cmd_echo_off(const struct shell *shell, size_t argc, char **argv)
|
|||
ARG_UNUSED(argc);
|
||||
ARG_UNUSED(argv);
|
||||
|
||||
shell->ctx->internal.flags.echo = 0;
|
||||
flag_echo_set(shell, false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -248,7 +248,7 @@ static int cmd_echo_on(const struct shell *shell, size_t argc, char **argv)
|
|||
ARG_UNUSED(argc);
|
||||
ARG_UNUSED(argv);
|
||||
|
||||
shell->ctx->internal.flags.echo = 1;
|
||||
flag_echo_set(shell, true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -262,7 +262,7 @@ static int cmd_echo(const struct shell *shell, size_t argc, char **argv)
|
|||
}
|
||||
|
||||
shell_print(shell, "Echo status: %s",
|
||||
flag_echo_is_set(shell) ? "on" : "off");
|
||||
flag_echo_get(shell) ? "on" : "off");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -204,7 +204,7 @@ static void data_insert(const struct shell *shell, const char *data, u16_t len)
|
|||
shell->ctx->cmd_buff_len += len;
|
||||
shell->ctx->cmd_buff[shell->ctx->cmd_buff_len] = '\0';
|
||||
|
||||
if (!flag_echo_is_set(shell)) {
|
||||
if (!flag_echo_get(shell)) {
|
||||
shell->ctx->cmd_buff_pos += len;
|
||||
return;
|
||||
}
|
||||
|
@ -263,6 +263,17 @@ void shell_op_completion_insert(const struct shell *shell,
|
|||
data_insert(shell, compl, compl_len);
|
||||
}
|
||||
|
||||
void shell_cmd_line_erase(const struct shell *shell)
|
||||
{
|
||||
shell_multiline_data_calc(&shell->ctx->vt100_ctx.cons,
|
||||
shell->ctx->cmd_buff_pos,
|
||||
shell->ctx->cmd_buff_len);
|
||||
shell_op_cursor_horiz_move(shell, -shell->ctx->vt100_ctx.cons.cur_x);
|
||||
shell_op_cursor_vert_move(shell, shell->ctx->vt100_ctx.cons.cur_y - 1);
|
||||
|
||||
clear_eos(shell);
|
||||
}
|
||||
|
||||
static void shell_pend_on_txdone(const struct shell *shell)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_MULTITHREADING)) {
|
||||
|
@ -270,9 +281,9 @@ static void shell_pend_on_txdone(const struct shell *shell)
|
|||
k_poll_signal_reset(&shell->ctx->signals[SHELL_SIGNAL_TXDONE]);
|
||||
} else {
|
||||
/* Blocking wait in case of bare metal. */
|
||||
while (!shell->ctx->internal.flags.tx_rdy) {
|
||||
while (!flag_tx_rdy_get(shell)) {
|
||||
}
|
||||
shell->ctx->internal.flags.tx_rdy = 0;
|
||||
flag_tx_rdy_set(shell, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -306,3 +317,48 @@ void shell_print_stream(const void *user_ctx, const char *data,
|
|||
{
|
||||
shell_write((const struct shell *) user_ctx, data, data_len);
|
||||
}
|
||||
|
||||
static void vt100_bgcolor_set(const struct shell *shell,
|
||||
enum shell_vt100_color bgcolor)
|
||||
{
|
||||
if ((bgcolor == SHELL_NORMAL) ||
|
||||
(shell->ctx->vt100_ctx.col.bgcol == bgcolor)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* -1 because default value is first in enum */
|
||||
u8_t cmd[] = SHELL_VT100_BGCOLOR(bgcolor - 1);
|
||||
|
||||
shell->ctx->vt100_ctx.col.bgcol = bgcolor;
|
||||
shell_raw_fprintf(shell->fprintf_ctx, "%s", cmd);
|
||||
|
||||
}
|
||||
|
||||
void shell_vt100_color_set(const struct shell *shell,
|
||||
enum shell_vt100_color color)
|
||||
{
|
||||
|
||||
if (shell->ctx->vt100_ctx.col.col == color) {
|
||||
return;
|
||||
}
|
||||
|
||||
shell->ctx->vt100_ctx.col.col = color;
|
||||
|
||||
if (color != SHELL_NORMAL) {
|
||||
|
||||
u8_t cmd[] = SHELL_VT100_COLOR(color - 1);
|
||||
|
||||
shell_raw_fprintf(shell->fprintf_ctx, "%s", cmd);
|
||||
} else {
|
||||
static const u8_t cmd[] = SHELL_VT100_MODESOFF;
|
||||
|
||||
shell_raw_fprintf(shell->fprintf_ctx, "%s", cmd);
|
||||
}
|
||||
}
|
||||
|
||||
void shell_vt100_colors_restore(const struct shell *shell,
|
||||
const struct shell_vt100_colors *color)
|
||||
{
|
||||
shell_vt100_color_set(shell, color->col);
|
||||
vt100_bgcolor_set(shell, color->bgcol);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#ifndef SHELL_OPS_H__
|
||||
#define SHELL_OPS_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <shell/shell.h>
|
||||
#include "shell_vt100.h"
|
||||
#include "shell_utils.h"
|
||||
|
@ -68,11 +69,81 @@ static inline void shell_putc(const struct shell *shell, char ch)
|
|||
shell_raw_fprintf(shell->fprintf_ctx, "%c", ch);
|
||||
}
|
||||
|
||||
static inline bool flag_echo_is_set(const struct shell *shell)
|
||||
static inline bool flag_insert_mode_get(const struct shell *shell)
|
||||
{
|
||||
return ((shell->ctx->internal.flags.insert_mode == 1) ? true : false);
|
||||
}
|
||||
|
||||
static inline void flag_insert_mode_set(const struct shell *shell, bool val)
|
||||
{
|
||||
shell->ctx->internal.flags.insert_mode = val ? 1 : 0;
|
||||
}
|
||||
|
||||
static inline bool flag_use_colors_get(const struct shell *shell)
|
||||
{
|
||||
return shell->ctx->internal.flags.use_colors == 1 ? true : false;
|
||||
}
|
||||
|
||||
static inline void flag_use_colors_set(const struct shell *shell, bool val)
|
||||
{
|
||||
shell->ctx->internal.flags.use_colors = val ? 1 : 0;
|
||||
}
|
||||
|
||||
static inline bool flag_echo_get(const struct shell *shell)
|
||||
{
|
||||
return shell->ctx->internal.flags.echo == 1 ? true : false;
|
||||
}
|
||||
|
||||
static inline void flag_echo_set(const struct shell *shell, bool val)
|
||||
{
|
||||
shell->ctx->internal.flags.echo = val ? 1 : 0;
|
||||
}
|
||||
|
||||
static inline bool flag_processing_get(const struct shell *shell)
|
||||
{
|
||||
return shell->ctx->internal.flags.processing == 1 ? true : false;
|
||||
}
|
||||
|
||||
static inline bool flag_tx_rdy_get(const struct shell *shell)
|
||||
{
|
||||
return shell->ctx->internal.flags.tx_rdy == 1 ? true : false;
|
||||
}
|
||||
|
||||
static inline void flag_tx_rdy_set(const struct shell *shell, bool val)
|
||||
{
|
||||
shell->ctx->internal.flags.tx_rdy = val ? 1 : 0;
|
||||
}
|
||||
|
||||
static inline bool flag_mode_delete_get(const struct shell *shell)
|
||||
{
|
||||
return shell->ctx->internal.flags.mode_delete == 1 ? true : false;
|
||||
}
|
||||
|
||||
static inline void flag_mode_delete_set(const struct shell *shell, bool val)
|
||||
{
|
||||
shell->ctx->internal.flags.mode_delete = val ? 1 : 0;
|
||||
}
|
||||
|
||||
static inline bool flag_history_exit_get(const struct shell *shell)
|
||||
{
|
||||
return shell->ctx->internal.flags.history_exit == 1 ? true : false;
|
||||
}
|
||||
|
||||
static inline void flag_history_exit_set(const struct shell *shell, bool val)
|
||||
{
|
||||
shell->ctx->internal.flags.history_exit = val ? 1 : 0;
|
||||
}
|
||||
|
||||
static inline u8_t flag_last_nl_get(const struct shell *shell)
|
||||
{
|
||||
return shell->ctx->internal.flags.last_nl;
|
||||
}
|
||||
|
||||
static inline void flag_last_nl_set(const struct shell *shell, u8_t val)
|
||||
{
|
||||
shell->ctx->internal.flags.last_nl = val;
|
||||
}
|
||||
|
||||
void shell_op_cursor_vert_move(const struct shell *shell, s32_t delta);
|
||||
void shell_op_cursor_horiz_move(const struct shell *shell, s32_t delta);
|
||||
|
||||
|
@ -121,6 +192,8 @@ void shell_op_completion_insert(const struct shell *shell,
|
|||
|
||||
bool shell_cursor_in_empty_line(const struct shell *shell);
|
||||
|
||||
void shell_cmd_line_erase(const struct shell *shell);
|
||||
|
||||
/* Function sends data stream to the shell instance. Each time before the
|
||||
* shell_write function is called, it must be ensured that IO buffer of fprintf
|
||||
* is flushed to avoid synchronization issues.
|
||||
|
@ -143,6 +216,19 @@ void shell_write(const struct shell *shell, const void *data,
|
|||
void shell_print_stream(const void *user_ctx, const char *data,
|
||||
size_t data_len);
|
||||
|
||||
/** @internal @brief Function for setting font color */
|
||||
void shell_vt100_color_set(const struct shell *shell,
|
||||
enum shell_vt100_color color);
|
||||
|
||||
static inline void shell_vt100_colors_store(const struct shell *shell,
|
||||
struct shell_vt100_colors *color)
|
||||
{
|
||||
memcpy(color, &shell->ctx->vt100_ctx.col, sizeof(*color));
|
||||
}
|
||||
|
||||
void shell_vt100_colors_restore(const struct shell *shell,
|
||||
const struct shell_vt100_colors *color);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -225,7 +225,7 @@ static inline u32_t shell_root_cmd_count(void)
|
|||
}
|
||||
|
||||
/* Function returning pointer to root command matching requested syntax. */
|
||||
const struct shell_cmd_entry *root_cmd_find(const char *syntax)
|
||||
const struct shell_cmd_entry *shell_root_cmd_find(const char *syntax)
|
||||
{
|
||||
const size_t cmd_count = shell_root_cmd_count();
|
||||
const struct shell_cmd_entry *cmd;
|
||||
|
@ -335,7 +335,10 @@ void shell_spaces_trim(char *str)
|
|||
}
|
||||
}
|
||||
|
||||
void shell_buffer_trim(char *buff, u16_t *buff_len)
|
||||
/** @brief Remove white chars from beginning and end of command buffer.
|
||||
*
|
||||
*/
|
||||
static void buffer_trim(char *buff, u16_t *buff_len)
|
||||
{
|
||||
u16_t i = 0U;
|
||||
|
||||
|
@ -369,3 +372,9 @@ void shell_buffer_trim(char *buff, u16_t *buff_len)
|
|||
*buff_len = *buff_len - i;
|
||||
}
|
||||
}
|
||||
|
||||
void shell_cmd_trim(const struct shell *shell)
|
||||
{
|
||||
buffer_trim(shell->ctx->cmd_buff, &shell->ctx->cmd_buff_len);
|
||||
shell->ctx->cmd_buff_pos = shell->ctx->cmd_buff_len;
|
||||
}
|
||||
|
|
|
@ -64,20 +64,17 @@ void shell_cmd_get(const struct shell_cmd_entry *command, size_t lvl,
|
|||
int shell_command_add(char *buff, u16_t *buff_len,
|
||||
const char *new_cmd, const char *pattern);
|
||||
|
||||
const struct shell_cmd_entry *root_cmd_find(const char *syntax);
|
||||
const struct shell_cmd_entry *shell_root_cmd_find(const char *syntax);
|
||||
|
||||
void shell_spaces_trim(char *str);
|
||||
|
||||
/** @brief Remove white chars from beginning and end of command buffer.
|
||||
*
|
||||
*/
|
||||
void shell_buffer_trim(char *buff, u16_t *buff_len);
|
||||
|
||||
static inline void transport_buffer_flush(const struct shell *shell)
|
||||
{
|
||||
shell_fprintf_buffer_flush(shell->fprintf_ctx);
|
||||
}
|
||||
|
||||
void shell_cmd_trim(const struct shell *shell);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue