79e6b0e0f6
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>. This patch proposes to then include <zephyr/kernel.h> instead of <zephyr/zephyr.h> since it is more clear that you are including the Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a catch-all header that may be confusing. Most applications need to include a bunch of other things to compile, e.g. driver headers or subsystem headers like BT, logging, etc. The idea of a catch-all header in Zephyr is probably not feasible anyway. Reason is that Zephyr is not a library, like it could be for example `libpython`. Zephyr provides many utilities nowadays: a kernel, drivers, subsystems, etc and things will likely grow. A catch-all header would be massive, difficult to keep up-to-date. It is also likely that an application will only build a small subset. Note that subsystem-level headers may use a catch-all approach to make things easier, though. NOTE: This patch is **NOT** removing the header, just removing its usage in-tree. I'd advocate for its deprecation (add a #warning on it), but I understand many people will have concerns. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
115 lines
2.5 KiB
C
115 lines
2.5 KiB
C
/*
|
|
* Copyright (c) 2018 Nordic Semiconductor ASA
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#ifndef SHELL_HISTORY_H__
|
|
#define SHELL_HISTORY_H__
|
|
|
|
#include <zephyr/kernel.h>
|
|
#include <zephyr/sys/util.h>
|
|
#include <zephyr/sys/dlist.h>
|
|
#include <zephyr/sys/ring_buffer.h>
|
|
#include <stdbool.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
|
|
struct shell_history {
|
|
struct ring_buf *ring_buf;
|
|
sys_dlist_t list;
|
|
sys_dnode_t *current;
|
|
};
|
|
|
|
/**
|
|
* @brief Create shell history instance.
|
|
*
|
|
* @param _name History instance name.
|
|
* @param _size Memory dedicated for shell history.
|
|
*/
|
|
#define Z_SHELL_HISTORY_DEFINE(_name, _size) \
|
|
static uint8_t __noinit __aligned(sizeof(void *)) \
|
|
_name##_ring_buf_data[_size]; \
|
|
static struct ring_buf _name##_ring_buf = \
|
|
{ \
|
|
.size = _size, \
|
|
.buffer = _name##_ring_buf_data \
|
|
}; \
|
|
static struct shell_history _name = { \
|
|
.ring_buf = &_name##_ring_buf \
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Initialize shell history module.
|
|
*
|
|
* @param history Shell history instance.
|
|
*/
|
|
void z_shell_history_init(struct shell_history *history);
|
|
|
|
/**
|
|
* @brief Purge shell history.
|
|
*
|
|
* Function clears whole shell command history.
|
|
*
|
|
* @param history Shell history instance.
|
|
*
|
|
*/
|
|
void z_shell_history_purge(struct shell_history *history);
|
|
|
|
/**
|
|
* @brief Exit history browsing mode.
|
|
*
|
|
* @param history Shell history instance.
|
|
*/
|
|
void z_shell_history_mode_exit(struct shell_history *history);
|
|
|
|
/**
|
|
* @brief Get next entry in shell command history.
|
|
*
|
|
* Function returns next (in given direction) stored line.
|
|
*
|
|
* @param[in] history Shell history instance.
|
|
* @param[in] up Direction.
|
|
* @param[out] dst Buffer where line is copied.
|
|
* @param[in,out] len Buffer size (input), amount of copied
|
|
* data (output).
|
|
* @return True if remains in history mode.
|
|
*/
|
|
bool z_shell_history_get(struct shell_history *history, bool up,
|
|
uint8_t *dst, uint16_t *len);
|
|
|
|
/**
|
|
* @brief Put line into shell command history.
|
|
*
|
|
* If history is full, oldest entry (or entries) is removed.
|
|
*
|
|
* @param history Shell history instance.
|
|
* @param line Data.
|
|
* @param len Data length.
|
|
*
|
|
*/
|
|
void z_shell_history_put(struct shell_history *history, uint8_t *line,
|
|
size_t len);
|
|
|
|
/**
|
|
* @brief Get state of shell history.
|
|
*
|
|
* @param history Shell history instance.
|
|
*
|
|
* @return True if in browsing mode.
|
|
*/
|
|
static inline bool z_shell_history_active(struct shell_history *history)
|
|
{
|
|
return (history->current) ? true : false;
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* SHELL_HISTORY_H__ */
|