term.h 902 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef __TERM_H
  2. #define __TERM_H
  3. #include <stdint.h>
  4. #define TERM_MAX_PARAMS 2
  5. enum term_state {
  6. TERM_STATE_GROUND,
  7. TERM_STATE_ESC,
  8. TERM_STATE_ESC_INTERMEDIATE,
  9. TERM_STATE_CSI_ENTRY,
  10. TERM_STATE_CSI_PARAM,
  11. TERM_STATE_CSI_INTERMEDIATE,
  12. TERM_STATE_CSI_IGNORE,
  13. };
  14. struct term_cursor {
  15. int x;
  16. int y;
  17. };
  18. struct sgr_attrs {
  19. int normal;
  20. uint8_t bg;
  21. uint8_t fg;
  22. int bold;
  23. };
  24. struct cell {
  25. // No unicode support >:(
  26. char c;
  27. struct sgr_attrs sgra;
  28. };
  29. struct row {
  30. struct cell *cells;
  31. };
  32. struct term {
  33. enum term_state state;
  34. int num_rows;
  35. int num_cols;
  36. int params[TERM_MAX_PARAMS];
  37. int param_idx;
  38. struct term_cursor cursor;
  39. struct row *rows;
  40. struct sgr_attrs sgra;
  41. int pango;
  42. };
  43. void term_init(struct term *t, int rows, int cols, int pango);
  44. void term_put(struct term *t, char c);
  45. void term_put_string(struct term *t, char *str);
  46. char *term_to_string(struct term *t);
  47. #endif