tsyn: handle non-black terminal forground colour - neatvi - [fork] simple vi-type editor with UTF-8 support
(HTM) git clone git://src.adamsgaard.dk/neatvi
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit e14f2566479bd4cb53821e13d0518b11e4b89b94
(DIR) parent c56b1c07c8afc6c7e7455f32c82c9b1f52ace59e
(HTM) Author: Ali Gholami Rudi <ali@rudi.ir>
Date: Mon, 22 Jun 2015 18:23:24 +0430
syn: handle non-black terminal forground colour
Reported by Dirk-Wilhelm Peters <peters@schwertfisch.de>.
Diffstat:
M syn.c | 7 +++----
M term.c | 18 ++++++++++--------
M vi.h | 17 +++++++++++------
3 files changed, 24 insertions(+), 18 deletions(-)
---
(DIR) diff --git a/syn.c b/syn.c
t@@ -24,10 +24,9 @@ static struct rset *syn_find(char *ft)
int syn_merge(int old, int new)
{
- int fg = SYN_FG(new) ? SYN_FG(new) : SYN_FG(old);
- int bg = SYN_BG(new) ? SYN_BG(new) : SYN_BG(old);
- int flg = (old | new) & (SYN_IT | SYN_BD | SYN_RV);
- return flg | fg | SYN_BGMK(bg);
+ int fg = SYN_FGSET(new) ? SYN_FG(new) : SYN_FG(old);
+ int bg = SYN_BGSET(new) ? SYN_BG(new) : SYN_BG(old);
+ return ((old | new) & SYN_FLG) | (bg << 8) | fg;
}
int *syn_highlight(char *ft, char *s)
(DIR) diff --git a/term.c b/term.c
t@@ -173,17 +173,19 @@ char *term_att(int att, int old)
if (att == old)
return "";
s += sprintf(s, "\33[");
- if (fg & SYN_BD)
+ if (att & SYN_BD)
s += sprintf(s, ";1");
- if (fg & SYN_IT)
+ if (att & SYN_IT)
s += sprintf(s, ";3");
- else if (fg & SYN_RV)
+ else if (att & SYN_RV)
s += sprintf(s, ";7");
- if ((fg & 0xff) < 8)
- s += sprintf(s, ";%d", 30 + (fg & 0xff));
- else
- s += sprintf(s, ";38;5;%d", (fg & 0xff));
- if (bg) {
+ if (SYN_FGSET(att)) {
+ if ((fg & 0xff) < 8)
+ s += sprintf(s, ";%d", 30 + (fg & 0xff));
+ else
+ s += sprintf(s, ";38;5;%d", (fg & 0xff));
+ }
+ if (SYN_BGSET(att)) {
if ((bg & 0xff) < 8)
s += sprintf(s, ";%d", 40 + (bg & 0xff));
else
(DIR) diff --git a/vi.h b/vi.h
t@@ -151,12 +151,17 @@ char *cmd_pipe(char *cmd, char *s, int iproc, int oproc);
int cmd_exec(char *cmd);
/* syntax highlighting */
-#define SYN_BD 0x100
-#define SYN_IT 0x200
-#define SYN_RV 0x400
-#define SYN_BGMK(b) ((b) << 16)
-#define SYN_FG(a) ((a) & 0xffff)
-#define SYN_BG(a) ((a) >> 16)
+#define SYN_BD 0x010000
+#define SYN_IT 0x020000
+#define SYN_RV 0x040000
+#define SYN_FGMK(f) (0x100000 | (f))
+#define SYN_BGMK(b) (0x200000 | ((b) << 8))
+
+#define SYN_FLG 0xff0000
+#define SYN_FGSET(a) ((a) & 0x1000ff)
+#define SYN_BGSET(a) ((a) & 0x20ff00)
+#define SYN_FG(a) ((a) & 0xff)
+#define SYN_BG(a) (((a) >> 8) & 0xff)
int *syn_highlight(char *ft, char *s);
char *syn_filetype(char *path);