microrl.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #ifndef _MICRORL_H_
  2. #define _MICRORL_H_
  3. #include "MicroRLConfig.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #define true 1
  8. #define false 0
  9. /* define the Key codes */
  10. #define KEY_NUL 0 /**< ^@ Null character */
  11. #define KEY_SOH 1 /**< ^A Start of heading, = console interrupt */
  12. #define KEY_STX 2 /**< ^B Start of text, maintenance mode on HP console */
  13. #define KEY_ETX 3 /**< ^C End of text */
  14. #define KEY_EOT 4 /**< ^D End of transmission, not the same as ETB */
  15. #define KEY_ENQ 5 /**< ^E Enquiry, goes with ACK; old HP flow control */
  16. #define KEY_ACK 6 /**< ^F Acknowledge, clears ENQ logon hand */
  17. #define KEY_BEL 7 /**< ^G Bell, rings the bell... */
  18. #define KEY_BS 8 /**< ^H Backspace, works on HP terminals/computers */
  19. #define KEY_HT 9 /**< ^I Horizontal tab, move to next tab stop */
  20. #define KEY_LF 10 /**< ^J Line Feed */
  21. #define KEY_VT 11 /**< ^K Vertical tab */
  22. #define KEY_FF 12 /**< ^L Form Feed, page eject */
  23. #define KEY_CR 13 /**< ^M Carriage Return*/
  24. #define KEY_SO 14 /**< ^N Shift Out, alternate character set */
  25. #define KEY_SI 15 /**< ^O Shift In, resume defaultn character set */
  26. #define KEY_DLE 16 /**< ^P Data link escape */
  27. #define KEY_DC1 17 /**< ^Q XON, with XOFF to pause listings; "okay to send". */
  28. #define KEY_DC2 18 /**< ^R Device control 2, block-mode flow control */
  29. #define KEY_DC3 19 /**< ^S XOFF, with XON is TERM=18 flow control */
  30. #define KEY_DC4 20 /**< ^T Device control 4 */
  31. #define KEY_NAK 21 /**< ^U Negative acknowledge */
  32. #define KEY_SYN 22 /**< ^V Synchronous idle */
  33. #define KEY_ETB 23 /**< ^W End transmission block, not the same as EOT */
  34. #define KEY_CAN 24 /**< ^X Cancel line, MPE echoes !!! */
  35. #define KEY_EM 25 /**< ^Y End of medium, Control-Y interrupt */
  36. #define KEY_SUB 26 /**< ^Z Substitute */
  37. #define KEY_ESC 27 /**< ^[ Escape, next character is not echoed */
  38. #define KEY_FS 28 /**< ^\ File separator */
  39. #define KEY_GS 29 /**< ^] Group separator */
  40. #define KEY_RS 30 /**< ^^ Record separator, block-mode terminator */
  41. #define KEY_US 31 /**< ^_ Unit separator */
  42. #define KEY_DEL 127 /**< Delete (not a real control character...) */
  43. #define IS_CONTROL_CHAR(x) ((x)<=31)
  44. // direction of history navigation
  45. #define _HIST_UP 0
  46. #define _HIST_DOWN 1
  47. // esc seq internal codes
  48. #define _ESC_BRACKET 1
  49. #define _ESC_HOME 2
  50. #define _ESC_END 3
  51. #ifdef _USE_HISTORY
  52. // history struct, contain internal variable
  53. // history store in static ring buffer for memory saving
  54. typedef struct {
  55. char ring_buf [_RING_HISTORY_LEN];
  56. int begin;
  57. int end;
  58. int cur;
  59. } ring_history_t;
  60. #endif
  61. // microrl struct, contain internal library data
  62. typedef struct {
  63. #ifdef _USE_ESC_SEQ
  64. char escape_seq;
  65. char escape;
  66. #endif
  67. #if (defined(_ENDL_CRLF) || defined(_ENDL_LFCR))
  68. char tmpch;
  69. #endif
  70. #ifdef _USE_HISTORY
  71. ring_history_t ring_hist; // history object
  72. #endif
  73. char * prompt_str; // pointer to prompt string
  74. char cmdline [_COMMAND_LINE_LEN]; // cmdline buffer
  75. int cmdlen; // last position in command line
  76. int cursor; // input cursor
  77. int (*execute) (int argc, const char * const * argv ); // ptr to 'execute' callback
  78. char ** (*get_completion) (int argc, const char * const * argv ); // ptr to 'completion' callback
  79. void (*print) (const char *); // ptr to 'print' callback
  80. #ifdef _USE_CTLR_C
  81. void (*sigint) (void);
  82. #endif
  83. } microrl_t;
  84. // init internal data, calls once at start up
  85. void microrl_init (microrl_t * pThis, void (*print)(const char*));
  86. // set echo mode (true/false), using for disabling echo for password input
  87. // echo mode will enabled after user press Enter.
  88. void microrl_set_echo (int);
  89. // set pointer to callback complition func, that called when user press 'Tab'
  90. // callback func description:
  91. // param: argc - argument count, argv - pointer array to token string
  92. // must return NULL-terminated string, contain complite variant splitted by 'Whitespace'
  93. // If complite token found, it's must contain only one token to be complitted
  94. // Empty string if complite not found, and multiple string if there are some token
  95. void microrl_set_complete_callback (microrl_t * pThis, char ** (*get_completion)(int, const char* const*));
  96. // pointer to callback func, that called when user press 'Enter'
  97. // execute func param: argc - argument count, argv - pointer array to token string
  98. void microrl_set_execute_callback (microrl_t * pThis, int (*execute)(int, const char* const*));
  99. // set callback for Ctrl+C terminal signal
  100. #ifdef _USE_CTLR_C
  101. void microrl_set_sigint_callback (microrl_t * pThis, void (*sigintf)(void));
  102. #endif
  103. // insert char to cmdline (for example call in usart RX interrupt)
  104. void microrl_insert_char (microrl_t * pThis, int ch);
  105. #ifdef __cplusplus
  106. }
  107. #endif
  108. #endif