Skip to content

Commit

Permalink
In ruler show the current line number as a percentage of the total li…
Browse files Browse the repository at this point in the history
…nes (#131)

Modeled after control-G, will only show the percentage if the last
line can be determined.

From OpenBSD openbsd/src@b254483
and openbsd/src@39e743a
  • Loading branch information
job authored Apr 26, 2024
1 parent 848546f commit 52c07e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion man/vi.1
Original file line number Diff line number Diff line change
Expand Up @@ -2482,7 +2482,7 @@ Set the number of lines about which the editor reports changes or yanks.
.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 "window size / 2"
Set the number of lines scrolled.
.It Cm searchincr Bq off
Expand Down
13 changes: 10 additions & 3 deletions vi/vs_refresh.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,8 @@ vs_modeline(SCR *sp)
size_t cols, curcol, curlen, endpoint, len, midpoint;
const char *t = NULL;
int ellipsis;
char buf[20];
char buf[30];
recno_t last;

gp = sp->gp;

Expand Down Expand Up @@ -846,8 +847,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,%lu",
(u_long)sp->lno, (u_long)(curcol + 1));

if (db_last(sp, &last) || last == 0)
len = snprintf(buf, sizeof(buf), "%lu,%zu",
(u_long)sp->lno, curcol + 1);
else
len = snprintf(buf, sizeof(buf), "%lu,%zu %lu%%",
(u_long)sp->lno, curcol + 1,
(u_long)(sp->lno * 100) / last);

midpoint = (cols - ((len + 1) / 2)) / 2;
if (curlen < midpoint) {
Expand Down

0 comments on commit 52c07e8

Please sign in to comment.