private.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. // Tinyrl
  30. bool_t tinyrl_extend_line(tinyrl_t *tinyrl, size_t len);
  31. bool_t tinyrl_esc_seq(tinyrl_t *tinyrl, const char *esc_seq);
  32. typedef struct line_s {
  33. char *str;
  34. size_t size; // Size of buffer
  35. size_t len; // Length of string
  36. off_t pos;
  37. } line_t;
  38. #define NUM_HANDLERS 256
  39. struct tinyrl_s {
  40. tinyrl_key_func_t *handlers[NUM_HANDLERS]; // Handlers for pressed keys
  41. tinyrl_key_func_t *hotkey_fn; // Handler for non-standard hotkeys
  42. hist_t *hist; // History object
  43. vt100_t *term; // VT100 terminal object
  44. struct termios default_termios; // Saved terminal settings
  45. unsigned int width; // Terminal width
  46. bool_t utf8; // Is encoding UTF-8 flag. Default is UTF-8
  47. line_t line; // Current line
  48. // Input processing vars. Input is processed char by char so
  49. // the current state of processing is necessary.
  50. size_t utf8_cont; // Number of UTF-8 continue bytes left
  51. bool_t esc_cont; // Does escape sequence continue
  52. char esc_seq[10]; // Current ESC sequence (line doesn't contain it)
  53. char *esc_p; // Pointer for unfinished ESC sequence
  54. unsigned max_line_length;
  55. char *prompt;
  56. size_t prompt_size; /* strlen() */
  57. size_t prompt_len; /* Symbol positions */
  58. char *buffer;
  59. size_t buffer_size;
  60. bool_t done;
  61. bool_t completion_over;
  62. bool_t completion_error_over;
  63. tinyrl_completion_func_t *attempted_completion_function;
  64. int state;
  65. #define RL_STATE_COMPLETING (0x00000001)
  66. char *kill_string;
  67. void *context; /* context supplied by caller
  68. * to tinyrl_readline()
  69. */
  70. char echo_char;
  71. bool_t echo_enabled;
  72. char *last_buffer; /* hold record of the previous
  73. buffer for redisplay purposes */
  74. unsigned int last_point; /* hold record of the previous
  75. cursor position for redisplay purposes */
  76. unsigned int last_line_size; /* The length of last_buffer */
  77. };