2023-08-29 13:09:55 -04:00
|
|
|
#include "terminal.h"
|
2023-08-27 18:49:36 -04:00
|
|
|
|
|
|
|
display_t * cterm = &(display_t) {
|
|
|
|
.key = "cterm",
|
|
|
|
.callback = cterm_render_callback
|
|
|
|
};
|
|
|
|
|
2023-08-23 21:37:40 -04:00
|
|
|
void cterm_render_callback(const char * const string,
|
|
|
|
const int length,
|
|
|
|
void * const attributes) {
|
2023-08-28 18:19:40 -04:00
|
|
|
if (!length) {
|
2023-08-23 21:37:40 -04:00
|
|
|
fputs(TERMINAL_STYLE_BOLD, stdout);
|
|
|
|
putchar(*string);
|
|
|
|
fputs(TERMINAL_RESET, stdout);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
terminal_hl_t * term_hl = (terminal_hl_t*)attributes;
|
2023-09-20 16:43:12 -04:00
|
|
|
if (term_hl) {
|
|
|
|
if (term_hl->attribute) {
|
|
|
|
fputs(term_hl->attribute, stdout);
|
|
|
|
}
|
|
|
|
if (term_hl->foreground_color) {
|
|
|
|
fputs(term_hl->foreground_color, stdout);
|
|
|
|
}
|
2023-08-28 09:40:36 -04:00
|
|
|
}
|
2023-08-23 21:37:40 -04:00
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
putchar(*(string+i));
|
|
|
|
}
|
|
|
|
fputs(TERMINAL_RESET, stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-28 18:19:40 -04:00
|
|
|
void fun(const char * attribute,
|
|
|
|
const char * color,
|
|
|
|
hl_group_t * * group){
|
|
|
|
terminal_hl_t * t = (terminal_hl_t *) malloc(sizeof(terminal_hl_t));
|
|
|
|
t->attribute = attribute;
|
|
|
|
t->foreground_color = color;
|
|
|
|
t->background_color = NULL;
|
2023-08-28 09:40:36 -04:00
|
|
|
(*group) = (hl_group_t *)malloc(sizeof(hl_group_t));
|
2023-08-28 18:19:40 -04:00
|
|
|
(*group)->link = NULL;
|
|
|
|
(*group)->attributes = (void*)t;
|
2023-08-28 09:40:36 -04:00
|
|
|
}
|
2023-08-23 21:37:40 -04:00
|
|
|
|
2023-08-27 18:49:36 -04:00
|
|
|
int terminal_hl_init(void) {
|
2023-08-23 21:37:40 -04:00
|
|
|
hl_init();
|
|
|
|
new_display_mode(cterm);
|
|
|
|
//
|
2023-08-28 09:40:36 -04:00
|
|
|
fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_CYAN, &special_hl);
|
|
|
|
fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_YELLOW, &control_hl);
|
|
|
|
fun(NULL, TERMINAL_COLOR_FG_YELLOW, &operator_hl);
|
|
|
|
fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_GREEN, &keyword_hl);
|
|
|
|
fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_BLUE, &comment_hl);
|
|
|
|
fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_RED, &string_literal_hl);
|
2023-08-23 21:37:40 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|