"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Omar Polo <op@omarpolo.com>
Subject:
Re: tog: fix horizontal scrolling of unicode in the diff view
To:
Stefan Sperling <stsp@stsp.name>
Cc:
gameoftrees@openbsd.org
Date:
Thu, 16 Jun 2022 19:16:24 +0200

Download raw body.

Thread
Stefan Sperling <stsp@stsp.name> wrote:
> On Thu, Jun 16, 2022 at 07:06:05PM +0200, Stefan Sperling wrote:
> > On Thu, Jun 16, 2022 at 05:46:24PM +0200, Stefan Sperling wrote:
> > > As you noted, this patch breaks the '$' key in the diff view.
> > > 
> > > I will need some more time to investigate and find a proper fix.
> > 
> > Here is a much simpler version which seems to work better.
> > 
> > Instead of complicating format_line() even further, we can let
> > draw_file() run it twice, each time with different parameters.
> > This way draw_file() can get all the required information.
> > 
> > Neither this version nor the old version of this patch fixes
> > the search highlighting case yet. That will come later.
> > 
> > ok?
> > 
> 
> And, on top, the same fix for the blame view:

ok op@ for both

> diff 3714876751901b56caaa1a0f030bc190cb5addaf c99ab962e94352d9570c6d6fee433ccb2a6eb150
> blob - 34234f43c9ed0ca69cafef58339f81769b9fcc06
> blob + 8e0df704f4fdfb2b9ed714236a383ff6eb0010f9
> --- tog/tog.c
> +++ tog/tog.c
> @@ -4275,7 +4275,7 @@ draw_blame(struct tog_view *view)
>  	struct tog_blame *blame = &s->blame;
>  	regmatch_t *regmatch = &view->regmatch;
>  	const struct got_error *err;
> -	int lineno = 0, nprinted = 0, i;
> +	int lineno = 0, nprinted = 0;
>  	char *line = NULL;
>  	size_t linesize = 0;
>  	ssize_t linelen;
> @@ -4354,8 +4354,6 @@ draw_blame(struct tog_view *view)
>  		if (++lineno < s->first_displayed_line)
>  			continue;
>  
> -		view->maxx = MAX(view->maxx, linelen);
> -
>  		if (view->focussed && nprinted == s->selected_line - 1)
>  			wstandout(view->window);
>  
> @@ -4413,19 +4411,32 @@ draw_blame(struct tog_view *view)
>  				free(line);
>  				return err;
>  			}
> +			view->maxx = MAX(view->maxx, width);
>  			width += 9;
>  		} else {
> -			err = format_line(&wline, &width, NULL, line, 0,
> -			    view->x + view->ncols - 9, 9, 1);
> +			int skip;
> +
> +			/* Set view->maxx based on full line length. */
> +			err = format_line(&wline, &width, NULL, line,
> +			    0, INT_MAX, 9, 1);
>  			if (err) {
>  				free(line);
>  				return err;
>  			}
> -			if (view->x < width) {
> -				waddwstr(view->window, wline + view->x);
> -				for (i = 0; i < view->x; i++)
> -					width -= wcwidth(wline[i]);
> +			view->maxx = MAX(view->maxx, width);
> +
> +			/*
> +			 * Get a new version of the line for display.
> +			 * This will be scrolled and/or trimmed in length.
> +			 */
> +			free(wline);
> +			err = format_line(&wline, &width, &skip, line, view->x,
> +			    view->ncols - 9, 9, 1);
> +			if (err) {
> +				free(line);
> +				return err;
>  			}
> +			waddwstr(view->window, &wline[skip]);
>  			width += 9;
>  			free(wline);
>  			wline = NULL;