2 * Copyright (C) 1984-2015 Mark Nudelman
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
7 * For more information, see the README file.
12 * Primitives for displaying the file on the screen,
13 * scrolling either forward or backward.
19 public int screen_trashed
;
21 public int no_back_scroll
= 0;
22 public int forw_prompt
;
23 public int same_pos_bell
= 1;
26 extern int top_scroll
;
28 extern int sc_width
, sc_height
;
29 extern int plusoption
;
30 extern int forw_scroll
;
31 extern int back_scroll
;
32 extern int ignore_eoi
;
34 extern int final_attr
;
37 extern int size_linebuf
;
38 extern int hilite_search
;
39 extern int status_col
;
42 extern char *tagoption
;
46 * Sound the bell to indicate user is trying to move past end of file.
51 if (quiet
== NOT_QUIET
)
58 * Check to see if the end of file is currently displayed.
68 if (ch_length() == NULL_POSITION
)
70 * If the file length is not known,
71 * we can't possibly be displaying EOF.
76 * If the bottom line is empty, we are at EOF.
77 * If the bottom line ends at the file length,
78 * we must be just at EOF.
80 pos
= position(BOTTOM_PLUS_ONE
);
81 return (pos
== NULL_POSITION
|| pos
== ch_length());
85 * Check to see if the entire file is currently displayed.
88 entire_file_displayed()
92 /* Make sure last line of file is displayed. */
96 /* Make sure first line of file is displayed. */
98 return (pos
== NULL_POSITION
|| pos
== 0);
102 * If the screen is "squished", repaint it.
103 * "Squished" means the first displayed line is not at the top
104 * of the screen; this can happen when we display a short file
105 * for the first time.
117 * Display n lines, scrolling forward,
118 * starting at position pos in the input file.
119 * "force" means display the n lines even if we hit end of file.
120 * "only_last" means display only the last screenful if n > screen size.
121 * "nblank" is the number of blank lines to draw before the first
122 * real line. If nblank > 0, the pos must be NULL_POSITION.
123 * The first real line after the blanks will start at ch_zero().
126 forw(n
, pos
, force
, only_last
, nblank
)
135 static int first_time
= 1;
140 * do_repaint tells us not to display anything till the end,
141 * then just repaint the entire screen.
142 * We repaint if we are supposed to display only the last
143 * screenful and the request is for more than a screenful.
144 * Also if the request exceeds the forward scroll limit
145 * (but not if the request is for exactly a screenful, since
146 * repainting itself involves scrolling forward a screenful).
148 do_repaint
= (only_last
&& n
> sc_height
-1) ||
149 (forw_scroll
>= 0 && n
> forw_scroll
&& n
!= sc_height
-1);
152 if (hilite_search
== OPT_ONPLUS
|| is_filtering() || status_col
) {
153 prep_hilite(pos
, pos
+ 4*size_linebuf
, ignore_eoi
? 1 : -1);
154 pos
= next_unfiltered(pos
);
160 if (top_scroll
&& n
>= sc_height
- 1 && pos
!= ch_length())
163 * Start a new screen.
164 * {{ This is not really desirable if we happen
165 * to hit eof in the middle of this screen,
166 * but we don't yet know if that will happen. }}
175 if (pos
!= position(BOTTOM_PLUS_ONE
) || empty_screen())
178 * This is not contiguous with what is
179 * currently displayed. Clear the screen image
180 * (position table) and start a new screen.
189 } else if (!first_time
)
191 putstr("...skipping...\n");
199 * Read the next line of input.
204 * Still drawing blanks; don't get a line
206 * If this is the last blank line, get ready to
207 * read a line starting at ch_zero() next time.
214 * Get the next line from the file.
216 pos
= forw_line(pos
);
218 pos
= next_unfiltered(pos
);
220 if (pos
== NULL_POSITION
)
223 * End of file: stop here unless the top line
224 * is still empty, or "force" is true.
225 * Even if force is true, stop when the last
226 * line in the file reaches the top of screen.
228 if (!force
&& position(TOP
) != NULL_POSITION
)
230 if (!empty_lines(0, 0) &&
231 !empty_lines(1, 1) &&
232 empty_lines(2, sc_height
-1))
237 * Add the position of the next line to the position table.
238 * Display the current line on the screen.
245 * If this is the first screen displayed and
246 * we hit an early EOF (i.e. before the requested
247 * number of lines), we "squish" the display down
248 * at the bottom of the screen.
249 * But don't do this if a + option or a -t option
250 * was given. These options can cause us to
251 * start the display after the beginning of the file,
252 * and it is not appropriate to squish in that case.
254 if (first_time
&& pos
== NULL_POSITION
&& !top_scroll
&&
266 * Can't call clear_eol here. The cursor might be at end of line
267 * on an ignaw terminal, so clear_eol would clear the last char
268 * of the current line instead of all of the next line.
269 * If we really need to do this on clear_bg terminals, we need
270 * to find a better way.
273 if (clear_bg
&& apply_at_specials(final_attr
) != AT_NORMAL
)
276 * Writing the last character on the last line
277 * of the display may have scrolled the screen.
278 * If we were in standout mode, clear_bg terminals
279 * will fill the new line with the standout color.
280 * Now we're in normal mode again, so clear the line.
288 if (nlines
== 0 && same_pos_bell
)
293 (void) currline(BOTTOM
);
297 * Display n lines, scrolling backward.
300 back(n
, pos
, force
, only_last
)
310 do_repaint
= (n
> get_back_scroll() || (only_last
&& n
> sc_height
-1));
312 if (hilite_search
== OPT_ONPLUS
|| is_filtering() || status_col
) {
313 prep_hilite((pos
< 3*size_linebuf
) ? 0 : pos
- 3*size_linebuf
, pos
, -1);
319 * Get the previous line of input.
322 pos
= prev_unfiltered(pos
);
325 pos
= back_line(pos
);
326 if (pos
== NULL_POSITION
)
329 * Beginning of file: stop here unless "force" is true.
335 * Add the position of the previous line to the position table.
336 * Display the line on the screen.
348 if (nlines
== 0 && same_pos_bell
)
354 (void) currline(BOTTOM
);
358 * Display n more lines, forward.
359 * Start just after the line currently displayed at the bottom of the screen.
362 forward(n
, force
, only_last
)
369 if (get_quit_at_eof() && eof_displayed() && !(ch_getflags() & CH_HELPFILE
))
372 * If the -e flag is set and we're trying to go
373 * forward from end-of-file, go on to the next file.
380 pos
= position(BOTTOM_PLUS_ONE
);
381 if (pos
== NULL_POSITION
&& (!force
|| empty_lines(2, sc_height
-1)))
386 * ignore_eoi is to support A_F_FOREVER.
387 * Back up until there is a line at the bottom
396 back(1, position(TOP
), 1, 0);
397 pos
= position(BOTTOM_PLUS_ONE
);
398 } while (pos
== NULL_POSITION
);
406 forw(n
, pos
, force
, only_last
, 0);
410 * Display n more lines, backward.
411 * Start just before the line currently displayed at the top of the screen.
414 backward(n
, force
, only_last
)
422 if (pos
== NULL_POSITION
&& (!force
|| position(BOTTOM
) == 0))
427 back(n
, pos
, force
, only_last
);
431 * Get the backwards scroll limit.
432 * Must call this function instead of just using the value of
433 * back_scroll, because the default case depends on sc_height and
434 * top_scroll, as well as back_scroll.
441 if (back_scroll
>= 0)
442 return (back_scroll
);
444 return (sc_height
- 2);
445 return (10000); /* infinity */