private.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include <termios.h>
  2. #include <faux/faux.h>
  3. #include "tinyrl/vt100.h"
  4. #include "tinyrl/hist.h"
  5. #include "tinyrl/tinyrl.h"
  6. // UTF-8 functions
  7. ssize_t utf8_to_wchar(const char *sp, unsigned long *sym_out);
  8. bool_t utf8_wchar_is_cjk(unsigned long sym);
  9. char *utf8_move_left(const char *line, char *cur_pos);
  10. char *utf8_move_right(const char *line, char *cur_pos);
  11. // Keys
  12. bool_t tinyrl_key_default(tinyrl_t * tinyrl, int key);
  13. bool_t tinyrl_key_interrupt(tinyrl_t * tinyrl, int key);
  14. bool_t tinyrl_key_start_of_line(tinyrl_t * tinyrl, int key);
  15. bool_t tinyrl_key_end_of_line(tinyrl_t * tinyrl, int key);
  16. bool_t tinyrl_key_kill(tinyrl_t * tinyrl, int key);
  17. bool_t tinyrl_key_yank(tinyrl_t * tinyrl, int key);
  18. bool_t tinyrl_key_crlf(tinyrl_t * tinyrl, int key);
  19. bool_t tinyrl_key_up(tinyrl_t * tinyrl, int key);
  20. bool_t tinyrl_key_down(tinyrl_t * tinyrl, int key);
  21. bool_t tinyrl_key_left(tinyrl_t * tinyrl, int key);
  22. bool_t tinyrl_key_right(tinyrl_t * tinyrl, int key);
  23. bool_t tinyrl_key_backspace(tinyrl_t *tinyrl, int key);
  24. bool_t tinyrl_key_backword(tinyrl_t *tinyrl, int key);
  25. bool_t tinyrl_key_delete(tinyrl_t * tinyrl, int key);
  26. bool_t tinyrl_key_clear_screen(tinyrl_t * tinyrl, int key);
  27. bool_t tinyrl_key_erase_line(tinyrl_t * tinyrl, int key);
  28. bool_t tinyrl_key_tab(tinyrl_t * tinyrl, int key);
  29. /* define the class member data and virtual methods */
  30. struct _tinyrl {
  31. const char *line;
  32. unsigned max_line_length;
  33. char *prompt;
  34. size_t prompt_size; /* strlen() */
  35. size_t prompt_len; /* Symbol positions */
  36. char *buffer;
  37. size_t buffer_size;
  38. bool_t done;
  39. bool_t completion_over;
  40. bool_t completion_error_over;
  41. unsigned point;
  42. unsigned end;
  43. tinyrl_completion_func_t *attempted_completion_function;
  44. tinyrl_keypress_fn_t *keypress_fn; /* keypress callback */
  45. int state;
  46. #define RL_STATE_COMPLETING (0x00000001)
  47. char *kill_string;
  48. #define NUM_HANDLERS 256
  49. tinyrl_key_func_t *handlers[NUM_HANDLERS];
  50. tinyrl_key_func_t *hotkey_fn;
  51. hist_t *hist; // History object
  52. vt100_t *term;
  53. void *context; /* context supplied by caller
  54. * to tinyrl_readline()
  55. */
  56. char echo_char;
  57. bool_t echo_enabled;
  58. struct termios default_termios;
  59. bool_t isatty;
  60. char *last_buffer; /* hold record of the previous
  61. buffer for redisplay purposes */
  62. unsigned int last_point; /* hold record of the previous
  63. cursor position for redisplay purposes */
  64. unsigned int last_line_size; /* The length of last_buffer */
  65. unsigned int width; /* Last terminal width. For resize */
  66. bool_t utf8; /* Is the encoding UTF-8 */
  67. };