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

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: [rfc] tog horizontal scroll (diff & blame view)
To:
Mark Jamsek <mark@jamsek.com>
Cc:
gameoftrees@openbsd.org
Date:
Wed, 15 Jun 2022 16:52:47 +0200

Download raw body.

Thread
On Thu, Jun 16, 2022 at 12:04:17AM +1000, Mark Jamsek wrote:
> This patch introduces support for horizontal scrolling in diff and blame
> views.
> 
> New key maps:
> 
> h - scroll left (left arrow works too)
> l - scroll right (right arrow works too)
> 0 - scroll to the beginning of the line
> $ - scroll to the end of longest line on screen

The $ key triggers scrolling to the right even if all lines fit within
the current width of the window. I am not sure if this is intended.

As an example, in a hypothetical small 8 columns diff/blame view,
and with just one line in the file:

12345678
foobar

Hitting '$' now results in something like this, where it seems to
scroll to roughly the middle of the line:

12345678
bar

Whereas I would expect it to work like this:

Given:

12345678
foobar

Hit '$' -> no change since the line already fits

But in this situation:

12345678....<- columns with dots are offscreen
foobarbazboo

The result of '$' I expect would be:

12345678
arbazboo

Does this make sense?
Or is there something wrong in my assumptions?

> +static uint16_t
> +expanded_strsz(const char *str, unsigned short n)
> +{
> +	uint16_t i = 0;
> +
> +	while (str && (str[i] != '\n' && str[i] != '\0')) {
> +		if (str[i] == '\t')
> +			n += 8 - (i % 8);  /* expand tabs */
> +		if ((str[i] & 0xc0) == 0x80)
> +			--n;  /* utf8 continutation byte */
> +		++i;
> +	}
> +
> +	return n;

This code should work fine on OpenBSD. However, Got -portable might
be running on systems which use non-UTF8 locales. For this reason,
it might be better to use wchar_t and wcwidth() to determine the
display length of the expanded version of the string. It would then
work on OpenBSD and everywhere else, and less work would be required
for the -portable version.