mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-20 04:54:45 -07:00
This reverts commit 0f831412fa.
This was reverted by OFW right after it was made, back in October 2024.
They are now getting back to implementing these features differently.
Thus, a revert is in order. But neofetch is staying :)
111 lines
3.2 KiB
C
111 lines
3.2 KiB
C
/**
|
|
* @file cli.h
|
|
* API for registering commands with the CLI
|
|
*/
|
|
|
|
#pragma once
|
|
#include <furi.h>
|
|
#include <m-array.h>
|
|
#include "cli_ansi.h"
|
|
#include <toolbox/pipe.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define RECORD_CLI "cli"
|
|
|
|
typedef enum {
|
|
CliCommandFlagDefault = 0, /**< Default */
|
|
CliCommandFlagParallelSafe = (1 << 0), /**< Safe to run in parallel with other apps */
|
|
CliCommandFlagInsomniaSafe = (1 << 1), /**< Safe to run with insomnia mode on */
|
|
CliCommandFlagDontAttachStdio = (1 << 2), /**< Do no attach I/O pipe to thread stdio */
|
|
} CliCommandFlag;
|
|
|
|
/** Cli type anonymous structure */
|
|
typedef struct Cli Cli;
|
|
|
|
/**
|
|
* @brief CLI execution callback pointer. Implement this interface and use
|
|
* `add_cli_command`.
|
|
*
|
|
* This callback will be called from a separate thread spawned just for your
|
|
* command. The pipe will be installed as the thread's stdio, so you can use
|
|
* `printf`, `getchar` and other standard functions to communicate with the
|
|
* user.
|
|
*
|
|
* @param [in] pipe Pipe that can be used to send and receive data. If
|
|
* `CliCommandFlagDontAttachStdio` was not set, you can
|
|
* also use standard C functions (printf, getc, etc.) to
|
|
* access this pipe.
|
|
* @param [in] args String with what was passed after the command
|
|
* @param [in] context Whatever you provided to `cli_add_command`
|
|
*/
|
|
typedef void (*CliExecuteCallback)(PipeSide* pipe, FuriString* args, void* context);
|
|
|
|
/**
|
|
* @brief Registers a command with the CLI. Provides less options than the `_ex`
|
|
* counterpart.
|
|
*
|
|
* @param [in] cli Pointer to CLI instance
|
|
* @param [in] name Command name
|
|
* @param [in] flags CliCommandFlag
|
|
* @param [in] callback Callback function
|
|
* @param [in] context Custom context
|
|
*/
|
|
void cli_add_command(
|
|
Cli* cli,
|
|
const char* name,
|
|
CliCommandFlag flags,
|
|
CliExecuteCallback callback,
|
|
void* context);
|
|
|
|
/**
|
|
* @brief Registers a command with the CLI. Provides more options than the
|
|
* non-`_ex` counterpart.
|
|
*
|
|
* @param [in] cli Pointer to CLI instance
|
|
* @param [in] name Command name
|
|
* @param [in] flags CliCommandFlag
|
|
* @param [in] callback Callback function
|
|
* @param [in] context Custom context
|
|
* @param [in] stack_size Thread stack size
|
|
*/
|
|
void cli_add_command_ex(
|
|
Cli* cli,
|
|
const char* name,
|
|
CliCommandFlag flags,
|
|
CliExecuteCallback callback,
|
|
void* context,
|
|
size_t stack_size);
|
|
|
|
/**
|
|
* @brief Deletes a cli command
|
|
*
|
|
* @param [in] cli pointer to cli instance
|
|
* @param [in] name command name
|
|
*/
|
|
void cli_delete_command(Cli* cli, const char* name);
|
|
|
|
/**
|
|
* @brief Detects if Ctrl+C has been pressed or session has been terminated
|
|
*
|
|
* @param [in] side Pointer to pipe side given to the command thread
|
|
* @warning This function also assumes that the pipe is installed as the
|
|
* thread's stdio
|
|
* @warning This function will consume 1 byte from the pipe
|
|
*/
|
|
bool cli_is_pipe_broken_or_is_etx_next_char(PipeSide* side);
|
|
|
|
/** Print unified cmd usage tip
|
|
*
|
|
* @param cmd cmd name
|
|
* @param usage usage tip
|
|
* @param arg arg passed by user
|
|
*/
|
|
void cli_print_usage(const char* cmd, const char* usage, const char* arg);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|