3 * Copyright (C) 1984-2015 Mark Nudelman
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Less License, as specified in the README file.
8 * For more information, see the README file.
13 * Primitives for displaying the file on the screen,
14 * scrolling either forward or backward.
20 public int screen_trashed
;
22 public int no_back_scroll
= 0;
23 public int forw_prompt
;
24 public int same_pos_bell
= 1;
27 extern int top_scroll
;
29 extern int sc_width
, sc_height
;
30 extern int less_is_more
;
31 extern int plusoption
;
32 extern int forw_scroll
;
33 extern int back_scroll
;
34 extern int ignore_eoi
;
36 extern int final_attr
;
39 extern int size_linebuf
;
40 extern int hilite_search
;
41 extern int status_col
;
44 extern char *tagoption
;
48 * Sound the bell to indicate user is trying to move past end of file.
53 if (quiet
== NOT_QUIET
)
60 * Check to see if the end of file is currently displayed.
70 if (ch_length() == NULL_POSITION
)
72 * If the file length is not known,
73 * we can't possibly be displaying EOF.
78 * If the bottom line is empty, we are at EOF.
79 * If the bottom line ends at the file length,
80 * we must be just at EOF.
82 pos
= position(BOTTOM_PLUS_ONE
);
83 return (pos
== NULL_POSITION
|| pos
== ch_length());
87 * Check to see if the entire file is currently displayed.
90 entire_file_displayed()
94 /* Make sure last line of file is displayed. */
98 /* Make sure first line of file is displayed. */
100 return (pos
== NULL_POSITION
|| pos
== 0);
104 * If the screen is "squished", repaint it.
105 * "Squished" means the first displayed line is not at the top
106 * of the screen; this can happen when we display a short file
107 * for the first time.
119 * Display n lines, scrolling forward,
120 * starting at position pos in the input file.
121 * "force" means display the n lines even if we hit end of file.
122 * "only_last" means display only the last screenful if n > screen size.
123 * "nblank" is the number of blank lines to draw before the first
124 * real line. If nblank > 0, the pos must be NULL_POSITION.
125 * The first real line after the blanks will start at ch_zero().
128 forw(n
, pos
, force
, only_last
, nblank
)
137 static int first_time
= 1;
142 * do_repaint tells us not to display anything till the end,
143 * then just repaint the entire screen.
144 * We repaint if we are supposed to display only the last
145 * screenful and the request is for more than a screenful.
146 * Also if the request exceeds the forward scroll limit
147 * (but not if the request is for exactly a screenful, since
148 * repainting itself involves scrolling forward a screenful).
150 do_repaint
= (only_last
&& n
> sc_height
-1) ||
151 (forw_scroll
>= 0 && n
> forw_scroll
&& n
!= sc_height
-1);
154 if (hilite_search
== OPT_ONPLUS
|| is_filtering() || status_col
) {
155 prep_hilite(pos
, pos
+ 4*size_linebuf
, ignore_eoi
? 1 : -1);
156 pos
= next_unfiltered(pos
);
162 if (top_scroll
&& n
>= sc_height
- 1 && pos
!= ch_length())
165 * Start a new screen.
166 * {{ This is not really desirable if we happen
167 * to hit eof in the middle of this screen,
168 * but we don't yet know if that will happen. }}
173 if (less_is_more
== 0) {
179 if (pos
!= position(BOTTOM_PLUS_ONE
) || empty_screen())
182 * This is not contiguous with what is
183 * currently displayed. Clear the screen image
184 * (position table) and start a new screen.
193 } else if (!first_time
)
195 putstr("...skipping...\n");
203 * Read the next line of input.
208 * Still drawing blanks; don't get a line
210 * If this is the last blank line, get ready to
211 * read a line starting at ch_zero() next time.
218 * Get the next line from the file.
220 pos
= forw_line(pos
);
222 pos
= next_unfiltered(pos
);
224 if (pos
== NULL_POSITION
)
227 * End of file: stop here unless the top line
228 * is still empty, or "force" is true.
229 * Even if force is true, stop when the last
230 * line in the file reaches the top of screen.
232 if (!force
&& position(TOP
) != NULL_POSITION
)
234 if (!empty_lines(0, 0) &&
235 !empty_lines(1, 1) &&
236 empty_lines(2, sc_height
-1))
241 * Add the position of the next line to the position table.
242 * Display the current line on the screen.
249 * If this is the first screen displayed and
250 * we hit an early EOF (i.e. before the requested
251 * number of lines), we "squish" the display down
252 * at the bottom of the screen.
253 * But don't do this if a + option or a -t option
254 * was given. These options can cause us to
255 * start the display after the beginning of the file,
256 * and it is not appropriate to squish in that case.
258 if ((first_time
|| less_is_more
) &&
259 pos
== NULL_POSITION
&& !top_scroll
&&
271 * Can't call clear_eol here. The cursor might be at end of line
272 * on an ignaw terminal, so clear_eol would clear the last char
273 * of the current line instead of all of the next line.
274 * If we really need to do this on clear_bg terminals, we need
275 * to find a better way.
278 if (clear_bg
&& apply_at_specials(final_attr
) != AT_NORMAL
)
281 * Writing the last character on the last line
282 * of the display may have scrolled the screen.
283 * If we were in standout mode, clear_bg terminals
284 * will fill the new line with the standout color.
285 * Now we're in normal mode again, so clear the line.
293 if (nlines
== 0 && same_pos_bell
)
298 (void) currline(BOTTOM
);
302 * Display n lines, scrolling backward.
305 back(n
, pos
, force
, only_last
)
315 do_repaint
= (n
> get_back_scroll() || (only_last
&& n
> sc_height
-1));
317 if (hilite_search
== OPT_ONPLUS
|| is_filtering() || status_col
) {
318 prep_hilite((pos
< 3*size_linebuf
) ? 0 : pos
- 3*size_linebuf
, pos
, -1);
324 * Get the previous line of input.
327 pos
= prev_unfiltered(pos
);
330 pos
= back_line(pos
);
331 if (pos
== NULL_POSITION
)
334 * Beginning of file: stop here unless "force" is true.
340 * Add the position of the previous line to the position table.
341 * Display the line on the screen.
353 if (nlines
== 0 && same_pos_bell
)
359 (void) currline(BOTTOM
);
363 * Display n more lines, forward.
364 * Start just after the line currently displayed at the bottom of the screen.
367 forward(n
, force
, only_last
)
374 if (get_quit_at_eof() && eof_displayed() && !(ch_getflags() & CH_HELPFILE
))
377 * If the -e flag is set and we're trying to go
378 * forward from end-of-file, go on to the next file.
385 pos
= position(BOTTOM_PLUS_ONE
);
386 if (pos
== NULL_POSITION
&& (!force
|| empty_lines(2, sc_height
-1)))
391 * ignore_eoi is to support A_F_FOREVER.
392 * Back up until there is a line at the bottom
401 back(1, position(TOP
), 1, 0);
402 pos
= position(BOTTOM_PLUS_ONE
);
403 } while (pos
== NULL_POSITION
);
411 forw(n
, pos
, force
, only_last
, 0);
415 * Display n more lines, backward.
416 * Start just before the line currently displayed at the top of the screen.
419 backward(n
, force
, only_last
)
427 if (pos
== NULL_POSITION
&& (!force
|| position(BOTTOM
) == 0))
432 back(n
, pos
, force
, only_last
);
436 * Get the backwards scroll limit.
437 * Must call this function instead of just using the value of
438 * back_scroll, because the default case depends on sc_height and
439 * top_scroll, as well as back_scroll.
446 if (back_scroll
>= 0)
447 return (back_scroll
);
449 return (sc_height
- 2);
450 return (10000); /* infinity */