Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix ansi converter by passing char pointer by reference
  • Loading branch information
ulwlu authored and koutcher committed Sep 4, 2023
commit dc7addb136673b64d296c0645b2ae1e63e9821fb
2 changes: 1 addition & 1 deletion include/tig/ansi.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void split_ansi(const char *string, int *ansi_num, char **ansi_ptrs);
void draw_ansi(struct view *view, int *ansi_num, char **ansi_ptrs, int max_width, size_t skip);
void draw_ansi_line(struct view *view, char *ansi_end_ptr, int *after_ansi_len, size_t *skip, int *cur_width, int *widths_of_display);
void wattrset_by_ansi_status(struct view *view, struct ansi_status* cur_ansi_status);
short convert_ansi_into_256_color(char *save_ptr);
short convert_ansi_into_256_color(char **save_ptr);

#endif

Expand Down
10 changes: 5 additions & 5 deletions src/ansi.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ draw_ansi(struct view *view, int *ansi_num, char **ansi_ptrs, int max_width, siz
if (strcmp(ansi_code_part, "37") == 0)
cur_ansi_status.fg = COLOR_WHITE;
if (strcmp(ansi_code_part, "38") == 0) {
short c256 = convert_ansi_into_256_color(saveptr);
short c256 = convert_ansi_into_256_color(&saveptr);
if (c256 != -1)
cur_ansi_status.fg = c256;
}
Expand All @@ -152,7 +152,7 @@ draw_ansi(struct view *view, int *ansi_num, char **ansi_ptrs, int max_width, siz
if (strcmp(ansi_code_part, "46") == 0)
cur_ansi_status.bg = COLOR_CYAN;
if (strcmp(ansi_code_part, "48") == 0) {
short c256 = convert_ansi_into_256_color(saveptr);
short c256 = convert_ansi_into_256_color(&saveptr);
if (c256 != -1)
cur_ansi_status.bg = c256;
}
Expand Down Expand Up @@ -208,11 +208,11 @@ wattrset_by_ansi_status(struct view *view, struct ansi_status* cur_ansi_status)
}

short
convert_ansi_into_256_color(char *save_ptr) {
char *color_method_mark = strtok_r(NULL, ";", &save_ptr);
convert_ansi_into_256_color(char **save_ptr) {
char *color_method_mark = strtok_r(NULL, ";", save_ptr);
short c256 = -1;
if (strcmp(color_method_mark, "5") == 0) {
char *color_code = strtok_r(NULL, ";", &save_ptr);
char *color_code = strtok_r(NULL, ";", save_ptr);
c256 = atoi(color_code);
}

Expand Down