Skip to content

Commit

Permalink
Add --intr option.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Jan 7, 2023
1 parent 3e6697e commit 7a930a4
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 25 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

* Add --modelines option (github #89).

* Add --intr option (github #224).

* Allow empty "lines" field in --header option.

* Update Unicode tables.
Expand Down
20 changes: 11 additions & 9 deletions less.hlp
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,12 @@
Use N lines and M columns to display file headers.
--incsearch
Search file as each pattern character is typed in.
--line-num-width=N
Set the width of the -N line number field to N characters.
--modelines=N
Read N lines from the input file and look for vim modelines.
--intr=_C
Use _C instead of ^X to interrupt a read.
--line-num-width=_N
Set the width of the -N line number field to _N characters.
--modelines=_N
Read _N lines from the input file and look for vim modelines.
--mouse
Enable mouse input.
--no-keypad
Expand All @@ -235,22 +237,22 @@
Disable the terminal's visual bell.
--redraw-on-quit
Redraw final screen when quitting.
--rscroll=C
--rscroll=_C
Set the character used to mark truncated lines.
--save-marks
Retain marks across invocations of less.
--search-options=[EFKNRW-]
Set default options for every search.
--status-col-width=N
Set the width of the -J status column to N characters.
--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
Enables colored text.
--wheel-lines=N
Each click of the mouse wheel moves N lines.
--wheel-lines=_N
Each click of the mouse wheel moves _N lines.


---------------------------------------------------------------------------
Expand Down
13 changes: 11 additions & 2 deletions less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ while it is being viewed.
To stop waiting for more data, enter the interrupt character (usually \(haC).
On systems which support
.BR poll (1)
you can also use \(haX.
you can also use \(haX or the character specified by the \-\-intr option.
If the input is a pipe and the \-\-exit-follow-on-close option is in effect,
.B less
will automatically stop waiting for data when the input side
Expand Down Expand Up @@ -470,7 +470,9 @@ This may cause
.B less
to think that the file ends at the current position,
so it may be necessary to use the R or F command to see more data.
The \(haX command works only on systems that support the
The \-\-intr option can be used to specify a different character
to use instead of \(haX.
This command works only on systems that support the
.BR poll (1)
function.
On systems without
Expand Down Expand Up @@ -1174,6 +1176,13 @@ Subsequent search commands will be "incremental"; that is,
.B less
will advance to the next line containing the search pattern
as each character of the pattern is typed in.
.IP "\-\-intr=\fIc\fP"
Use the character \fIc\fP instead of \(haX to interrupt a read
when the "Waiting for data" message is displayed.
\fIc\fP must be an ASCII character; that is, one with a value
between 1 and 127 inclusive.
A caret followed by a single character can be used
to specify a control character.
.IP "\-\-line-num-width=\fIn\fP"
Sets the minimum width of the line number field when the \-N option is in effect
to \fIn\fP characters.
Expand Down
2 changes: 1 addition & 1 deletion lesstest/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CC = gcc
CC ?= gcc
CFLAGS = -Wall -O2
TERMLIB = -lncurses

Expand Down
26 changes: 25 additions & 1 deletion optfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ extern int chopline;
extern int tabstops[];
extern int ntabstops;
extern int tabdefault;
extern char intr_char;
#if LOGFILE
extern char *namelogfile;
extern int force_logfile;
Expand Down Expand Up @@ -793,7 +794,7 @@ public void opt_rscroll(int type, char *s)
break; }
case QUERY: {
p.p_string = rscroll_char ? prchar(rscroll_char) : "-";
error("rscroll char is %s", &p);
error("rscroll character is %s", &p);
break; }
}
}
Expand Down Expand Up @@ -920,6 +921,29 @@ public void opt_filesize(int type, char *s)
}
}

/*
* Handler for the --intr option.
*/
/*ARGSUSED*/
public void opt_intr(int type, char *s)
{
PARG p;

switch (type)
{
case INIT:
case TOGGLE:
intr_char = *s;
if (intr_char == '^' && s[1] != '\0')
intr_char = CONTROL(s[1]);
break;
case QUERY: {
p.p_string = prchar(intr_char);
error("interrupt character is %s", &p);
break; }
}
}

/*
* Handler for the --header option.
*/
Expand Down
8 changes: 7 additions & 1 deletion opttbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public int redraw_on_quit; /* Redraw last screen after term deinit */
public int def_search_type; /* */
public int exit_F_on_close; /* Exit F command when input closes */
public int modelines; /* Lines to read looking for modelines */
public char intr_char = CONTROL('X'); /* Char to interrupt reads */
#if HILITE_SEARCH
public int hilite_search; /* Highlight matched search patterns? */
#endif
Expand Down Expand Up @@ -158,6 +159,7 @@ static struct optname search_type_optname = { "search-options", NULL };
static struct optname exit_F_on_close_optname = { "exit-follow-on-close", NULL };
static struct optname modelines_optname = { "modelines", NULL };
static struct optname no_vbell_optname = { "no-vbell", NULL };
static struct optname intr_optname = { "intr", NULL };
#if LESSTEST
static struct optname ttyin_name_optname = { "tty", NULL };
#endif /*LESSTEST*/
Expand Down Expand Up @@ -506,7 +508,7 @@ static struct loption option[] =
},
{ OLETTER_NONE, &rscroll_optname,
STRING|REPAINT|INIT_HANDLER, 0, NULL, opt_rscroll,
{ "right scroll character: ", NULL, NULL }
{ "rscroll character: ", NULL, NULL }
},
{ OLETTER_NONE, &nohistdups_optname,
BOOL, OPT_OFF, &no_hist_dups, NULL,
Expand Down Expand Up @@ -652,6 +654,10 @@ static struct loption option[] =
NULL
}
},
{ OLETTER_NONE, &intr_optname,
STRING, 0, NULL, opt_intr,
{ "interrupt character: ", NULL, NULL }
},
#if LESSTEST
{ OLETTER_NONE, &ttyin_name_optname,
STRING|NO_TOGGLE, 0, NULL, opt_ttyin_name,
Expand Down
5 changes: 3 additions & 2 deletions os.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ extern int sigs;
extern int ignore_eoi;
extern int exit_F_on_close;
extern int follow_mode;
extern char intr_char;
#if !MSDOS_COMPILER
extern int tty;
#endif
Expand Down Expand Up @@ -111,7 +112,7 @@ static int check_poll(int fd, int tty)
if (poller[1].revents & POLLIN)
{
LWCHAR ch = getchr();
if (ch == CONTROL('X'))
if (ch == intr_char)
/* Break out of "waiting for data". */
return (READ_INTR);
ungetcc_back(ch);
Expand Down Expand Up @@ -223,7 +224,7 @@ public int iread(int fd, unsigned char *buf, unsigned int len)
}
#else
#if MSDOS_COMPILER==WIN32C
if (win32_kbhit() && WIN32getch() == CONTROL('X'))
if (win32_kbhit() && WIN32getch() == intr_char)
{
sigs |= S_INTERRUPT;
reading = 0;
Expand Down
16 changes: 8 additions & 8 deletions output.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern int so_s_width, so_e_width;
extern int screen_trashed;
extern int is_tty;
extern int oldbot;
extern char intr_char;

#if MSDOS_COMPILER==WIN32C || MSDOS_COMPILER==BORLANDC || MSDOS_COMPILER==DJGPPC
extern int ctldisp;
Expand Down Expand Up @@ -661,33 +662,32 @@ public void error(char *fmt, PARG *parg)
* Usually used to warn that we are beginning a potentially
* time-consuming operation.
*/
static void ierror_suffix(char *fmt, char *suffix, PARG *parg)
static void ierror_suffix(char *fmt, PARG *parg, char *suffix1, char *suffix2, char *suffix3)
{
at_exit();
clear_bot();
at_enter(AT_STANDOUT|AT_COLOR_ERROR);
(void) less_printf(fmt, parg);
putstr(suffix);
putstr(suffix1);
putstr(suffix2);
putstr(suffix3);
at_exit();
flush();
need_clr = 1;
}

public void ierror(char *fmt, PARG *parg)
{
static char suffix[] = "... (interrupt to abort)";
ierror_suffix(fmt, suffix, parg);
ierror_suffix(fmt, parg, "... (interrupt to abort)", "", "");
}

public void ixerror(char *fmt, PARG *parg)
{
if (!supports_ctrl_x())
ierror(fmt, parg);
else
{
static char suffix[] = "... (^X or interrupt to abort)";
ierror_suffix(fmt, suffix, parg);
}
ierror_suffix(fmt, parg,
"... (", prchar(intr_char), " or interrupt to abort)");
}

/*
Expand Down
2 changes: 1 addition & 1 deletion version.c
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ v616 12/9/22 Don't open tty as input file without -f.
v617 12/10/22 Support poll on newer versions of MacOS.
v618 12/29/22 Add --no-search-headers option; use C89 function definitions.
v619 12/30/22 Fix bug using 'n' before '/'.
v620 Add --modelines option.
v620 Add --modelines option; add --intr option.
*/

char version[] = "620x";

0 comments on commit 7a930a4

Please sign in to comment.