]> git.xolatile.top Git - public-libhl.git/commitdiff
new std hi groups; terribly named constructor for them
authoranon <anon@anon.anon>
Mon, 28 Aug 2023 13:40:36 +0000 (15:40 +0200)
committeranon <anon@anon.anon>
Mon, 28 Aug 2023 13:40:36 +0000 (15:40 +0200)
source/hl.h
source/terminal_hl.h

index 462a024e6cdda795e161c2c70b7b6e38b78b81ad..89abe25fba5427a9e11569389e012da7a6635fe2 100644 (file)
@@ -260,9 +260,14 @@ void render_string(const char * const string,
 // -------------------------
 // ### Library Mangement ###
 // -------------------------
-hl_group_t * keyword_hl = NULL;
-hl_group_t * preprocessor_hl = NULL;
-hl_group_t * symbol_hl = NULL;
+hl_group_t * special_hl          = NULL;
+hl_group_t * control_hl          = NULL;
+hl_group_t * keyword_hl          = NULL;
+hl_group_t * block_hl            = NULL;
+hl_group_t * separator_hl        = NULL;
+hl_group_t * operator_hl         = NULL;
+hl_group_t * comment_hl          = NULL;
+hl_group_t * string_literal_hl   = NULL;
 
 int hl_init(void) {
        return 0;
index 83b52df72b19be4e6102043eb98ecabb4ba78081..c71cdaa6c27d0ae77d392db3e472136e9d4c5972 100644 (file)
@@ -17,8 +17,12 @@ void cterm_render_callback(const char * const string,
        }
 
        terminal_hl_t * term_hl = (terminal_hl_t*)attributes;
-       fputs(term_hl->attribute, stdout);
-       fputs(term_hl->foreground_color, stdout);
+       if (term_hl->attribute) {
+               fputs(term_hl->attribute, stdout);
+       }
+       if (term_hl->foreground_color) {
+               fputs(term_hl->foreground_color, stdout);
+       }
        for (int i = 0; i < length; i++) {
                putchar(*(string+i));
        }
@@ -30,34 +34,28 @@ display_t * cterm = &(display_t) {
        .callback = cterm_render_callback
 };
 
+void fun(const char       *   const attribute,
+         const char       *   const     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;
+       (*group) = (hl_group_t *)malloc(sizeof(hl_group_t));
+               (*group)->link = NULL;
+               (*group)->attributes = (void*)t;
+}
 
 int terminal_hl_init(void){
        hl_init();
        new_display_mode(cterm);
        //
-       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;
-       //
-       terminal_hl_t * terminal_preprocessor_hl = (terminal_hl_t *)malloc(sizeof(terminal_hl_t));
-               terminal_preprocessor_hl->attribute = TERMINAL_STYLE_BOLD;
-               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;
-       //
-       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;
+       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);
 
        return 0;
 }