cli_helpers.h 2.4 KB

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