Highlight things
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.6KB

  1. #include "terminal.h"
  2. display_t * cterm = &(display_t) {
  3. .key = "cterm",
  4. .callback = cterm_render_callback
  5. };
  6. void cterm_render_callback(const char * const string,
  7. const int length,
  8. void * const attributes) {
  9. if (!length) {
  10. fputs(TERMINAL_STYLE_BOLD, stdout);
  11. putchar(*string);
  12. fputs(TERMINAL_RESET, stdout);
  13. return;
  14. }
  15. terminal_hl_t * term_hl = (terminal_hl_t*)attributes;
  16. if (term_hl) {
  17. if (term_hl->attribute) {
  18. fputs(term_hl->attribute, stdout);
  19. }
  20. if (term_hl->foreground_color) {
  21. fputs(term_hl->foreground_color, stdout);
  22. }
  23. }
  24. for (int i = 0; i < length; i++) {
  25. putchar(*(string+i));
  26. }
  27. fputs(TERMINAL_RESET, stdout);
  28. }
  29. void fun(const char * attribute,
  30. const char * color,
  31. hl_group_t * * group){
  32. terminal_hl_t * t = (terminal_hl_t *) malloc(sizeof(terminal_hl_t));
  33. t->attribute = attribute;
  34. t->foreground_color = color;
  35. t->background_color = NULL;
  36. (*group) = (hl_group_t *)malloc(sizeof(hl_group_t));
  37. (*group)->link = NULL;
  38. (*group)->attributes = (void*)t;
  39. }
  40. int terminal_hl_init(void) {
  41. hl_init();
  42. new_display_mode(cterm);
  43. //
  44. fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_CYAN, &special_hl);
  45. fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_YELLOW, &control_hl);
  46. fun(NULL, TERMINAL_COLOR_FG_YELLOW, &operator_hl);
  47. fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_GREEN, &keyword_hl);
  48. fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_BLUE, &comment_hl);
  49. fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_RED, &string_literal_hl);
  50. return 0;
  51. }