From: Claudio Jeker Subject: Re: usr.bin/vi: add 'are we there yet' indicator to the ruler To: Job Snijders Cc: tech@openbsd.org Date: Wed, 24 Apr 2024 10:40:49 +0200 On Sun, Apr 21, 2024 at 10:27:59PM +0000, Job Snijders wrote: > When working my way through source code files, I sometimes notice myself > starting to wonder how long it'll be before my plight is over. Hitting > control-G over and over again increases anxiety. Instead, the ruler > could just show, as a percentage, how far into the file the cursor is. > > This patch adds an 'are we there yet?' signal in the column bar by means > of displaying the current line number as a percentage of the total lines > in the file, only if the 'ruler' option is set, and if the last line > number can be determined. > > OK? Works for me. Code is mostly the same as ^G so OK claudio@ > Index: docs/USD.doc/vi.man/vi.1 > =================================================================== > RCS file: /cvs/src/usr.bin/vi/docs/USD.doc/vi.man/vi.1,v > diff -u -p -r1.84 vi.1 > --- docs/USD.doc/vi.man/vi.1 12 Feb 2024 16:42:42 -0000 1.84 > +++ docs/USD.doc/vi.man/vi.1 21 Apr 2024 22:12:29 -0000 > @@ -2461,7 +2461,7 @@ Set the number of lines about which the > .It Cm ruler Bq off > .Nm vi > only. > -Display a row/column ruler on the colon command line. > +Display a row/column/percentage ruler on the colon command line. > .It Cm scroll , scr Bq "($LINES \- 1) / 2" > Set the number of lines scrolled. > .It Cm searchincr Bq off > Index: vi/vs_refresh.c > =================================================================== > RCS file: /cvs/src/usr.bin/vi/vi/vs_refresh.c,v > diff -u -p -r1.23 vs_refresh.c > --- vi/vs_refresh.c 12 Feb 2024 16:42:43 -0000 1.23 > +++ vi/vs_refresh.c 21 Apr 2024 22:12:29 -0000 > @@ -782,6 +782,7 @@ vs_modeline(SCR *sp) > const char *t = NULL; > int ellipsis; > char *p, buf[20]; > + recno_t last; > > /* > * It's possible that this routine will be called after sp->frp > @@ -857,8 +858,14 @@ vs_modeline(SCR *sp) > cols = sp->cols - 1; > if (O_ISSET(sp, O_RULER)) { > vs_column(sp, &curcol); > - len = snprintf(buf, sizeof(buf), "%lu,%zu", > - (ulong)sp->lno, curcol + 1); > + > + if (db_last(sp, &last)) > + len = snprintf(buf, sizeof(buf), "%lu,%zu", > + (ulong)sp->lno, curcol + 1); > + else > + len = snprintf(buf, sizeof(buf), "%lu,%zu %lu%%", > + (ulong)sp->lno, curcol + 1, > + (unsigned long)(sp->lno * 100) / last); > > midpoint = (cols - ((len + 1) / 2)) / 2; > if (curlen < midpoint) { > -- :wq Claudio