Skip to content

Commit

Permalink
Add --no-number-headers option.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Aug 29, 2021
1 parent 24a3c8a commit 6356151
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 13 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

* Add the --header option.

* Add the --no-number-headers option.

* Add the --status-line option.

* Fix display of multibyte and double-width chars in prompt.
Expand Down
1 change: 1 addition & 0 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extern IFILE curr_ifile;
extern void *ml_search;
extern void *ml_examine;
extern int wheel_lines;
extern int header_lines;
#if SHELL_ESCAPE || PIPEC
extern void *ml_shell;
#endif
Expand Down
22 changes: 20 additions & 2 deletions forwback.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ forw_line_pfx(pos, pfx, skipeol)
int save_sc_width = sc_width;
int save_auto_wrap = auto_wrap;
int save_hshift = hshift;
/* Set fake sc_width to force only pfx chars to be read. */
/* Set fake sc_width to force only pfx chars to be read. */
sc_width = pfx + line_pfx_width();
auto_wrap = 0;
hshift = 0;
Expand Down Expand Up @@ -165,6 +165,12 @@ overlay_header(VOID_PARAM)
for (ln = 0; ln < header_lines; ++ln)
{
pos = forw_line(pos);
/*
* Underline last line of header, unless
* we are at beginning of file.
*/
if (ln+1 == header_lines && position(0) != ch_zero())
punderline();
clear_eol();
put_line();
}
Expand All @@ -184,7 +190,7 @@ overlay_header(VOID_PARAM)
putchr('\n');
else
{
/* Need skipeol for all header lines except the last one. */
/* Need skipeol for all header lines except the last one. */
pos = forw_line_pfx(pos, header_cols, ln+1 < header_lines);
put_line();
}
Expand Down Expand Up @@ -364,6 +370,18 @@ forw(n, pos, force, only_last, nblank)
forw_prompt = 1;
}

if (header_lines > 0)
{
/*
* Don't allow ch_zero to appear on screen except at top of screen.
* Otherwise duplicate header lines may be displayed.
*/
if (onscreen(ch_zero()) > 0)
{
jump_loc(ch_zero(), 0); /* {{ yuck }} */
return;
}
}
if (nlines == 0 && !ignore_eoi)
eof_bell();
else if (do_repaint)
Expand Down
2 changes: 2 additions & 0 deletions less.hlp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@
Don't send termcap keypad init/deinit strings.
--no-histdups
Remove duplicates from command history.
--no-number-headers
Don't give line numbers to header lines.
--rscroll=C
Set the character used to mark truncated lines.
--save-marks
Expand Down
5 changes: 5 additions & 0 deletions less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,8 @@ even if the rest of the line is scrolled horizontally.
If either N or M is zero,
.I less
stops displaying header lines or columns, respectively.
(Note that it may be neccessary to change the setting of the \-j option
to ensure that the target line is not obscured by the header line(s).)
.IP "\-\-incsearch"
Subsequent search commands will be "incremental"; that is,
.I less
Expand Down Expand Up @@ -1149,6 +1151,9 @@ file name is typed in, and the same string is already in the history list,
the existing copy is removed from the history list before the new one is added.
Thus, a given string will appear only once in the history list.
Normally, a string may appear multiple times.
.IP "\-\-no-number-headers"
Header lines (defined via the \-\-header option) are not assigned line numbers.
Line number 1 is assigned to the first line after any header lines.
.IP "\-\-rscroll"
This option changes the character used to mark truncated lines.
It may begin with a two-character attribute indicator like LESSBINFMT does.
Expand Down
24 changes: 21 additions & 3 deletions line.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,14 @@ plinestart(pos)
char buf[INT_STRLEN_BOUND(linenum) + 2];
int len;

linenumtoa(linenum, buf);
len = (int) strlen(buf);
linenum = vlinenum(linenum);
if (linenum == 0)
len = 0;
else
{
linenumtoa(linenum, buf);
len = (int) strlen(buf);
}
for (i = 0; i < linenum_width - len; i++)
add_pfx(' ', AT_NORMAL);
for (i = 0; i < len; i++)
Expand Down Expand Up @@ -1260,7 +1266,19 @@ pdone(endline, chopped, forw)
}

/*
*
* Underline the line in the line buffer.
*/
public void
punderline(VOID_PARAM)
{
int i;

for (i = linebuf.print; i < linebuf.end; i++)
linebuf.attr[i] |= AT_UNDERLINE;
}

/*
* Set the char to be displayed in the status column.
*/
public void
set_status_col(c, attr)
Expand Down
21 changes: 18 additions & 3 deletions linenum.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ extern int linenums;
extern int sigs;
extern int sc_height;
extern int screen_trashed;
extern int header_lines;
extern int nonum_headers;

/*
* Initialize the line number structures.
Expand Down Expand Up @@ -484,11 +486,24 @@ scan_eof(VOID_PARAM)
ierror("Determining length of file", NULL_PARG);
while (pos != NULL_POSITION)
{
/* For efficiency, only add one every 256 line numbers. */
if ((linenum++ % 256) == 0)
add_lnum(linenum, pos);
/* For efficiency, only add one every 256 line numbers. */
if ((linenum++ % 256) == 0)
add_lnum(linenum, pos);
pos = forw_raw_line(pos, (char **)NULL, (int *)NULL);
if (ABORT_SIGS())
break;
}
}

/*
* Return a line number adjusted for display
* (handles the --no-number-headers option).
*/
public LINENUM
vlinenum(linenum)
LINENUM linenum;
{
if (nonum_headers)
linenum = (linenum < header_lines) ? 0 : linenum - header_lines;
return linenum;
}
2 changes: 1 addition & 1 deletion optfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,6 @@ get_swindow(VOID_PARAM)
{
if (swindow > 0)
return (swindow);
return (sc_height + swindow);
return (sc_height - header_lines + swindow);
}

10 changes: 10 additions & 0 deletions opttbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public int want_filesize; /* Scan to EOF if necessary to get file size */
public int status_line; /* Highlight entire marked lines */
public int header_lines; /* Freeze header lines at top of screen */
public int header_cols; /* Freeze header columns at left of screen */
public int nonum_headers; /* Don't give headers line numbers */
#if HILITE_SEARCH
public int hilite_search; /* Highlight matched search patterns? */
#endif
Expand Down Expand Up @@ -144,6 +145,7 @@ static struct optname use_color_optname = { "use-color", NULL };
static struct optname want_filesize_optname = { "file-size", NULL };
static struct optname status_line_optname = { "status-line", NULL };
static struct optname header_optname = { "header", NULL };
static struct optname nonum_headers_optname = { "no-number-headers", NULL };
#if LESSTEST
static struct optname ttyin_name_optname = { "tty", NULL };
static struct optname rstat_optname = { "rstat", NULL };
Expand Down Expand Up @@ -583,6 +585,14 @@ static struct loption option[] =
NULL
}
},
{ OLETTER_NONE, &nonum_headers_optname,
BOOL|REPAINT, 0, &nonum_headers, NULL,
{
"Number header lines",
"Don't number header lines",
NULL
}
},
#if LESSTEST
{ OLETTER_NONE, &ttyin_name_optname,
STRING|NO_TOGGLE, 0, NULL, opt_ttyin_name,
Expand Down
1 change: 1 addition & 0 deletions position.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ static POSITION *table = NULL; /* The position table */
static int table_size = 0;

extern int sc_width, sc_height;
extern int header_lines;

/*
* Return the starting file position of a line displayed on the screen.
Expand Down
7 changes: 4 additions & 3 deletions prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extern int hshift;
extern int sc_height;
extern int jump_sline;
extern int less_is_more;
extern int header_lines;
extern IFILE curr_ifile;
#if EDITOR
extern char *editor;
Expand Down Expand Up @@ -260,7 +261,7 @@ protochar(c, where, iseditproto)
char *s;

#undef PAGE_NUM
#define PAGE_NUM(linenum) ((((linenum) - 1) / (sc_height - 1)) + 1)
#define PAGE_NUM(linenum) ((((linenum) - 1) / (sc_height - header_lines - 1)) + 1)

switch (c)
{
Expand Down Expand Up @@ -325,7 +326,7 @@ protochar(c, where, iseditproto)
case 'l': /* Current line number */
linenum = currline(where);
if (linenum != 0)
ap_linenum(linenum);
ap_linenum(vlinenum(linenum));
else
ap_quest();
break;
Expand All @@ -335,7 +336,7 @@ protochar(c, where, iseditproto)
(linenum = find_linenum(len)) <= 0)
ap_quest();
else
ap_linenum(linenum-1);
ap_linenum(vlinenum(linenum-1));
break;
case 'm': /* Number of files */
#if TAGS
Expand Down
2 changes: 1 addition & 1 deletion version.c
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ v590 6/3/21 Fix non-autoconf Makefiles.
v591 8/8/21 Use \kB for backspace key in lesskey; add more \k codes;
handle multibyte chars in prompt.
v592 8/24/21 Add --status-line option; limit use of /proc kludge; add --header.
v593
v593 Add header columns, --no-number-headers.
*/

char version[] = "593x";

0 comments on commit 6356151

Please sign in to comment.