File syn_cli.h¶
Go to the documentation of this file
#ifndef SYN_CLI_H
#define SYN_CLI_H
#include "../common/syn_defs.h"
#include "../port/syn_port_serial.h"
#include <stdbool.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ── Configuration ──────────────────────────────────────────────────────── */
#ifndef SYN_CLI_LINE_BUF_SIZE
#define SYN_CLI_LINE_BUF_SIZE 128
#endif
#ifndef SYN_CLI_MAX_ARGS
#define SYN_CLI_MAX_ARGS 16
#endif
#ifndef SYN_CLI_HISTORY_DEPTH
#define SYN_CLI_HISTORY_DEPTH 0
#endif
/* ── Types ──────────────────────────────────────────────────────────────── */
typedef int (*SYN_CLI_Handler)(int argc, char *argv[]);
typedef struct {
const char *name;
const char *help;
SYN_CLI_Handler handler;
} SYN_CLI_Command;
typedef struct {
/* Command table */
const SYN_CLI_Command *commands;
size_t command_count;
/* Line buffer */
char line_buf[SYN_CLI_LINE_BUF_SIZE];
size_t line_pos;
/* Configuration */
const char *prompt;
bool echo;
bool prompt_visible;
uint8_t escape_state;
/* History */
#if SYN_CLI_HISTORY_DEPTH > 0
char history[SYN_CLI_HISTORY_DEPTH][SYN_CLI_LINE_BUF_SIZE];
size_t history_count;
size_t history_write;
size_t history_read;
#endif
} SYN_CLI;
/* ── API ────────────────────────────────────────────────────────────────── */
void syn_cli_init(SYN_CLI *cli, const SYN_CLI_Command *commands, size_t cmd_count,
const char *prompt);
void syn_cli_set_echo(SYN_CLI *cli, bool echo);
void syn_cli_process_char(SYN_CLI *cli, char ch);
void syn_cli_process_line(SYN_CLI *cli, const char *line);
void syn_cli_print_prompt(SYN_CLI *cli);
void syn_cli_refresh_prompt(SYN_CLI *cli);
void syn_cli_printf(SYN_CLI *cli, const char *fmt, ...);
/* ── Built-in commands ──────────────────────────────────────────────────── */
#ifndef SYN_CLI_CMD_VERSION
#define SYN_CLI_CMD_VERSION 1
#endif
#ifndef SYN_CLI_CMD_UPTIME
#define SYN_CLI_CMD_UPTIME 1
#endif
#ifndef SYN_CLI_CMD_ERRORS
#define SYN_CLI_CMD_ERRORS 1
#endif
#ifndef SYN_CLI_CMD_TASKS
#define SYN_CLI_CMD_TASKS 1
#endif
struct SYN_ErrLog;
struct SYN_Sched;
#if SYN_CLI_CMD_ERRORS
void syn_cli_set_errlog(struct SYN_ErrLog *errlog);
#endif
#if SYN_CLI_CMD_TASKS
void syn_cli_set_scheduler(struct SYN_Sched *sched);
#endif
#ifdef __cplusplus
}
#endif
#endif /* SYN_CLI_H */