summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorulwlu <ooulwluoo@gmail.com>2022-08-16 23:37:52 +0200
committerThomas Koutcher <thomas.koutcher@online.fr>2023-09-04 21:36:48 +0200
commitd2b29cd2d424ccdd78ef080bd6b8e184847ce909 (patch)
tree96b0a6fb5f62efd67a3ba3dfda4e6bd72682182e
parentd0f5df28702240c72b84a24e7535c09f2223f7c1 (diff)
Rework after reviewansi-support
-rw-r--r--doc/tigrc.5.adoc2
-rw-r--r--include/tig/line.h2
-rw-r--r--src/ansi.c12
-rw-r--r--src/draw.c12
-rw-r--r--src/line.c4
5 files changed, 22 insertions, 10 deletions
diff --git a/doc/tigrc.5.adoc b/doc/tigrc.5.adoc
index 158ef647..865d3784 100644
--- a/doc/tigrc.5.adoc
+++ b/doc/tigrc.5.adoc
@@ -280,7 +280,7 @@ The following variables can be set:
to false. When set to true then 'diff-highlight' is used, else the option
value is used as the path. When this option is in effect, highlighted
regions are governed by `color diff-add-highlight` and
- `color diff-del-highlight`. git-delta is also supported.
+ `color diff-del-highlight`.
'ignore-space' (mixed) [no|all|some|at-eol|<bool>]::
diff --git a/include/tig/line.h b/include/tig/line.h
index 83941a94..fd5bad17 100644
--- a/include/tig/line.h
+++ b/include/tig/line.h
@@ -17,7 +17,9 @@
#include "tig/tig.h"
struct ref;
+#if defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH >= 20180127
extern short color_pairs_map[257][257];
+#endif
/*
* Line-oriented content detection.
diff --git a/src/ansi.c b/src/ansi.c
index f310791c..1aa17d8c 100644
--- a/src/ansi.c
+++ b/src/ansi.c
@@ -63,9 +63,8 @@ draw_ansi(struct view *view, int *ansi_num, char **ansi_ptrs, int max_width, siz
waddnstr(view->win, text, len);
continue;
}
- // delta won't add moving ansi codes which are
- // A, B, C, D, E, F, G, H, f, S, T.
- // J, K exists for filling lines with a color, but ncurses can't do.
+
+ // ncurses can't handle J and K of ANSI code behavior.
if ((text[3] == 'J') || (text[3] == 'K'))
continue;
@@ -219,15 +218,14 @@ convert_ansi_into_256_color(char **save_ptr) {
}
// WONTFIX: You can't init_color with numerous RGB code in ncurses.
- // I decided to force delta users to use "true-color = never" when using tig,
- // so the process never comes to this condition.
- // I leave the code for someone who wants to implements in the future.
+ // Therefore, \e[(3 or 4)8;2;r;g;bm syntax is disabled currently.
+ // The below code is left for when it is someday implemented.
// if (strcmp(color_method_mark, "2") == 0) {
// char *r = strtok(NULL, ";");
// char *g = strtok(NULL, ";");
// char *b = strtok(NULL, ";");
// }
- // Do some process to convert those color infos for ncurses.
+ // Return a color pair ID that matches this rgb combination.
return c256;
}
diff --git a/src/draw.c b/src/draw.c
index 8dcf4428..b6f8eeb2 100644
--- a/src/draw.c
+++ b/src/draw.c
@@ -13,11 +13,14 @@
#include "tig/tig.h"
#include "tig/graph.h"
-#include "tig/ansi.h"
#include "tig/draw.h"
#include "tig/options.h"
#include "compat/hashtab.h"
+#if defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH >= 20180127
+#include "tig/ansi.h"
+#endif
+
static const enum line_type palette_colors[] = {
LINE_PALETTE_0,
LINE_PALETTE_1,
@@ -172,13 +175,18 @@ draw_text_expanded(struct view *view, enum line_type type, const char *string, i
size_t pos = string_expand(text, sizeof(text), string, length, opt_tab_size);
size_t col = view->col;
- if (opt_diff_highlight && *opt_diff_highlight && strcmp(opt_diff_highlight, "delta") == 0 && strstr(string, "\033[") != NULL) {
+#if defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH >= 20180127
+ if (strstr(string, "\033[") != NULL) {
if (draw_chars_with_ansi(view, type, text, -1, max_width, use_tilde))
return true;
} else {
if (draw_chars(view, type, text, -1, max_width, use_tilde))
return true;
}
+#else
+ if (draw_chars(view, type, text, -1, max_width, use_tilde))
+ return true;
+#endif
string += pos;
length -= pos;
diff --git a/src/line.c b/src/line.c
index 19446d50..3cd8c3b2 100644
--- a/src/line.c
+++ b/src/line.c
@@ -23,7 +23,9 @@ static size_t line_rules;
static struct line_info **color_pair;
static size_t color_pairs;
+#if defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH >= 20180127
short color_pairs_map[257][257];
+#endif
DEFINE_ALLOCATOR(realloc_line_rule, struct line_rule, 8)
DEFINE_ALLOCATOR(realloc_color_pair, struct line_info *, 8)
@@ -243,6 +245,7 @@ init_colors(void)
}
}
+#if defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH >= 20180127
// Because init_extended_pair can't accept more than 32768 pairs,
// we skip the colors with color codes odd numbered and greater than 15 currently.
short cnt = COLOR_ID(LINE_NONE) + 1;
@@ -264,6 +267,7 @@ init_colors(void)
}
init_extended_pair(++cnt, COLOR_DEFAULT, COLOR_DEFAULT);
color_pairs_map[256][256] = cnt;
+#endif
}
/* vim: set ts=8 sw=8 noexpandtab: */