cli_helpers.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_LOCK_UI(plugin_state) \
  23. Scene __previous_scene = plugin_state->current_scene; \
  24. totp_scene_director_activate_scene(plugin_state, TotpSceneStandby); \
  25. totp_scene_director_force_redraw(plugin_state)
  26. #define TOTP_CLI_UNLOCK_UI(plugin_state) \
  27. totp_scene_director_activate_scene(plugin_state, __previous_scene); \
  28. totp_scene_director_force_redraw(plugin_state)
  29. #define TOTP_CLI_PRINT_INVALID_ARGUMENTS() \
  30. TOTP_CLI_PRINTF_ERROR( \
  31. "Invalid command arguments. use \"help\" command to get list of available commands")
  32. #define TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE() \
  33. TOTP_CLI_PRINTF_ERROR("An error has occurred during updating config file\r\n")
  34. #define TOTP_CLI_PRINT_ERROR_LOADING_TOKEN_INFO() \
  35. TOTP_CLI_PRINTF_ERROR("An error has occurred during loading token information\r\n")
  36. #define TOTP_CLI_PRINT_PROCESSING() TOTP_CLI_PRINTF("Processing, please wait...\r\n")
  37. #define TOTP_CLI_DELETE_LAST_CHAR() \
  38. TOTP_CLI_PRINTF("\b \b"); \
  39. fflush(stdout)
  40. #define TOTP_CLI_DELETE_CURRENT_LINE() \
  41. TOTP_CLI_PRINTF("\33[2K\r"); \
  42. fflush(stdout)
  43. #define TOTP_CLI_DELETE_LAST_LINE() \
  44. TOTP_CLI_PRINTF("\033[A\33[2K\r"); \
  45. fflush(stdout)
  46. #ifdef __cplusplus
  47. }
  48. #endif