Skip to content

Commit

Permalink
Rework after review
Browse files Browse the repository at this point in the history
  • Loading branch information
ulwlu authored and koutcher committed Sep 4, 2023
1 parent d0f5df2 commit 3069211
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion doc/tigrc.5.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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>]::
Expand Down
2 changes: 2 additions & 0 deletions include/tig/line.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 5 additions & 7 deletions src/ansi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 2 additions & 8 deletions src/apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,8 @@ struct app_external
&& app_diff_highlight_path_search(dhlt_path, sizeof(dhlt_path), query)
&& *dhlt_path) {
if (suffixcmp(dhlt_path, strlen(dhlt_path), "/diff-highlight.perl")) {
if (strcmp(strrchr(dhlt_path, '/'), "/delta") == 0) {
dhlt_app.argv[0] = dhlt_path;
dhlt_app.argv[1] = "--true-color=never";
dhlt_app.argv[2] = NULL;
} else {
dhlt_app.argv[0] = dhlt_path;
dhlt_app.argv[1] = NULL;
}
dhlt_app.argv[0] = dhlt_path;
dhlt_app.argv[1] = NULL;
} else if (path_search(perl_path, sizeof(perl_path), "perl", getenv("PATH"), X_OK)) {
/* if the package manager failed to "make install" within the contrib dir, rescue via */
/* perl -MDiffHighlight -I/path/containing /path/containing/diff-highlight.perl */
Expand Down
12 changes: 10 additions & 2 deletions src/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/line.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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: */

0 comments on commit 3069211

Please sign in to comment.