From 2c85e017fdc0de8b5ff6ffe139f257c4ea5ab44f Mon Sep 17 00:00:00 2001 From: Charlie Gordon Date: Wed, 21 Oct 2020 09:55:01 +0000 Subject: [PATCH] Improve colorization - add QE_STYLE_BLANK_HILITE style for extra blanks at end of lines - add MODEF_NO_TRAILING_BLANKS flag to control this feature on a mode basis - add -nc (--no-crc) command line option du disable CRC based update cache - add disable-crc global variable for the same purpose - fix termios c_oflag flags in raw mode --- qe.c | 13 ++++++++++++- qe.h | 3 +++ qestyles.h | 2 ++ shell.c | 9 +++++++++ tty.c | 14 +++++++++++--- variables.c | 1 + 6 files changed, 38 insertions(+), 4 deletions(-) diff --git a/qe.c b/qe.c index 4550a53..7a52a9e 100644 --- a/qe.c +++ b/qe.c @@ -71,6 +71,7 @@ static int screen_height = 0; static int no_init_file; static int single_window; int force_tty; +int disable_crc; int use_session_file; int use_html = 1; #ifndef CONFIG_TINY @@ -3440,7 +3441,7 @@ static void flush_line(DisplayState *ds, e->shadow_nb_lines = n; } } - if (ds->line_num < e->shadow_nb_lines) { + if (ds->line_num < e->shadow_nb_lines && !disable_crc) { QELineShadow *ls; uint64_t crc; @@ -4217,6 +4218,14 @@ static int syntax_get_colorized_line(EditState *s, offset = eb_next(b, offset); } } + if (!(s->colorize_mode->flags & MODEF_NO_TRAILING_BLANKS)) { + /* Mark trailing blanks as errors if cursor is not on same line */ + if (!(s->offset >= offset && s->offset < *offsetp)) { + for (i = len; i > 0 && qe_isblank(buf[i - 1]); i--) { + sbuf[i - 1] = QE_STYLE_BLANK_HILITE; + } + } + } return len; } @@ -8925,6 +8934,8 @@ static CmdLineOptionDef cmd_options[] = { CMD_LINE_FVOID("?", "", show_usage, ""), CMD_LINE_BOOL("q", "no-init-file", &no_init_file, "do not load config files"), + CMD_LINE_BOOL("nc", "no-crc", &disable_crc, + "do not use crc based display cacheing"), CMD_LINE_BOOL("1", "single-window", &single_window, "keep a single window when loading multiple files"), CMD_LINE_BOOL("nw", "no-windows", &force_tty, diff --git a/qe.h b/qe.h index 427e2e1..d8aa0f9 100644 --- a/qe.h +++ b/qe.h @@ -1364,6 +1364,8 @@ void eb_delete_properties(EditBuffer *b, int offset, int offset2); /* qe.c */ +extern int disable_crc; /* Prevent CRC based display cacheing */ + /* contains all the information necessary to uniquely identify a line, to avoid displaying it */ typedef struct QELineShadow { @@ -1531,6 +1533,7 @@ struct ModeDef { #define MODEF_DATATYPE 0x10 #define MODEF_SHELLPROC 0x20 #define MODEF_NEWINSTANCE 0x100 +#define MODEF_NO_TRAILING_BLANKS 0x200 int buffer_instance_size; /* size of malloced buffer state */ int window_instance_size; /* size of malloced window state */ diff --git a/qestyles.h b/qestyles.h index 1517824..a0266b8 100644 --- a/qestyles.h +++ b/qestyles.h @@ -57,6 +57,8 @@ QERGB(0x00, 0x00, 0x00), QERGB(0x00, 0x80, 0x80), 0, 0) STYLE_DEF(QE_STYLE_SEARCH_MATCH, "search-match", /* grey88 on #f000f0 */ QERGB(0xe0, 0xe0, 0xe0), QERGB(0xf0, 0x00, 0xf0), 0, 0) + STYLE_DEF(QE_STYLE_BLANK_HILITE, "blank-hilite", /* black on red */ + QERGB(0x00, 0x00, 0x00), QERGB(0xff, 0x00, 0x00), 0, 0) /* HTML coloring styles */ STYLE_DEF(QE_STYLE_HTML_COMMENT, "html-comment", /* #f84400 */ diff --git a/shell.c b/shell.c index e2c3120..5cb959b 100644 --- a/shell.c +++ b/shell.c @@ -3092,6 +3092,14 @@ void shell_colorize_line(QEColorizeContext *cp, cp->colorize_state = 0; m->colorize_func(cp, str + i, n - i, m); cp->combine_stop = i; + if (!(m->flags & MODEF_NO_TRAILING_BLANKS)) { + /* Mark trailing blanks as errors if cursor is not on same line */ + int j; + for (j = n; j > i && qe_isblank(str[j - 1] & CHAR_MASK); j--) { + str[j - 1] &= CHAR_MASK; + SET_COLOR1(str, j - 1, QE_STYLE_BLANK_HILITE); + } + } } cp->colorize_state = 0; } @@ -3212,6 +3220,7 @@ static int shell_init(void) /* populate and register shell mode and commands */ memcpy(&shell_mode, &text_mode, sizeof(ModeDef)); shell_mode.name = "shell"; + shell_mode.flags |= MODEF_NO_TRAILING_BLANKS; shell_mode.mode_probe = shell_mode_probe; shell_mode.colorize_func = shell_colorize_line, shell_mode.buffer_instance_size = sizeof(ShellState); diff --git a/tty.c b/tty.c index b8ef5df..ffd40c6 100644 --- a/tty.c +++ b/tty.c @@ -276,14 +276,22 @@ static int tty_dpy_init(QEditScreen *s, tcgetattr(fileno(s->STDIN), &tty); ts->oldtty = tty; + /* input modes: no break, no CR to NL, no parity check, no strip char, + * no start/stop output control. */ tty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); - tty.c_oflag |= OPOST; + /* output modes - disable post processing */ + tty.c_oflag &= ~(OPOST); + /* local modes - echoing off, canonical off, no extended functions, + * no signal chars (^Z,^C) */ tty.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG); + /* control modes - set 8 bit chars, disable parity handling */ tty.c_cflag &= ~(CSIZE | PARENB); tty.c_cflag |= CS8; - tty.c_cc[VMIN] = 1; - tty.c_cc[VTIME] = 0; + /* control chars - set return condition: min number of bytes and timer. + * We want read to return every single byte, without timeout. */ + tty.c_cc[VMIN] = 1; /* 1 byte */ + tty.c_cc[VTIME] = 0; /* no timer */ tcsetattr(fileno(s->STDIN), TCSANOW, &tty); diff --git a/variables.c b/variables.c index 7e05117..30f2ee2 100644 --- a/variables.c +++ b/variables.c @@ -79,6 +79,7 @@ static VarDef var_table[] = { G_VAR( "use-session-file", use_session_file, VAR_NUMBER, VAR_RW ) G_VAR( "force-tty", force_tty, VAR_NUMBER, VAR_RW ) + G_VAR( "disable-crc", disable_crc, VAR_NUMBER, VAR_RW_SAVE ) G_VAR( "use-html", use_html, VAR_NUMBER, VAR_RW ) /* more buffer fields: modified, readonly, binary, charset */