microrl.h 4.7 KB

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