libhl/source/terminal_hl.h

64 lines
2.0 KiB
C
Raw Normal View History

2023-08-23 21:47:09 -04:00
#include "hl.h"
2023-08-23 21:37:40 -04:00
typedef struct {
char * attribute;
char * foreground_color;
char * background_color;
} terminal_hl_t;
void cterm_render_callback(const char * const string,
const int length,
void * const attributes) {
if(!length){
fputs(TERMINAL_STYLE_BOLD, stdout);
putchar(*string);
fputs(TERMINAL_RESET, stdout);
return;
}
terminal_hl_t * term_hl = (terminal_hl_t*)attributes;
fputs(term_hl->attribute, stdout);
fputs(term_hl->foreground_color, stdout);
for (int i = 0; i < length; i++) {
putchar(*(string+i));
}
fputs(TERMINAL_RESET, stdout);
}
display_t * cterm = &(display_t) {
.key = "cterm",
.callback = cterm_render_callback
};
int terminal_hl_init(void){
hl_init();
new_display_mode(cterm);
//
2023-08-24 15:08:03 -04:00
terminal_hl_t * terminal_keyword_hl = (terminal_hl_t *)malloc(sizeof(terminal_hl_t));
terminal_keyword_hl->attribute = TERMINAL_STYLE_BOLD;
terminal_keyword_hl->foreground_color = TERMINAL_COLOR_FG_GREEN;;
terminal_keyword_hl->background_color = NULL;
keyword_hl = (hl_group_t *)malloc(sizeof(hl_group_t));
keyword_hl->link = NULL;
keyword_hl->attributes = (void*)terminal_keyword_hl;
2023-08-23 21:37:40 -04:00
//
2023-08-24 15:08:03 -04:00
terminal_hl_t * terminal_preprocessor_hl = (terminal_hl_t *)malloc(sizeof(terminal_hl_t));
2023-08-25 13:44:07 -04:00
terminal_preprocessor_hl->attribute = TERMINAL_STYLE_BOLD;
2023-08-24 15:08:03 -04:00
terminal_preprocessor_hl->foreground_color = TERMINAL_COLOR_FG_BLUE;
terminal_preprocessor_hl->background_color = NULL;
preprocessor_hl = (hl_group_t *)malloc(sizeof(hl_group_t));
preprocessor_hl->link = NULL;
preprocessor_hl->attributes = (void*)terminal_keyword_hl;
2023-08-23 21:37:40 -04:00
//
2023-08-24 15:08:03 -04:00
terminal_hl_t * terminal_symbol_hl = (terminal_hl_t *)malloc(sizeof(terminal_hl_t));
terminal_symbol_hl->attribute = TERMINAL_STYLE_BOLD;
terminal_symbol_hl->foreground_color = TERMINAL_COLOR_FG_YELLOW;
terminal_symbol_hl->background_color = NULL;
symbol_hl = (hl_group_t *)malloc(sizeof(hl_group_t));
symbol_hl->link = NULL;
symbol_hl->attributes = (void*)terminal_symbol_hl;
2023-08-23 21:37:40 -04:00
return 0;
}