Download raw body.
[rfc] tog horizontal scroll (diff & blame view)
Stefan Sperling <stsp@stsp.name> wrote:
> On Thu, Jun 16, 2022 at 01:38:16PM +0200, Stefan Sperling wrote:
> > On Thu, Jun 16, 2022 at 09:16:05PM +1000, Mark Jamsek wrote:
> > > On 22-06-16 12:33pm, Stefan Sperling wrote:
> > > > This new helper could be part of format_line(), but for now I wanted
> > > > to keep it seperate. Otherwise I would need to update all existing
> > > > callers of format_line() in the same patch.
> > > >
> > >
> > > I think that's a good idea too; it makes sense doing this in
> > > format_line().
> >
> > Yes, I'll try to this later once things have settled a bit.
>
> Well, why not do it now.
>
> Having this functionality built into format_line() should make it
> easier to fix the other views for unicode.
>
> ok?
looking at this i thought of simplifying the loop around wcwidth.
wcwidth can't really fail, it either returns 0, 1, 2 or -1 and doesn't
set errno. Furthermore, we're repeating most of the bits around...
(while here also a bit of style(9): not declare and initialize vars with
a function call, as pointed out by tb@ in a previous mail about a
different bit.)
ok?
diff ccda2f4db6c3f1c5132eefc87f1fc2dbd5298cc4 /home/op/w/got
blob - 285021accb225e5cc858097d09e1a68d4b32e1ca
file + tog/tog.c
--- tog/tog.c
+++ tog/tog.c
@@ -1261,47 +1261,35 @@ expand_tab(char **ptr, const char *src)
* Skip leading nscroll columns of a wide character string.
* Returns the index to the first character of the scrolled string.
*/
-static const struct got_error *
+static void
scroll_wline(int *scrollx , wchar_t *wline, int nscroll,
int col_tab_align)
{
- int cols = 0;
- size_t wlen = wcslen(wline);
+ int width, cols = 0;
+ size_t wlen;
int i = 0;
+ wlen = wcslen(wline);
*scrollx = 0;
while (i < wlen && cols < nscroll) {
- int width = wcwidth(wline[i]);
+ width = wcwidth(wline[i]);
+ if (wline[i] == L'\t')
+ width = TABSIZE - ((cols + col_tab_align) % TABSIZE);
- if (width == 0) {
- i++;
- continue;
+ if (width == -1) {
+ width = 1;
+ wline[i] = L'.';
}
- if (width == 1 || width == 2) {
- if (cols + width > nscroll)
- break;
- cols += width;
- i++;
- } else if (width == -1) {
- if (wline[i] == L'\t') {
- width = TABSIZE -
- ((cols + col_tab_align) % TABSIZE);
- } else {
- width = 1;
- wline[i] = L'.';
- }
- if (cols + width > nscroll)
- break;
- cols += width;
- i++;
- } else
- return got_error_from_errno("wcwidth");
+ if (cols + width > nscroll)
+ break;
+
+ cols += width;
+ i++;
}
*scrollx = i;
- return NULL;
}
/*
@@ -1334,9 +1322,7 @@ format_line(wchar_t **wlinep, int *widthp, int *scroll
if (err)
return err;
- err = scroll_wline(&scrollx, wline, nscroll, col_tab_align);
- if (err)
- goto done;
+ scroll_wline(&scrollx, wline, nscroll, col_tab_align);
if (wlen > 0 && wline[wlen - 1] == L'\n') {
wline[wlen - 1] = L'\0';
@@ -1349,41 +1335,28 @@ format_line(wchar_t **wlinep, int *widthp, int *scroll
i = scrollx;
while (i < wlen) {
- int width = wcwidth(wline[i]);
+ int width;
- if (width == 0) {
- i++;
- continue;
- }
+ width = wcwidth(wline[i]);
+ if (wline[i] == L'\t')
+ width = TABSIZE - ((cols + col_tab_align) % TABSIZE);
- if (width == 1 || width == 2) {
- if (cols + width > wlimit)
- break;
- cols += width;
- i++;
- } else if (width == -1) {
- if (wline[i] == L'\t') {
- width = TABSIZE -
- ((cols + col_tab_align) % TABSIZE);
- } else {
- width = 1;
- wline[i] = L'.';
- }
- if (cols + width > wlimit)
- break;
- cols += width;
- i++;
- } else {
- err = got_error_from_errno("wcwidth");
- goto done;
+ if (width == -1) {
+ width = 1;
+ wline[i] = L'.';
}
+
+ if (cols + width > wlimit)
+ break;
+
+ cols += width;
+ i++;
}
wline[i] = L'\0';
if (widthp)
*widthp = cols;
if (scrollxp)
*scrollxp = scrollx;
-done:
if (err)
free(wline);
else
[rfc] tog horizontal scroll (diff & blame view)