terminal.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #include "vfs.h"
  6. #define CURSOR_MS 500
  7. #define LINE_MAX 64
  8. #define HISTORY_SIZE 32
  9. #define KEY_BUF_SIZE 16
  10. struct term {
  11. struct text_screen screen;
  12. char history[HISTORY_SIZE][LINE_MAX];
  13. unsigned int history_count;
  14. unsigned int history_next;
  15. char line[LINE_MAX];
  16. unsigned int line_len;
  17. unsigned int line_pos;
  18. unsigned int line_start;
  19. unsigned int history_browse;
  20. char cwd[VFS_PATH_MAX]; /* absolute current working directory */
  21. /* Per-terminal key queue: WM (slot 0) pushes, terminal process pops. */
  22. int keys[KEY_BUF_SIZE];
  23. unsigned int key_head;
  24. unsigned int key_tail;
  25. };
  26. /* Entry point for a terminal process (arg = struct term *). */
  27. void term_entry(void *arg);
  28. void term_run(struct term *t);
  29. /* Single-producer (WM) / single-consumer (terminal) key queue. */
  30. static inline void term_key_push(struct term *t, int k)
  31. {
  32. unsigned int next = (t->key_head + 1) % KEY_BUF_SIZE;
  33. if (next != t->key_tail) {
  34. t->keys[t->key_head] = k;
  35. t->key_head = next;
  36. }
  37. }
  38. static inline int term_key_pop(struct term *t)
  39. {
  40. int k;
  41. if (t->key_tail == t->key_head)
  42. return 0;
  43. k = t->keys[t->key_tail];
  44. t->key_tail = (t->key_tail + 1) % KEY_BUF_SIZE;
  45. return k;
  46. }
  47. #endif