Skip to content

Commit

Permalink
Add --status-line option.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Aug 21, 2021
1 parent a8b4980 commit 465a0b3
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 22 deletions.
4 changes: 3 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
https://github.com/gwsw/less/issues.

======================================================================
Major changes between "less" versions 590 and 591
Major changes between "less" versions 590 and 592

* Add the --status-line option.

* Fix display of multibyte and double-width chars in prompt.

Expand Down
2 changes: 2 additions & 0 deletions less.hlp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@
Retain marks across invocations of less.
--status-col-width=N
Set the width of the -J status column to N characters.
--status-line
Highlight or color the entire line containing a mark.
--use-backslash
Subsequent options use backslash as escape char.
--use-color
Expand Down
11 changes: 10 additions & 1 deletion less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,10 @@ The first "new" line is the line immediately following the line previously
at the bottom of the screen.
Also highlights the target line after a g or p command.
The highlight is removed at the next command which causes movement.
The entire line is highlighted, unless the \-J option is in effect,
If the \-\-status-line option is in effect, the entire line
(the width of the screen) is highlighted.
Otherwise, only the text in the line is highlighted,
unless the \-J option is in effect,
in which case only the status column is highlighted.
.IP "\-W or \-\-HILITE-UNREAD"
Like \-w, but temporarily highlights the first new line after any
Expand Down Expand Up @@ -1143,6 +1146,12 @@ across different invocations of
.IP "\-\-status-col-width"
Sets the width of the status column when the \-J option is in effect.
The default is 2 characters.
.IP "\-\-status-line"
If a line is marked, the entire line (rather than just the status column)
is highlighted.
Also lines highlighted due to the \-w option will have
the entire line highlighted.
If \-\-use-color is set, the line is colored rather than highlighted.
.IP "\-\-use-backslash"
This option changes the interpretations of options which follow this one.
After the \-\-use-backslash option, any backslash in an option string is
Expand Down
56 changes: 37 additions & 19 deletions line.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct xbuffer last_ansi;
public int size_linebuf = 0; /* Size of line buffer (and attr buffer) */
static struct ansi_state *line_ansi = NULL;
static int ansi_in_line;
static int line_mark_attr;
static int cshift; /* Current left-shift of output line buffer */
public int hshift; /* Desired left-shift of output line buffer */
public int tabstops[TABSTOP_MAX] = { 0 }; /* Custom tabstops */
Expand Down Expand Up @@ -83,6 +84,7 @@ extern POSITION end_attnpos;
extern char rscroll_char;
extern int rscroll_attr;
extern int use_color;
extern int status_line;

static char mbc_buf[MAX_UTF_CHAR_LEN];
static int mbc_buf_len = 0;
Expand Down Expand Up @@ -223,6 +225,7 @@ prewind(VOID_PARAM)
pendc = '\0';
in_hilite = 0;
ansi_in_line = 0;
line_mark_attr = 0;
xbuf_reset(&shifted_ansi);
xbuf_reset(&last_ansi);
}
Expand Down Expand Up @@ -303,22 +306,20 @@ plinestart(pos)
/*
* Display a status column if the -J option is set.
*/
if (status_col)
if (status_col || status_line)
{
int a = AT_NORMAL;
char c = posmark(pos);
if (c != 0)
a |= AT_HILITE|AT_COLOR_MARK;
else
line_mark_attr = AT_HILITE|AT_COLOR_MARK;
else if (start_attnpos != NULL_POSITION &&
pos >= start_attnpos && pos <= end_attnpos)
line_mark_attr = AT_HILITE|AT_COLOR_ATTN;
if (status_col)
{
c = ' ';
if (start_attnpos != NULL_POSITION &&
pos >= start_attnpos && pos <= end_attnpos)
a |= AT_HILITE|AT_COLOR_ATTN;
add_pfx(c ? c : ' ', line_mark_attr); /* column 0: status */
while (linebuf.pfx_end < status_col_width)
add_pfx(' ', AT_NORMAL);
}
add_pfx(c, a); /* column 0: status */
while (linebuf.pfx_end < status_col_width)
add_pfx(' ', AT_NORMAL);
}

/*
Expand Down Expand Up @@ -659,9 +660,18 @@ store_char(ch, a, rep, pos)
{
int matches;
int resend_last = 0;
int hl_attr = (pos != NULL_POSITION) ?
is_hilited_attr(pos, pos+1, 0, &matches) :
(!ansi_in_line) ? AT_STANDOUT|AT_COLOR_PROMPT : 0;
int hl_attr;

if (pos == NULL_POSITION)
{
/* Color the prompt unless it has ansi sequences in it. */
hl_attr = ansi_in_line ? 0 : AT_STANDOUT|AT_COLOR_PROMPT;
} else
{
hl_attr = is_hilited_attr(pos, pos+1, 0, &matches);
if (hl_attr == 0 && status_line)
hl_attr = line_mark_attr;
}
if (hl_attr)
{
/*
Expand Down Expand Up @@ -1202,6 +1212,14 @@ pdone(endline, chopped, forw)
add_attr_normal();
}

/*
* If we're coloring a status line, fill out the line with spaces.
*/
if (status_line && line_mark_attr != 0) {
while (end_column +1 < sc_width + cshift)
add_linebuf(' ', line_mark_attr, 1);
}

/*
* Add a newline if necessary,
* and append a '\0' to the end of the line.
Expand Down Expand Up @@ -1459,11 +1477,11 @@ load_line(str)
prewind();
if (pappstr(str) == 0)
break;
/*
* Didn't fit on screen; increase left shift by one.
* {{ This gets very inefficient if the string
* is much longer than the screen width. }}
*/
/*
* Didn't fit on screen; increase left shift by one.
* {{ This gets very inefficient if the string
* is much longer than the screen width. }}
*/
hshift += 1;
}
set_linebuf(linebuf.end, '\0', AT_NORMAL);
Expand Down
10 changes: 10 additions & 0 deletions opttbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public int status_col_width; /* Width of status column */
public int incr_search; /* Incremental search */
public int use_color; /* Use UI color */
public int want_filesize; /* */
public int status_line; /* */
#if HILITE_SEARCH
public int hilite_search; /* Highlight matched search patterns? */
#endif
Expand Down Expand Up @@ -139,6 +140,7 @@ static struct optname status_col_width_optname = { "status-col-width", NULL };
static struct optname incr_search_optname = { "incsearch", NULL };
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 };
#if LESSTEST
static struct optname ttyin_name_optname = { "tty", NULL };
static struct optname rstat_optname = { "rstat", NULL };
Expand Down Expand Up @@ -562,6 +564,14 @@ static struct loption option[] =
NULL
}
},
{ OLETTER_NONE, &status_line_optname,
BOOL|REPAINT, OPT_OFF, &status_line, NULL,
{
"Don't color each line with its status column color",
"Color each line with its status column color",
NULL
}
},
#if LESSTEST
{ OLETTER_NONE, &ttyin_name_optname,
STRING|NO_TOGGLE, 0, NULL, opt_ttyin_name,
Expand Down
2 changes: 1 addition & 1 deletion version.c
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ v589 5/29/21 Copyright & build changes.
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
v592 Add --status-line option.
*/

char version[] = "592x";

0 comments on commit 465a0b3

Please sign in to comment.