From b254483d64afb832597affd199aa63d6d99b70a3 Mon Sep 17 00:00:00 2001 From: job Date: Wed, 24 Apr 2024 15:15:40 +0000 Subject: [PATCH] In ruler show the current line number as a percentage of the total lines OK claudio@ --- usr.bin/vi/docs/USD.doc/vi.man/vi.1 | 6 +++--- usr.bin/vi/vi/vs_refresh.c | 13 ++++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/usr.bin/vi/docs/USD.doc/vi.man/vi.1 b/usr.bin/vi/docs/USD.doc/vi.man/vi.1 index 20abba2e8c1..585e033bce6 100644 --- a/usr.bin/vi/docs/USD.doc/vi.man/vi.1 +++ b/usr.bin/vi/docs/USD.doc/vi.man/vi.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: vi.1,v 1.84 2024/02/12 16:42:42 job Exp $ +.\" $OpenBSD: vi.1,v 1.85 2024/04/24 15:15:40 job Exp $ .\" .\" Copyright (c) 1994 .\" The Regents of the University of California. All rights reserved. @@ -14,7 +14,7 @@ .\" .\" @(#)vi.1 8.51 (Berkeley) 10/10/96 .\" -.Dd $Mdocdate: February 12 2024 $ +.Dd $Mdocdate: April 24 2024 $ .Dt VI 1 .Os .Sh NAME @@ -2461,7 +2461,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 "($LINES \- 1) / 2" Set the number of lines scrolled. .It Cm searchincr Bq off diff --git a/usr.bin/vi/vi/vs_refresh.c b/usr.bin/vi/vi/vs_refresh.c index 38b01ddee31..91769cfb3e6 100644 --- a/usr.bin/vi/vi/vs_refresh.c +++ b/usr.bin/vi/vi/vs_refresh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vs_refresh.c,v 1.23 2024/02/12 16:42:43 job Exp $ */ +/* $OpenBSD: vs_refresh.c,v 1.24 2024/04/24 15:15:40 job Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -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) { -- 2.20.1