2018-08-09 09:56:10 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Nordic Semiconductor ASA
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
#ifndef SHELL_OPS_H__
|
|
|
|
#define SHELL_OPS_H__
|
|
|
|
|
2018-12-13 10:26:49 +01:00
|
|
|
#include <stdbool.h>
|
2022-05-06 11:12:04 +02:00
|
|
|
#include <zephyr/shell/shell.h>
|
2018-08-09 09:56:10 +02:00
|
|
|
#include "shell_vt100.h"
|
|
|
|
#include "shell_utils.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-12-07 13:22:35 +01:00
|
|
|
static inline void z_shell_raw_fprintf(const struct shell_fprintf *const ctx,
|
|
|
|
const char *fmt, ...)
|
2018-08-09 09:56:10 +02:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
2020-12-06 11:22:27 +01:00
|
|
|
z_shell_fprintf_fmt(ctx, fmt, args);
|
2018-08-09 09:56:10 +02:00
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2021-09-20 14:18:08 +02:00
|
|
|
/* Macro to send VT100 command. */
|
|
|
|
#define Z_SHELL_VT100_CMD(_shell_, ...) \
|
2018-08-09 09:56:10 +02:00
|
|
|
do { \
|
2021-09-20 14:21:57 +02:00
|
|
|
if (!IS_ENABLED(CONFIG_SHELL_VT100_COMMANDS) || \
|
|
|
|
!z_flag_use_vt100_get(_shell_)) \
|
2021-06-07 18:48:27 +02:00
|
|
|
break; \
|
2021-09-20 14:18:08 +02:00
|
|
|
z_shell_raw_fprintf(_shell_->fprintf_ctx, __VA_ARGS__); \
|
2018-08-09 09:56:10 +02:00
|
|
|
} while (0)
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
#define Z_SHELL_SET_FLAG_ATOMIC(_shell_, _type_, _flag_, _val_, _ret_) \
|
2021-03-11 00:56:32 +01:00
|
|
|
do { \
|
2021-09-20 14:21:57 +02:00
|
|
|
union shell_backend_##_type_ _internal_; \
|
|
|
|
atomic_t *_dst_ = (atomic_t *)&(_shell_)->ctx->_type_.value; \
|
2021-03-11 00:56:32 +01:00
|
|
|
_internal_.value = 0U; \
|
|
|
|
_internal_.flags._flag_ = 1U; \
|
|
|
|
if (_val_) { \
|
|
|
|
_internal_.value = atomic_or(_dst_, \
|
|
|
|
_internal_.value); \
|
|
|
|
} else { \
|
|
|
|
_internal_.value = atomic_and(_dst_, \
|
|
|
|
~_internal_.value); \
|
|
|
|
} \
|
|
|
|
_ret_ = (_internal_.flags._flag_ != 0); \
|
2024-06-07 17:50:33 +02:00
|
|
|
} while (false)
|
2021-03-11 00:56:32 +01:00
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_insert_mode_get(const struct shell *sh)
|
|
|
|
{
|
|
|
|
return sh->ctx->cfg.flags.insert_mode == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool z_flag_insert_mode_set(const struct shell *sh, bool val)
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
Z_SHELL_SET_FLAG_ATOMIC(sh, cfg, insert_mode, val, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool z_flag_use_colors_get(const struct shell *sh)
|
2018-12-13 10:26:49 +01:00
|
|
|
{
|
2021-09-20 14:21:57 +02:00
|
|
|
return sh->ctx->cfg.flags.use_colors == 1;
|
2018-12-13 10:26:49 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_use_colors_set(const struct shell *sh, bool val)
|
2018-12-13 10:26:49 +01:00
|
|
|
{
|
2021-03-11 00:56:32 +01:00
|
|
|
bool ret;
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
Z_SHELL_SET_FLAG_ATOMIC(sh, cfg, use_colors, val, ret);
|
2021-03-11 00:56:32 +01:00
|
|
|
return ret;
|
2018-12-13 10:26:49 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_use_vt100_get(const struct shell *sh)
|
2018-12-13 10:26:49 +01:00
|
|
|
{
|
2021-09-20 14:21:57 +02:00
|
|
|
return sh->ctx->cfg.flags.use_vt100 == 1;
|
2018-12-13 10:26:49 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_use_vt100_set(const struct shell *sh, bool val)
|
2018-12-13 10:26:49 +01:00
|
|
|
{
|
2021-03-11 00:56:32 +01:00
|
|
|
bool ret;
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
Z_SHELL_SET_FLAG_ATOMIC(sh, cfg, use_vt100, val, ret);
|
2021-03-11 00:56:32 +01:00
|
|
|
return ret;
|
2018-12-13 10:26:49 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_echo_get(const struct shell *sh)
|
2018-08-09 09:56:10 +02:00
|
|
|
{
|
2021-09-20 14:21:57 +02:00
|
|
|
return sh->ctx->cfg.flags.echo == 1;
|
2018-08-09 09:56:10 +02:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_echo_set(const struct shell *sh, bool val)
|
2018-12-13 10:26:49 +01:00
|
|
|
{
|
2021-03-11 00:56:32 +01:00
|
|
|
bool ret;
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
Z_SHELL_SET_FLAG_ATOMIC(sh, cfg, echo, val, ret);
|
2021-03-11 00:56:32 +01:00
|
|
|
return ret;
|
2018-12-13 10:26:49 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_obscure_get(const struct shell *sh)
|
2021-03-04 20:28:05 +01:00
|
|
|
{
|
2021-09-20 14:21:57 +02:00
|
|
|
return sh->ctx->cfg.flags.obscure == 1;
|
2021-03-04 20:28:05 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_obscure_set(const struct shell *sh, bool val)
|
2021-03-04 20:28:05 +01:00
|
|
|
{
|
2021-03-11 00:56:32 +01:00
|
|
|
bool ret;
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
Z_SHELL_SET_FLAG_ATOMIC(sh, cfg, obscure, val, ret);
|
2021-03-11 00:56:32 +01:00
|
|
|
return ret;
|
2021-03-04 20:28:05 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_processing_get(const struct shell *sh)
|
2018-12-13 10:26:49 +01:00
|
|
|
{
|
2021-09-20 14:21:57 +02:00
|
|
|
return sh->ctx->ctx.flags.processing == 1;
|
2018-12-13 10:26:49 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_processing_set(const struct shell *sh, bool val)
|
2021-03-11 00:56:32 +01:00
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
Z_SHELL_SET_FLAG_ATOMIC(sh, ctx, processing, val, ret);
|
2021-03-11 00:56:32 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_tx_rdy_get(const struct shell *sh)
|
2018-12-13 10:26:49 +01:00
|
|
|
{
|
2021-09-20 14:21:57 +02:00
|
|
|
return sh->ctx->ctx.flags.tx_rdy == 1;
|
2018-12-13 10:26:49 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_tx_rdy_set(const struct shell *sh, bool val)
|
2018-12-13 10:26:49 +01:00
|
|
|
{
|
2021-03-11 00:56:32 +01:00
|
|
|
bool ret;
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
Z_SHELL_SET_FLAG_ATOMIC(sh, ctx, tx_rdy, val, ret);
|
2021-03-11 00:56:32 +01:00
|
|
|
return ret;
|
2018-12-13 10:26:49 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_mode_delete_get(const struct shell *sh)
|
2018-12-13 10:26:49 +01:00
|
|
|
{
|
2021-09-20 14:21:57 +02:00
|
|
|
return sh->ctx->cfg.flags.mode_delete == 1;
|
2018-12-13 10:26:49 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_mode_delete_set(const struct shell *sh, bool val)
|
2018-12-13 10:26:49 +01:00
|
|
|
{
|
2021-03-11 00:56:32 +01:00
|
|
|
bool ret;
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
Z_SHELL_SET_FLAG_ATOMIC(sh, cfg, mode_delete, val, ret);
|
2021-03-11 00:56:32 +01:00
|
|
|
return ret;
|
2018-12-13 10:26:49 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_history_exit_get(const struct shell *sh)
|
2018-12-13 10:26:49 +01:00
|
|
|
{
|
2021-09-20 14:21:57 +02:00
|
|
|
return sh->ctx->ctx.flags.history_exit == 1;
|
2018-12-13 10:26:49 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_history_exit_set(const struct shell *sh, bool val)
|
2018-12-13 10:26:49 +01:00
|
|
|
{
|
2021-03-11 00:56:32 +01:00
|
|
|
bool ret;
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
Z_SHELL_SET_FLAG_ATOMIC(sh, ctx, history_exit, val, ret);
|
2021-03-11 00:56:32 +01:00
|
|
|
return ret;
|
2018-12-13 10:26:49 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_cmd_ctx_get(const struct shell *sh)
|
shell: allow commands to suspend shell thread
It was possible to deadlock the shell when command
suspended shell's thread and next another thread wanted
to print something on the shell.
To avoid that shell releases mutex before entering command
handler. Due to this change some adapations to shell
internal print functions have been applied.
This change addresses following usecase:
1. A command handler needs to call a (system) function which
communicate results via a callback, and this callback is expected
to print these results. The callback is called by the system from
another thread.
2. To achieve that, the handler needs to pass `struct shell *`
to callbacks, but also some other data specific to callback.
Thus, handles allocates some structure will those fields on
the stack.
3. The handler schedules this callback to be called.
4. As a reference to stack structure is passed to the callback,
the handler can't return immediately (or stack data will go out
of scope and will be overwritten).
5. So, the handler blocks waiting for callback to finish.
Previously, this scenario led to deadlock when the callback
trying or print to shell. With these changes, it just works,
as long as main handler and callback serialize there access
to the shell structure (i.e. when callback prints, the main
handler is blocked waiting for its completion).
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-02-12 15:38:16 +01:00
|
|
|
{
|
2021-09-20 14:21:57 +02:00
|
|
|
return sh->ctx->ctx.flags.cmd_ctx == 1;
|
shell: allow commands to suspend shell thread
It was possible to deadlock the shell when command
suspended shell's thread and next another thread wanted
to print something on the shell.
To avoid that shell releases mutex before entering command
handler. Due to this change some adapations to shell
internal print functions have been applied.
This change addresses following usecase:
1. A command handler needs to call a (system) function which
communicate results via a callback, and this callback is expected
to print these results. The callback is called by the system from
another thread.
2. To achieve that, the handler needs to pass `struct shell *`
to callbacks, but also some other data specific to callback.
Thus, handles allocates some structure will those fields on
the stack.
3. The handler schedules this callback to be called.
4. As a reference to stack structure is passed to the callback,
the handler can't return immediately (or stack data will go out
of scope and will be overwritten).
5. So, the handler blocks waiting for callback to finish.
Previously, this scenario led to deadlock when the callback
trying or print to shell. With these changes, it just works,
as long as main handler and callback serialize there access
to the shell structure (i.e. when callback prints, the main
handler is blocked waiting for its completion).
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-02-12 15:38:16 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_cmd_ctx_set(const struct shell *sh, bool val)
|
shell: allow commands to suspend shell thread
It was possible to deadlock the shell when command
suspended shell's thread and next another thread wanted
to print something on the shell.
To avoid that shell releases mutex before entering command
handler. Due to this change some adapations to shell
internal print functions have been applied.
This change addresses following usecase:
1. A command handler needs to call a (system) function which
communicate results via a callback, and this callback is expected
to print these results. The callback is called by the system from
another thread.
2. To achieve that, the handler needs to pass `struct shell *`
to callbacks, but also some other data specific to callback.
Thus, handles allocates some structure will those fields on
the stack.
3. The handler schedules this callback to be called.
4. As a reference to stack structure is passed to the callback,
the handler can't return immediately (or stack data will go out
of scope and will be overwritten).
5. So, the handler blocks waiting for callback to finish.
Previously, this scenario led to deadlock when the callback
trying or print to shell. With these changes, it just works,
as long as main handler and callback serialize there access
to the shell structure (i.e. when callback prints, the main
handler is blocked waiting for its completion).
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-02-12 15:38:16 +01:00
|
|
|
{
|
2021-03-11 00:56:32 +01:00
|
|
|
bool ret;
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
Z_SHELL_SET_FLAG_ATOMIC(sh, ctx, cmd_ctx, val, ret);
|
2021-03-11 00:56:32 +01:00
|
|
|
return ret;
|
shell: allow commands to suspend shell thread
It was possible to deadlock the shell when command
suspended shell's thread and next another thread wanted
to print something on the shell.
To avoid that shell releases mutex before entering command
handler. Due to this change some adapations to shell
internal print functions have been applied.
This change addresses following usecase:
1. A command handler needs to call a (system) function which
communicate results via a callback, and this callback is expected
to print these results. The callback is called by the system from
another thread.
2. To achieve that, the handler needs to pass `struct shell *`
to callbacks, but also some other data specific to callback.
Thus, handles allocates some structure will those fields on
the stack.
3. The handler schedules this callback to be called.
4. As a reference to stack structure is passed to the callback,
the handler can't return immediately (or stack data will go out
of scope and will be overwritten).
5. So, the handler blocks waiting for callback to finish.
Previously, this scenario led to deadlock when the callback
trying or print to shell. With these changes, it just works,
as long as main handler and callback serialize there access
to the shell structure (i.e. when callback prints, the main
handler is blocked waiting for its completion).
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-02-12 15:38:16 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline uint8_t z_flag_last_nl_get(const struct shell *sh)
|
2018-12-13 10:26:49 +01:00
|
|
|
{
|
2021-09-20 14:21:57 +02:00
|
|
|
return sh->ctx->ctx.flags.last_nl;
|
2018-12-13 10:26:49 +01:00
|
|
|
}
|
|
|
|
|
2023-04-26 00:59:19 +02:00
|
|
|
static inline int z_shell_get_return_value(const struct shell *sh)
|
|
|
|
{
|
|
|
|
return sh->ctx->ret_val;
|
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline void z_flag_last_nl_set(const struct shell *sh, uint8_t val)
|
2018-12-13 10:26:49 +01:00
|
|
|
{
|
2021-09-20 14:21:57 +02:00
|
|
|
sh->ctx->ctx.flags.last_nl = val;
|
2018-12-13 10:26:49 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_print_noinit_get(const struct shell *sh)
|
2020-08-03 15:12:17 +02:00
|
|
|
{
|
2021-09-20 14:21:57 +02:00
|
|
|
return sh->ctx->ctx.flags.print_noinit == 1;
|
2020-08-03 15:12:17 +02:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline bool z_flag_print_noinit_set(const struct shell *sh, bool val)
|
2020-08-03 15:12:17 +02:00
|
|
|
{
|
2021-03-11 00:56:32 +01:00
|
|
|
bool ret;
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
Z_SHELL_SET_FLAG_ATOMIC(sh, ctx, print_noinit, val, ret);
|
2021-03-11 00:56:32 +01:00
|
|
|
return ret;
|
2020-08-03 15:12:17 +02:00
|
|
|
}
|
|
|
|
|
2022-01-05 11:11:52 +01:00
|
|
|
static inline bool z_flag_sync_mode_get(const struct shell *sh)
|
2021-09-21 11:10:28 +02:00
|
|
|
{
|
2022-01-05 11:11:52 +01:00
|
|
|
return sh->ctx->ctx.flags.sync_mode == 1;
|
2021-09-21 11:10:28 +02:00
|
|
|
}
|
|
|
|
|
2022-01-05 11:11:52 +01:00
|
|
|
static inline bool z_flag_sync_mode_set(const struct shell *sh, bool val)
|
2021-09-21 11:10:28 +02:00
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
|
2022-01-05 11:11:52 +01:00
|
|
|
Z_SHELL_SET_FLAG_ATOMIC(sh, ctx, sync_mode, val, ret);
|
2021-09-21 11:10:28 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-01-09 18:35:06 +01:00
|
|
|
static inline bool z_flag_handle_log_get(const struct shell *sh)
|
|
|
|
{
|
|
|
|
return sh->ctx->ctx.flags.handle_log == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool z_flag_handle_log_set(const struct shell *sh, bool val)
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
Z_SHELL_SET_FLAG_ATOMIC(sh, ctx, handle_log, val, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
/* Function sends VT100 command to clear the screen from cursor position to
|
|
|
|
* end of the screen.
|
|
|
|
*/
|
|
|
|
static inline void z_clear_eos(const struct shell *sh)
|
|
|
|
{
|
|
|
|
Z_SHELL_VT100_CMD(sh, SHELL_VT100_CLEAREOS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Function sends VT100 command to save cursor position. */
|
|
|
|
static inline void z_cursor_save(const struct shell *sh)
|
|
|
|
{
|
|
|
|
Z_SHELL_VT100_CMD(sh, SHELL_VT100_SAVECURSOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Function sends VT100 command to restore saved cursor position. */
|
|
|
|
static inline void z_cursor_restore(const struct shell *sh)
|
|
|
|
{
|
|
|
|
Z_SHELL_VT100_CMD(sh, SHELL_VT100_RESTORECURSOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Function forcing new line - cannot be replaced with function
|
|
|
|
* cursor_down_move.
|
|
|
|
*/
|
|
|
|
static inline void z_cursor_next_line_move(const struct shell *sh)
|
|
|
|
{
|
|
|
|
z_shell_raw_fprintf(sh->fprintf_ctx, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void z_shell_op_cursor_vert_move(const struct shell *sh, int32_t delta);
|
|
|
|
|
|
|
|
void z_shell_op_cursor_horiz_move(const struct shell *sh, int32_t delta);
|
2018-08-09 09:56:10 +02:00
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_op_cond_next_line(const struct shell *sh);
|
2018-08-09 09:56:10 +02:00
|
|
|
|
|
|
|
/* Function will move cursor back to position == cmd_buff_pos. Example usage is
|
|
|
|
* when cursor needs to be moved back after printing some text. This function
|
|
|
|
* cannot be used to move cursor to new location by manual change of
|
|
|
|
* cmd_buff_pos.
|
|
|
|
*/
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_op_cursor_position_synchronize(const struct shell *sh);
|
2018-08-09 09:56:10 +02:00
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_op_cursor_move(const struct shell *sh, int16_t val);
|
2018-08-09 09:56:10 +02:00
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_op_left_arrow(const struct shell *sh);
|
2018-08-09 09:56:10 +02:00
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_op_right_arrow(const struct shell *sh);
|
2018-08-09 09:56:10 +02:00
|
|
|
|
2019-01-11 15:08:55 +01:00
|
|
|
/* Moves cursor by defined number of words left (val negative) or right. */
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_op_cursor_word_move(const struct shell *sh, int16_t val);
|
2019-01-11 15:08:55 +01:00
|
|
|
|
2018-08-09 09:56:10 +02:00
|
|
|
/*
|
|
|
|
* Removes the "word" to the left of the cursor:
|
|
|
|
* - if there are spaces at the cursor position, remove all spaces to the left
|
|
|
|
* - remove the non-spaces (word) until a space is found or a beginning of
|
|
|
|
* buffer
|
|
|
|
*/
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_op_word_remove(const struct shell *sh);
|
2018-08-09 09:56:10 +02:00
|
|
|
|
|
|
|
/* Function moves cursor to begin of command position, just after console
|
|
|
|
* name.
|
|
|
|
*/
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_op_cursor_home_move(const struct shell *sh);
|
2018-08-09 09:56:10 +02:00
|
|
|
|
|
|
|
/* Function moves cursor to end of command. */
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_op_cursor_end_move(const struct shell *sh);
|
2018-08-09 09:56:10 +02:00
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_op_char_insert(const struct shell *sh, char data);
|
2018-08-09 09:56:10 +02:00
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_op_char_backspace(const struct shell *sh);
|
2018-08-09 09:56:10 +02:00
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_op_char_delete(const struct shell *sh);
|
2018-08-09 09:56:10 +02:00
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_op_delete_from_cursor(const struct shell *sh);
|
2019-01-11 15:08:55 +01:00
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_op_completion_insert(const struct shell *sh,
|
2020-12-07 13:22:35 +01:00
|
|
|
const char *compl,
|
|
|
|
uint16_t compl_len);
|
2018-08-09 09:56:10 +02:00
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
bool z_shell_cursor_in_empty_line(const struct shell *sh);
|
2018-11-26 17:09:56 +01:00
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_cmd_line_erase(const struct shell *sh);
|
2018-12-13 10:26:49 +01:00
|
|
|
|
2019-02-01 14:15:44 +01:00
|
|
|
/**
|
|
|
|
* @brief Print command buffer.
|
|
|
|
*
|
2023-04-13 18:59:37 +02:00
|
|
|
* @param sh Shell instance.
|
2019-02-01 14:15:44 +01:00
|
|
|
*/
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_print_cmd(const struct shell *sh);
|
2019-02-01 14:15:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Print prompt followed by command buffer.
|
|
|
|
*
|
2023-04-13 18:59:37 +02:00
|
|
|
* @param sh Shell instance.
|
2019-02-01 14:15:44 +01:00
|
|
|
*/
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_print_prompt_and_cmd(const struct shell *sh);
|
2019-02-01 14:15:44 +01:00
|
|
|
|
2018-11-26 17:09:56 +01:00
|
|
|
/* 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.
|
|
|
|
* For that purpose, use function transport_buffer_flush(shell)
|
|
|
|
*
|
|
|
|
* This function can be only used by shell module, it shall not be called
|
|
|
|
* directly.
|
|
|
|
*/
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_write(const struct shell *sh, const void *data, size_t length);
|
2018-11-26 17:09:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal @brief This function shall not be used directly, it is required by
|
|
|
|
* the fprintf module.
|
|
|
|
*
|
|
|
|
* @param[in] p_user_ctx Pointer to the context for the shell instance.
|
|
|
|
* @param[in] p_data Pointer to the data buffer.
|
2020-12-06 11:22:27 +01:00
|
|
|
* @param[in] len Data buffer size.
|
2018-11-26 17:09:56 +01:00
|
|
|
*/
|
2020-12-06 11:22:27 +01:00
|
|
|
void z_shell_print_stream(const void *user_ctx, const char *data, size_t len);
|
2018-11-26 17:09:56 +01:00
|
|
|
|
2018-12-13 10:26:49 +01:00
|
|
|
/** @internal @brief Function for setting font color */
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_vt100_color_set(const struct shell *sh,
|
2020-12-07 13:22:35 +01:00
|
|
|
enum shell_vt100_color color);
|
2018-12-13 10:26:49 +01:00
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
static inline void z_shell_vt100_colors_store(const struct shell *sh,
|
2020-12-07 13:22:35 +01:00
|
|
|
struct shell_vt100_colors *color)
|
2018-12-13 10:26:49 +01:00
|
|
|
{
|
2021-09-20 14:21:57 +02:00
|
|
|
memcpy(color, &sh->ctx->vt100_ctx.col, sizeof(*color));
|
2018-12-13 10:26:49 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_vt100_colors_restore(const struct shell *sh,
|
2020-12-07 13:22:35 +01:00
|
|
|
const struct shell_vt100_colors *color);
|
2018-12-13 10:26:49 +01:00
|
|
|
|
shell: allow commands to suspend shell thread
It was possible to deadlock the shell when command
suspended shell's thread and next another thread wanted
to print something on the shell.
To avoid that shell releases mutex before entering command
handler. Due to this change some adapations to shell
internal print functions have been applied.
This change addresses following usecase:
1. A command handler needs to call a (system) function which
communicate results via a callback, and this callback is expected
to print these results. The callback is called by the system from
another thread.
2. To achieve that, the handler needs to pass `struct shell *`
to callbacks, but also some other data specific to callback.
Thus, handles allocates some structure will those fields on
the stack.
3. The handler schedules this callback to be called.
4. As a reference to stack structure is passed to the callback,
the handler can't return immediately (or stack data will go out
of scope and will be overwritten).
5. So, the handler blocks waiting for callback to finish.
Previously, this scenario led to deadlock when the callback
trying or print to shell. With these changes, it just works,
as long as main handler and callback serialize there access
to the shell structure (i.e. when callback prints, the main
handler is blocked waiting for its completion).
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-02-12 15:38:16 +01:00
|
|
|
/* This function can be called only within shell thread but not from command
|
|
|
|
* handlers.
|
|
|
|
*/
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_fprintf(const struct shell *sh, enum shell_vt100_color color,
|
2020-12-06 11:22:27 +01:00
|
|
|
const char *fmt, ...);
|
shell: allow commands to suspend shell thread
It was possible to deadlock the shell when command
suspended shell's thread and next another thread wanted
to print something on the shell.
To avoid that shell releases mutex before entering command
handler. Due to this change some adapations to shell
internal print functions have been applied.
This change addresses following usecase:
1. A command handler needs to call a (system) function which
communicate results via a callback, and this callback is expected
to print these results. The callback is called by the system from
another thread.
2. To achieve that, the handler needs to pass `struct shell *`
to callbacks, but also some other data specific to callback.
Thus, handles allocates some structure will those fields on
the stack.
3. The handler schedules this callback to be called.
4. As a reference to stack structure is passed to the callback,
the handler can't return immediately (or stack data will go out
of scope and will be overwritten).
5. So, the handler blocks waiting for callback to finish.
Previously, this scenario led to deadlock when the callback
trying or print to shell. With these changes, it just works,
as long as main handler and callback serialize there access
to the shell structure (i.e. when callback prints, the main
handler is blocked waiting for its completion).
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-02-12 15:38:16 +01:00
|
|
|
|
2021-09-20 14:21:57 +02:00
|
|
|
void z_shell_vfprintf(const struct shell *sh, enum shell_vt100_color color,
|
2020-12-06 11:22:27 +01:00
|
|
|
const char *fmt, va_list args);
|
shell: allow commands to suspend shell thread
It was possible to deadlock the shell when command
suspended shell's thread and next another thread wanted
to print something on the shell.
To avoid that shell releases mutex before entering command
handler. Due to this change some adapations to shell
internal print functions have been applied.
This change addresses following usecase:
1. A command handler needs to call a (system) function which
communicate results via a callback, and this callback is expected
to print these results. The callback is called by the system from
another thread.
2. To achieve that, the handler needs to pass `struct shell *`
to callbacks, but also some other data specific to callback.
Thus, handles allocates some structure will those fields on
the stack.
3. The handler schedules this callback to be called.
4. As a reference to stack structure is passed to the callback,
the handler can't return immediately (or stack data will go out
of scope and will be overwritten).
5. So, the handler blocks waiting for callback to finish.
Previously, this scenario led to deadlock when the callback
trying or print to shell. With these changes, it just works,
as long as main handler and callback serialize there access
to the shell structure (i.e. when callback prints, the main
handler is blocked waiting for its completion).
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-02-12 15:38:16 +01:00
|
|
|
|
2018-08-09 09:56:10 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* SHELL_OPS_H__ */
|