nr_micro_shell.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * *****************************************************************************
  3. * MIT License
  4. *
  5. * Copyright (C) 2025 Ji Youzhou. or its affiliates. All Rights Reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE.
  24. ***********************************************************************************/
  25. #ifndef __NR_MICRO_SHELL_H
  26. #define __NR_MICRO_SHELL_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. #include "nr_micro_shell_port.h"
  31. #define NR_SHELL_VERSION "2.0.0"
  32. /* Default config */
  33. #ifndef NR_SHELL_MAX_LINE_SZ
  34. #define NR_SHELL_MAX_LINE_SZ 80
  35. #endif
  36. #ifndef NR_SHELL_PROMPT
  37. #define NR_SHELL_PROMPT "nr@dev"
  38. #endif
  39. #ifndef NR_SHELL_MAX_PARAM_NUM
  40. #define NR_SHELL_MAX_PARAM_NUM 8
  41. #endif
  42. #ifdef NR_SHELL_HISTORY_CMD_SUPPORT
  43. #ifndef NR_SHELL_HISTORY_CMD_NUM
  44. #define NR_SHELL_HISTORY_CMD_NUM 5
  45. #endif
  46. #ifndef NR_SHELL_HISTORY_CMD_SZ
  47. #define NR_SHELL_HISTORY_CMD_SZ 50
  48. #endif
  49. #endif
  50. struct nr_micro_shell {
  51. uint8_t cursor_pos;
  52. uint8_t rcv_len;
  53. char line[NR_SHELL_MAX_LINE_SZ];
  54. uint8_t state;
  55. #ifdef NR_SHELL_HISTORY_CMD_SUPPORT
  56. char his_cmd[NR_SHELL_HISTORY_CMD_NUM][NR_SHELL_HISTORY_CMD_SZ];
  57. char shadow_line[NR_SHELL_MAX_LINE_SZ];
  58. uint8_t his_cmd_count;
  59. uint8_t his_cmd_request_index;
  60. uint8_t his_cmd_rear;
  61. #endif
  62. };
  63. struct cmd {
  64. char *name;
  65. int (*func)(uint8_t argc, char **argv);
  66. char *desc;
  67. };
  68. extern struct cmd cmd_table[];
  69. extern char *auto_complete_words[];
  70. extern const uint16_t cmd_table_size;
  71. extern const uint16_t auto_complete_words_size;
  72. void shell_printf(const char *fmt, ...);
  73. void shell_init(void);
  74. void shell(char c);
  75. void show_all_cmds(void);
  76. #ifdef __cplusplus
  77. }
  78. #endif
  79. #endif /* __NR_MICRO_SHELL_H */
  80. /******************* (C) COPYRIGHT 2025 Ji Youzhou ****************************/