cli_helpers.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include <stdio.h>
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #define TOTP_CLI_COMMAND_NAME "totp"
  7. #define TOTP_CLI_COLOR_ERROR "91m"
  8. #define TOTP_CLI_COLOR_WARNING "93m"
  9. #define TOTP_CLI_COLOR_SUCCESS "92m"
  10. #define TOTP_CLI_COLOR_INFO "96m"
  11. #define TOTP_CLI_PRINTF(format, ...) printf(format, ##__VA_ARGS__)
  12. #define TOTP_CLI_PRINTF_COLORFUL(color, format, ...) \
  13. TOTP_CLI_PRINTF("\e[%s" format "\e[0m", color, ##__VA_ARGS__)
  14. #define TOTP_CLI_PRINTF_ERROR(format, ...) \
  15. TOTP_CLI_PRINTF_COLORFUL(TOTP_CLI_COLOR_ERROR, format, ##__VA_ARGS__)
  16. #define TOTP_CLI_PRINTF_WARNING(format, ...) \
  17. TOTP_CLI_PRINTF_COLORFUL(TOTP_CLI_COLOR_WARNING, format, ##__VA_ARGS__)
  18. #define TOTP_CLI_PRINTF_SUCCESS(format, ...) \
  19. TOTP_CLI_PRINTF_COLORFUL(TOTP_CLI_COLOR_SUCCESS, format, ##__VA_ARGS__)
  20. #define TOTP_CLI_PRINTF_INFO(format, ...) \
  21. TOTP_CLI_PRINTF_COLORFUL(TOTP_CLI_COLOR_INFO, format, ##__VA_ARGS__)
  22. #define TOTP_CLI_NL() TOTP_CLI_PRINTF("\r\n")
  23. #define TOTP_CLI_LOCK_UI(plugin_state) \
  24. Scene __previous_scene = plugin_state->current_scene; \
  25. totp_scene_director_activate_scene(plugin_state, TotpSceneStandby); \
  26. totp_scene_director_force_redraw(plugin_state)
  27. #define TOTP_CLI_UNLOCK_UI(plugin_state) \
  28. totp_scene_director_activate_scene(plugin_state, __previous_scene); \
  29. totp_scene_director_force_redraw(plugin_state)
  30. #define TOTP_CLI_PRINT_INVALID_ARGUMENTS() \
  31. TOTP_CLI_PRINTF_ERROR( \
  32. "Invalid command arguments. use \"help\" command to get list of available commands")
  33. #define TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE() \
  34. TOTP_CLI_PRINTF_ERROR("An error has occurred during updating config file\r\n")
  35. #define TOTP_CLI_PRINT_ERROR_LOADING_TOKEN_INFO() \
  36. TOTP_CLI_PRINTF_ERROR("An error has occurred during loading token information\r\n")
  37. #define TOTP_CLI_PRINT_PROCESSING() TOTP_CLI_PRINTF("Processing, please wait...\r\n")
  38. #define TOTP_CLI_DELETE_LAST_CHAR() \
  39. TOTP_CLI_PRINTF("\b \b"); \
  40. fflush(stdout)
  41. #define TOTP_CLI_DELETE_CURRENT_LINE() \
  42. TOTP_CLI_PRINTF("\33[2K\r"); \
  43. fflush(stdout)
  44. #define TOTP_CLI_DELETE_LAST_LINE() \
  45. TOTP_CLI_PRINTF("\033[A\33[2K\r"); \
  46. fflush(stdout)
  47. #ifdef __cplusplus
  48. }
  49. #endif