cli_helpers.h 2.3 KB

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