Skip to content

Commit

Permalink
Add --form-feed option.
Browse files Browse the repository at this point in the history
Related to #496.
  • Loading branch information
gwsw committed Jun 25, 2024
1 parent 22ac9f0 commit a0d1f5b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions forwback.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extern int ignore_eoi;
extern int header_lines;
extern int header_cols;
extern int full_screen;
extern int stop_on_form_feed;
extern POSITION header_start_pos;
#if HILITE_SEARCH
extern size_t size_linebuf;
Expand Down Expand Up @@ -345,6 +346,8 @@ public void forw(int n, POSITION pos, lbool force, lbool only_last, int nblank)
continue;
}
put_line();
if (stop_on_form_feed && !do_repaint && line_is_ff() && position(TOP) != NULL_POSITION)
break;
#if 0
/* {{
* Can't call clear_eol here. The cursor might be at end of line
Expand Down Expand Up @@ -431,6 +434,8 @@ public void back(int n, POSITION pos, lbool force, lbool only_last)
home();
add_line();
put_line();
if (stop_on_form_feed && line_is_ff())
break;
}
}
if (nlines == 0)
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 @@
Automatically determine the size of the input file.
--follow-name
The F command changes files if the input file is renamed.
--form-feed
Stop scrolling when a form feed character is reached.
--header=[_L[,_C[,_N]]]
Use _L lines (starting at line _N) and _C columns as headers.
--incsearch
Expand Down
4 changes: 4 additions & 0 deletions less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,10 @@ If the reopen succeeds and the file is a different file from the original
with the same name as the original (now renamed) file),
.B less
will display the contents of that new file.
.IP "\-\-form-feed"
When scrolling forward or backward in the file,
stop if a line beginning with a form feed character (\(haL) is reached.
This can be useful when viewing a file which uses form feeds between pages.
.IP "\-\-header=\fIL\fP,\fIC\fP,\fIN\fP"
.RS
Sets the number of header lines and columns displayed on the screen.
Expand Down
9 changes: 9 additions & 0 deletions line.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static int curr_last_ansi;
public size_t size_linebuf = 0; /* Size of line buffer (and attr buffer) */
static struct ansi_state *line_ansi = NULL;
static lbool ansi_in_line;
static int ff_starts_line;
static int hlink_in_line;
static int line_mark_attr;
static int cshift; /* Current left-shift of output line buffer */
Expand Down Expand Up @@ -252,6 +253,7 @@ public void prewind(void)
pendc = '\0';
in_hilite = 0;
ansi_in_line = FALSE;
ff_starts_line = -1;
hlink_in_line = 0;
line_mark_attr = 0;
line_pos = NULL_POSITION;
Expand Down Expand Up @@ -1038,9 +1040,16 @@ public int pappend_b(char c, POSITION pos, lbool before_pendc)

public int pappend(char c, POSITION pos)
{
if (ff_starts_line < 0)
ff_starts_line = (c == CONTROL('L'));
return pappend_b(c, pos, FALSE);
}

public lbool line_is_ff(void)
{
return (ff_starts_line == 1);
}

static int store_control_char(LWCHAR ch, constant char *rep, POSITION pos)
{
if (ctldisp == OPT_ON)
Expand Down
10 changes: 10 additions & 0 deletions opttbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public int proc_tab; /* Special handling of tab */
public int proc_return; /* Special handling of carriage return */
public int match_shift; /* Extra horizontal shift on search match */
public int no_paste; /* Don't accept pasted input */
public int stop_on_form_feed; /* Stop scrolling on a line starting with form feed */
public long match_shift_fraction = NUM_FRAC_DENOM/2; /* 1/2 of screen width */
public char intr_char = CONTROL('X'); /* Char to interrupt reads */
#if HILITE_SEARCH
Expand Down Expand Up @@ -163,6 +164,7 @@ 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 no_paste_optname = { "no-paste", NULL };
static struct optname form_feed_optname = { "form-feed", NULL };
static struct optname nonum_headers_optname = { "no-number-headers", NULL };
static struct optname nosearch_headers_optname = { "no-search-headers", NULL };
static struct optname nosearch_header_lines_optname = { "no-search-header-lines", NULL };
Expand Down Expand Up @@ -621,6 +623,14 @@ static struct loption option[] =
NULL
}
},
{ OLETTER_NONE, &form_feed_optname,
BOOL, OPT_OFF, &stop_on_form_feed, NULL,
{
"Don't stop on form feed",
"Stop on form feed",
NULL
}
},
{ OLETTER_NONE, &nonum_headers_optname,
BOOL|REPAINT, 0, &nonum_headers, NULL,
{
Expand Down

0 comments on commit a0d1f5b

Please sign in to comment.