terminal.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Terminal-in-a-window: per-instance state and the prompt/echo loop. */
  2. #ifndef TERMINAL_H
  3. #define TERMINAL_H
  4. #include "screen.h"
  5. #define CURSOR_MS 500
  6. #define LINE_MAX 64
  7. #define HISTORY_SIZE 32
  8. #define KEY_BUF_SIZE 16
  9. struct term {
  10. struct text_screen screen;
  11. char history[HISTORY_SIZE][LINE_MAX];
  12. unsigned int history_count;
  13. unsigned int history_next;
  14. char line[LINE_MAX];
  15. unsigned int line_len;
  16. unsigned int line_pos;
  17. unsigned int line_start;
  18. unsigned int history_browse;
  19. /* Per-terminal key queue: WM (slot 0) pushes, terminal process pops. */
  20. int keys[KEY_BUF_SIZE];
  21. unsigned int key_head;
  22. unsigned int key_tail;
  23. };
  24. /* Entry point for a terminal process (arg = struct term *). */
  25. void term_entry(void *arg);
  26. void term_run(struct term *t);
  27. /* Single-producer (WM) / single-consumer (terminal) key queue. */
  28. static inline void term_key_push(struct term *t, int k)
  29. {
  30. unsigned int next = (t->key_head + 1) % KEY_BUF_SIZE;
  31. if (next != t->key_tail) {
  32. t->keys[t->key_head] = k;
  33. t->key_head = next;
  34. }
  35. }
  36. static inline int term_key_pop(struct term *t)
  37. {
  38. int k;
  39. if (t->key_tail == t->key_head)
  40. return 0;
  41. k = t->keys[t->key_tail];
  42. t->key_tail = (t->key_tail + 1) % KEY_BUF_SIZE;
  43. return k;
  44. }
  45. #endif