commit dc6575130e2ead643f59217e54ec22ba3afd1c31
parent 9d042ca32187bb8ed793a3fae69c04a1b470e37f
Author: James Prestwood <prestwoj@gmail.com>
Date: Wed, 12 Oct 2022 11:35:22 -0700
client: fix missing character for line breaks without spaces
In nearly all cases the auto-line breaks can be on spaces in the
string. The only exception (so far) is DPP which displays a very
long URI without any spaces. When this is displayed a single
character was lost on each break. This was due to the current line
being NULL terminated prior to the next line string being returned.
To handle both cases the next line is copied prior to terminating
the current line. The offsets were modified slightly so the line
will be broken *after* the space, not on the space. This leaves
the space at the end of the current line which is invisible to the
user but allows the no-space case to also work without loss of
the last character (since that last character is where the space
normally would be).
Diffstat:
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/client/display.c b/client/display.c
@@ -405,6 +405,7 @@ static char* next_line(char *s, unsigned int width, unsigned int *new_width,
int last_color = -1;
unsigned int s_len = strlen(s);
unsigned int color_adjust = 0;
+ char *ret;
*new_width = width;
*color_out = NULL;
@@ -452,7 +453,7 @@ static char* next_line(char *s, unsigned int width, unsigned int *new_width,
/* Not anywhere nice to split the line */
if (last_space == -1)
- last_space = *new_width - 1;
+ last_space = *new_width;
/*
* Only set the color if it occurred prior to the last space. If after,
@@ -464,9 +465,11 @@ static char* next_line(char *s, unsigned int width, unsigned int *new_width,
else if (last_color != -1 && last_space < last_color)
*new_width -= color_adjust;
- s[last_space] = '\0';
+ ret = l_strdup(s + last_space + 1);
- return l_strdup(s + last_space + 1);
+ s[last_space + 1] = '\0';
+
+ return ret;
}
struct table_entry {