summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorulwlu <ooulwluoo@gmail.com>2021-08-17 16:40:56 +0900
committerThomas Koutcher <thomas.koutcher@online.fr>2023-09-04 21:23:47 +0200
commitda8ec39da53d77582025f38c5b8645bf7d3be8b8 (patch)
treef3bf4523563d912cb26714309f2f6ce540d11aed
parent256dea03a1c3cffee439e71916f534d80a97d3b7 (diff)
Fix wording for parsing ansi
-rw-r--r--src/ansi.c13
-rw-r--r--src/line.c4
2 files changed, 8 insertions, 9 deletions
diff --git a/src/ansi.c b/src/ansi.c
index e5c4467c..0272f9f0 100644
--- a/src/ansi.c
+++ b/src/ansi.c
@@ -19,15 +19,15 @@
void
split_ansi(const char *string, int *ansi_num, char **ansi_ptrs) {
- char *needle = "\033[";
+ char *head_of_ansi = "\033[";
int current_ansi_idx = 0;
- char *next_ansi_ptr = strstr(string + current_ansi_idx, needle);
+ char *next_ansi_ptr = strstr(string + current_ansi_idx, head_of_ansi);
if (next_ansi_ptr == NULL)
return;
while (next_ansi_ptr != NULL) {
if (strcmp(string, next_ansi_ptr) == 0) {
- next_ansi_ptr = strstr(string + current_ansi_idx + strlen(needle), needle);
+ next_ansi_ptr = strstr(string + current_ansi_idx + strlen(head_of_ansi), head_of_ansi);
continue;
}
int current_ansi_length = strlen(string + current_ansi_idx) - strlen(next_ansi_ptr);
@@ -35,7 +35,7 @@ split_ansi(const char *string, int *ansi_num, char **ansi_ptrs) {
ansi_ptrs[*ansi_num][current_ansi_length] = '\0';
*ansi_num += 1;
current_ansi_idx += current_ansi_length / sizeof(char);
- next_ansi_ptr = strstr(string + current_ansi_idx + strlen(needle), needle);
+ next_ansi_ptr = strstr(string + current_ansi_idx + strlen(head_of_ansi), head_of_ansi);
}
strcpy(ansi_ptrs[*ansi_num], string + current_ansi_idx);
@@ -49,8 +49,7 @@ draw_ansi(struct view *view, int *ansi_num, char **ansi_ptrs) {
cur_ansi_status.bg = COLOR_BLACK;
cur_ansi_status.attr = A_NORMAL;
- for (int i = 0; i < *ansi_num; i++)
- {
+ for (int i = 0; i < *ansi_num; i++) {
int len = strlen(ansi_ptrs[i]);
char text[len + 1];
strcpy(text, ansi_ptrs[i]);
@@ -131,7 +130,7 @@ draw_ansi(struct view *view, int *ansi_num, char **ansi_ptrs) {
strcpy(token, ansi_code);
char *ansi_code_part = strtok(token, ";");
- while(ansi_code_part != NULL) {
+ while (ansi_code_part != NULL) {
char *color_method_mark = strtok(NULL, ";");
if (strcmp(color_method_mark, "5") == 0) {
char *c256 = strtok(NULL, ";");
diff --git a/src/line.c b/src/line.c
index cfca4877..4db23067 100644
--- a/src/line.c
+++ b/src/line.c
@@ -247,12 +247,12 @@ init_colors(void)
// if we compiled with --ext-colors, but it doesn't work.
// https://github.com/mirror/ncurses/blob/56a81c7e79f73d397cc8074401d039f59c34cad5/ncurses/base/lib_color.c#L382-L391
// Currently we skip the odd number upper than 15.
- short cnt = COLOR_ID(LINE_NONE);
+ short cnt = COLOR_ID(LINE_NONE) + 1;
for (short bg = 0; bg < 256; bg++) {
for (short fg = 0; fg < 256; fg++) {
if ((fg > 15 && fg % 2 == 1) || (bg > 15 && bg % 2 == 1))
continue;
- init_extended_pair(cnt++, fg, bg);
+ init_extended_pair(++cnt, fg, bg);
color_pairs_map[fg][bg] = cnt;
}
}