mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 15:38:36 -07:00
Temporarily backport app updates from apps repo
This commit is contained in:
109
applications/external/totp/cli/cli_helpers.h
vendored
109
applications/external/totp/cli/cli_helpers.h
vendored
@@ -1,23 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <cli/cli.h>
|
||||
#include "../types/plugin_state.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TOTP_CLI_COMMAND_NAME "totp"
|
||||
|
||||
#define DOCOPT_ARGUMENT(arg) "<" arg ">"
|
||||
#define DOCOPT_MULTIPLE(arg) arg "..."
|
||||
#define DOCOPT_OPTIONAL(param) "[" param "]"
|
||||
#define DOCOPT_REQUIRED(param) "(" param ")"
|
||||
#define DOCOPT_OPTION(option, value) option " " value
|
||||
#define DOCOPT_SWITCH(option) option
|
||||
#define DOCOPT_OPTIONS "[options]"
|
||||
#define DOCOPT_DEFAULT(val) "[default: " val "]"
|
||||
|
||||
extern const char* TOTP_CLI_COLOR_ERROR;
|
||||
extern const char* TOTP_CLI_COLOR_WARNING;
|
||||
extern const char* TOTP_CLI_COLOR_SUCCESS;
|
||||
extern const char* TOTP_CLI_COLOR_INFO;
|
||||
#define TOTP_CLI_COLOR_ERROR "91m"
|
||||
#define TOTP_CLI_COLOR_WARNING "93m"
|
||||
#define TOTP_CLI_COLOR_SUCCESS "92m"
|
||||
#define TOTP_CLI_COLOR_INFO "96m"
|
||||
|
||||
#define TOTP_CLI_PRINTF(format, ...) printf(format, ##__VA_ARGS__)
|
||||
|
||||
@@ -42,75 +36,30 @@ extern const char* TOTP_CLI_COLOR_INFO;
|
||||
totp_scene_director_activate_scene(plugin_state, __previous_scene); \
|
||||
totp_scene_director_force_redraw(plugin_state)
|
||||
|
||||
/**
|
||||
* @brief Checks whether user is authenticated and entered correct PIN.
|
||||
* If user is not authenticated it prompts user to enter correct PIN to authenticate.
|
||||
* @param plugin_state application state
|
||||
* @param cli pointer to the firmware CLI subsystem
|
||||
* @return \c true if user is already authenticated or successfully authenticated; \c false otherwise
|
||||
*/
|
||||
bool totp_cli_ensure_authenticated(const PluginState* plugin_state, Cli* cli);
|
||||
#define TOTP_CLI_PRINT_INVALID_ARGUMENTS() \
|
||||
TOTP_CLI_PRINTF_ERROR( \
|
||||
"Invalid command arguments. use \"help\" command to get list of available commands")
|
||||
|
||||
/**
|
||||
* @brief Forces application to be instantly closed
|
||||
* @param event_queue main app queue
|
||||
*/
|
||||
void totp_cli_force_close_app(FuriMessageQueue* event_queue);
|
||||
#define TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE() \
|
||||
TOTP_CLI_PRINTF_ERROR("An error has occurred during updating config file\r\n")
|
||||
|
||||
/**
|
||||
* @brief Reads line of characters from console
|
||||
* @param cli pointer to the firmware CLI subsystem
|
||||
* @param out_str pointer to an output string to put read line to
|
||||
* @param mask_user_input whether to mask input characters in console or not
|
||||
* @return \c true if line successfully read and confirmed; \c false otherwise
|
||||
*/
|
||||
bool totp_cli_read_line(Cli* cli, FuriString* out_str, bool mask_user_input);
|
||||
#define TOTP_CLI_PRINT_ERROR_LOADING_TOKEN_INFO() \
|
||||
TOTP_CLI_PRINTF_ERROR("An error has occurred during loading token information\r\n")
|
||||
|
||||
/**
|
||||
* @brief Extracts \c uint8_t value and trims arguments string
|
||||
* @param args arguments string
|
||||
* @param[out] value parsed value
|
||||
* @return \c true if value successfully read and parsed as \c uint8_t ; \c false otherwise
|
||||
*/
|
||||
bool args_read_uint8_and_trim(FuriString* args, uint8_t* value);
|
||||
#define TOTP_CLI_PRINT_PROCESSING() TOTP_CLI_PRINTF("Processing, please wait...\r\n")
|
||||
|
||||
/**
|
||||
* @brief Free \c FuriString instance in a secure manner by clearing it first
|
||||
* @param str instance to free
|
||||
*/
|
||||
void furi_string_secure_free(FuriString* str);
|
||||
#define TOTP_CLI_DELETE_LAST_CHAR() \
|
||||
TOTP_CLI_PRINTF("\b \b"); \
|
||||
fflush(stdout)
|
||||
|
||||
/**
|
||||
* @brief Deletes last printed line in console
|
||||
*/
|
||||
void totp_cli_delete_last_line();
|
||||
#define TOTP_CLI_DELETE_CURRENT_LINE() \
|
||||
TOTP_CLI_PRINTF("\33[2K\r"); \
|
||||
fflush(stdout)
|
||||
|
||||
/**
|
||||
* @brief Deletes current printed line in console
|
||||
*/
|
||||
void totp_cli_delete_current_line();
|
||||
#define TOTP_CLI_DELETE_LAST_LINE() \
|
||||
TOTP_CLI_PRINTF("\033[A\33[2K\r"); \
|
||||
fflush(stdout)
|
||||
|
||||
/**
|
||||
* @brief Deletes last printed char in console
|
||||
*/
|
||||
void totp_cli_delete_last_char();
|
||||
|
||||
/**
|
||||
* @brief Prints error message about invalid command arguments
|
||||
*/
|
||||
void totp_cli_print_invalid_arguments();
|
||||
|
||||
/**
|
||||
* @brief Prints error message about config file update error
|
||||
*/
|
||||
void totp_cli_print_error_updating_config_file();
|
||||
|
||||
/**
|
||||
* @brief Prints error message about config file loading error
|
||||
*/
|
||||
void totp_cli_print_error_loading_token_info();
|
||||
|
||||
/**
|
||||
* @brief Prints message to let user know that command is processing now
|
||||
*/
|
||||
void totp_cli_print_processing();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user