nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: a scroll bar on the right that shows position and portion


From: Benno Schulenberg
Subject: Re: a scroll bar on the right that shows position and portion
Date: Fri, 24 Apr 2020 12:54:36 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0

Op 24-04-2020 om 05:53 schreef Marco Diego Aurélio Mesquita:
> I think it is possible to do a bit better with less code. Attached
> patch 2 allows us to use "scrollbarcolor " to set both foreground and
> background colors of the scrollbar.

Please, don't add unneeded complications.  Keep things simple: just
concentrate on the essential stuff to make the scrollbar work.  If
we want some coloring later, it can easily be added.  Don't annoy me
with unneeded patches now.

> +WINDOW *scrollbarwin = NULL;
> +             /* The last col of the screen. It is used to display the 
> scrollbar.
> +              */

Come one, don't use a whole line for just two characters.  And don't
abbreviate "column".

>       if (topwin != NULL)
>               delwin(topwin);
> +     if (scrollbarwin)
> +             delwin(scrollbarwin);
>       delwin(edit);
>       delwin(bottomwin);

Don't just put code anywhere: keep things in order.  The scrollbar window
is the fourth window: keep it in fourth place.  And not just here, but
everywhere.

> +     /* If the terminal is too thin, don't set up a scrollbar. */
> +     if (COLS < 3)
> +             scrollbarwin = NULL;

Again, wrong place for this snippet.

> -     editwincols = COLS - margin;
> +     editwincols = COLS - margin - (ISSET(SHOW_SCROLLBAR) ? 1 : 0);

The same things should be done in src/help.c.  Because now: run nano and
type ^G, then make your window narrower than 74 columns.  Continuation
characters (>) appear that shouldn't appear.

> +     int inf = (openfile->edittop->lineno*editwinrows)/(last_lineno+1);
> +     int sup = inf + (editwinrows*editwinrows)/(last_lineno+1);

Nano's style is to have spaces around all operators.

> +     /* Consider that we'll have no scrollbar if window is too thin. */
> +     if (!ISSET(SHOW_SCROLLBAR) && scrollbarwin)
> +             return;

I think this should just be:

    if (scrollbarwin == NULL)
        return;

If the setup of the subwindows is correct, it should be enough.

> +     if (editwinrows >= last_lineno) {
> +             inf = 0;
> +             sup = last_lineno - 1;
> +     }

This computation is not right.  Run for example:

  grep for README >shorttext
  src/nano --line shorttext

See that the scrollbar reaches just up to line 7.  But it ought to
occupy the full height of the edit window, because the entire content
of the buffer is in view.

Now type <Alt+Down> a few times.  The scrollbar does not change.
But it should shrink with each line that is scrolled out of view.

Benno

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]