tRemove supposed clear screen and store hl address in local variable - ve - a minimal text editor (work in progress)
 (HTM) git clone git://src.adamsgaard.dk/ve
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit aa2240b83487b25ae3ccdddd7120209fbd6d1f89
 (DIR) parent c3288feb03125b18f98b46cd0d82f9ff5ced5182
 (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
       Date:   Fri,  9 Aug 2019 20:52:27 +0200
       
       Remove supposed clear screen and store hl address in local variable
       
       Diffstat:
         M README                              |       4 ++--
         M config.def.h                        |       6 +++---
         M ve.c                                |      31 +++++++++++++++++++++++--------
       
       3 files changed, 28 insertions(+), 13 deletions(-)
       ---
 (DIR) diff --git a/README b/README
       t@@ -12,8 +12,8 @@ editor was originally inspired by antirez/kilo and snaptoken/kilo.
        
        Build requirements:
                - make
       -        - C99 compiler (gcc, clang)
       -        - glibc or musl (others might work too)
       +        - C compiler (C99, tested on gcc, clang)
       +        - libc (tested with glibc, musl)
        
        Install instructions:
                $ make
 (DIR) diff --git a/config.def.h b/config.def.h
       t@@ -19,7 +19,7 @@ static int status_message_timeout = 3;
        static const int colors[][3] = {
                /*                  fg   bg   style  */
                [ColorNormal]   = {  0,   0,     0 },
       -        [ColorDigits]   = {  1,   0,     0 },
       -        [ColorComments] = {  2,   0,     0 },
       -        [ColorKeywords] = {  3,   0,     0 },
       +        [ColorDigit]    = {  1,   0,     0 },
       +        [ColorComment]  = {  2,   0,     0 },
       +        [ColorKeyword]  = {  3,   0,     0 },
        };
        \ No newline at end of file
 (DIR) diff --git a/ve.c b/ve.c
       t@@ -54,7 +54,7 @@ struct editor_config {
        };
        
        /* color scheme types */
       -enum { ColorNormal, ColorDigits, ColorComments, ColorKeywords };
       +enum { ColorNormal, ColorDigit, ColorComment, ColorKeyword };
        enum { FG, BG, STYLE };
        
        /* configuration, allows nested code to access above variables */
       t@@ -173,6 +173,21 @@ get_window_size(int *rows, int *cols)
        
        /** SYNTAX HIGHLIGHTING **/
        
       +void
       +editor_update_syntax(eRow *row)
       +{
       +        int i;
       +        row->hl = realloc(row->hl, row->rsize);
       +        memset(row->hl, ColorNormal, row->rsize);
       +        for (i=0; i<row->rsize; ++i) {
       +                if (isdigit(row->rchars[i]))
       +                        row->hl[i] = ColorDigit;
       +        }
       +}
       +
       +
       +/** ROW OPERATIONS **/
       +
        /* navigate over tab-representative string as one character */
        int
        editor_row_cursor_x_to_rx(eRow *row, int cursor_x)
       t@@ -187,9 +202,6 @@ editor_row_cursor_x_to_rx(eRow *row, int cursor_x)
                return rx;
        }
        
       -
       -/** ROW OPERATIONS **/
       -
        /* translate on-screen position to data position */
        int
        editor_row_cursor_rx_to_x(eRow *row, int cursor_rx)
       t@@ -704,9 +716,11 @@ editor_draw_rows(struct abuf *ab)
        {
                int y, j, len, file_row;
                char *c;
       +        unsigned char *hl;
                char buf[16];
                for (y = 0; y < E.screen_rows; ++y) {
                        file_row = y + E.row_offset;
       +                editor_update_syntax(&E.row[file_row]);
                        if (file_row < E.num_rows) {
                                len = E.row[file_row].rsize - E.column_offset;
                                if (len < 0)
       t@@ -715,10 +729,11 @@ editor_draw_rows(struct abuf *ab)
                                        len = E.screen_columns;
                                /* ab_append(ab, &E.row[file_row].rchars[E.column_offset], len); */
                                c = &E.row[file_row].rchars[E.column_offset];
       +                        hl = &E.row[file_row].hl[E.column_offset];
                                for (j = 0; j < len; ++j) {
       -                                if (isdigit(c[j])) {
       +                                if (hl[j] == ColorDigit) {
                                                snprintf(buf, sizeof(buf),
       -                                                 "\x1b[3%dm", colors[ColorDigits][FG]);
       +                                                 "\x1b[3%dm", colors[ColorDigit][FG]); 
                                                ab_append(ab, buf, strlen(buf));
                                                /* ab_append(ab, "\x1b[31m", 5); */
                                                ab_append(ab, &c[j], 1);
       t@@ -920,8 +935,8 @@ editor_process_keypress()
                                                                                              "Press ;q! to confirm quit");
                                                                break;
                                                        } else {
       -                                                        write(STDOUT_FILENO, "\x1b[2J", 4); /* clear screen */
       -                                                        write(STDOUT_FILENO, "\x1b[H", 3);
       +                                                        /*write(STDOUT_FILENO, "\x1b[2J", 4);*/ /* clear screen */
       +                                                        /* write(STDOUT_FILENO, "\x1b[H", 3); */
                                                                exit(0);
                                                                break;
                                                        }