2 * Copyright (C) 1984-2014 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;
40 extern char *tagoption;
44 * Sound the bell to indicate user is trying to move past end of file.
49 if (quiet == NOT_QUIET)
56 * Check to see if the end of file is currently displayed.
66 if (ch_length() == NULL_POSITION)
68 * If the file length is not known,
69 * we can't possibly be displaying EOF.
74 * If the bottom line is empty, we are at EOF.
75 * If the bottom line ends at the file length,
76 * we must be just at EOF.
78 pos = position(BOTTOM_PLUS_ONE);
79 return (pos == NULL_POSITION || pos == ch_length());
83 * Check to see if the entire file is currently displayed.
86 entire_file_displayed()
90 /* Make sure last line of file is displayed. */
94 /* Make sure first line of file is displayed. */
96 return (pos == NULL_POSITION || pos == 0);
100 * If the screen is "squished", repaint it.
101 * "Squished" means the first displayed line is not at the top
102 * of the screen; this can happen when we display a short file
103 * for the first time.
115 * Display n lines, scrolling forward,
116 * starting at position pos in the input file.
117 * "force" means display the n lines even if we hit end of file.
118 * "only_last" means display only the last screenful if n > screen size.
119 * "nblank" is the number of blank lines to draw before the first
120 * real line. If nblank > 0, the pos must be NULL_POSITION.
121 * The first real line after the blanks will start at ch_zero().
124 forw(n, pos, force, only_last, nblank)
134 static int first_time = 1;
139 * do_repaint tells us not to display anything till the end,
140 * then just repaint the entire screen.
141 * We repaint if we are supposed to display only the last
142 * screenful and the request is for more than a screenful.
143 * Also if the request exceeds the forward scroll limit
144 * (but not if the request is for exactly a screenful, since
145 * repainting itself involves scrolling forward a screenful).
147 do_repaint = (only_last && n > sc_height-1) ||
148 (forw_scroll >= 0 && n > forw_scroll && n != sc_height-1);
151 prep_hilite(pos, pos + 3*size_linebuf, ignore_eoi ? 1 : -1);
152 pos = next_unfiltered(pos);
157 if (top_scroll && n >= sc_height - 1 && pos != ch_length())
160 * Start a new screen.
161 * {{ This is not really desirable if we happen
162 * to hit eof in the middle of this screen,
163 * but we don't yet know if that will happen. }}
172 if (pos != position(BOTTOM_PLUS_ONE) || empty_screen())
175 * This is not contiguous with what is
176 * currently displayed. Clear the screen image
177 * (position table) and start a new screen.
186 } else if (!first_time)
188 putstr("...skipping...\n");
196 * Read the next line of input.
201 * Still drawing blanks; don't get a line
203 * If this is the last blank line, get ready to
204 * read a line starting at ch_zero() next time.
211 * Get the next line from the file.
213 pos = forw_line(pos);
215 pos = next_unfiltered(pos);
217 if (pos == NULL_POSITION)
220 * End of file: stop here unless the top line
221 * is still empty, or "force" is true.
222 * Even if force is true, stop when the last
223 * line in the file reaches the top of screen.
226 if (!force && position(TOP) != NULL_POSITION)
228 if (!empty_lines(0, 0) &&
229 !empty_lines(1, 1) &&
230 empty_lines(2, sc_height-1))
235 * Add the position of the next line to the position table.
236 * Display the current line on the screen.
243 * If this is the first screen displayed and
244 * we hit an early EOF (i.e. before the requested
245 * number of lines), we "squish" the display down
246 * at the bottom of the screen.
247 * But don't do this if a + option or a -t option
248 * was given. These options can cause us to
249 * start the display after the beginning of the file,
250 * and it is not appropriate to squish in that case.
252 if (first_time && pos == NULL_POSITION && !top_scroll &&
264 * Can't call clear_eol here. The cursor might be at end of line
265 * on an ignaw terminal, so clear_eol would clear the last char
266 * of the current line instead of all of the next line.
267 * If we really need to do this on clear_bg terminals, we need
268 * to find a better way.
271 if (clear_bg && apply_at_specials(final_attr) != AT_NORMAL)
274 * Writing the last character on the last line
275 * of the display may have scrolled the screen.
276 * If we were in standout mode, clear_bg terminals
277 * will fill the new line with the standout color.
278 * Now we're in normal mode again, so clear the line.
286 if (nlines == 0 && same_pos_bell)
291 (void) currline(BOTTOM);
295 * Display n lines, scrolling backward.
298 back(n, pos, force, only_last)
308 do_repaint = (n > get_back_scroll() || (only_last && n > sc_height-1));
310 prep_hilite((pos < 3*size_linebuf) ? 0 : pos - 3*size_linebuf, pos, -1);
315 * Get the previous line of input.
318 pos = prev_unfiltered(pos);
321 pos = back_line(pos);
322 if (pos == NULL_POSITION)
325 * Beginning of file: stop here unless "force" is true.
331 * Add the position of the previous line to the position table.
332 * Display the line on the screen.
344 if (nlines == 0 && same_pos_bell)
350 (void) currline(BOTTOM);
354 * Display n more lines, forward.
355 * Start just after the line currently displayed at the bottom of the screen.
358 forward(n, force, only_last)
365 if (get_quit_at_eof() && eof_displayed() && !(ch_getflags() & CH_HELPFILE))
368 * If the -e flag is set and we're trying to go
369 * forward from end-of-file, go on to the next file.
376 pos = position(BOTTOM_PLUS_ONE);
377 if (pos == NULL_POSITION && (!force || empty_lines(2, sc_height-1)))
382 * ignore_eoi is to support A_F_FOREVER.
383 * Back up until there is a line at the bottom
392 back(1, position(TOP), 1, 0);
393 pos = position(BOTTOM_PLUS_ONE);
394 } while (pos == NULL_POSITION);
402 forw(n, pos, force, only_last, 0);
406 * Display n more lines, backward.
407 * Start just before the line currently displayed at the top of the screen.
410 backward(n, force, only_last)
418 if (pos == NULL_POSITION && (!force || position(BOTTOM) == 0))
423 back(n, pos, force, only_last);
427 * Get the backwards scroll limit.
428 * Must call this function instead of just using the value of
429 * back_scroll, because the default case depends on sc_height and
430 * top_scroll, as well as back_scroll.
437 if (back_scroll >= 0)
438 return (back_scroll);
440 return (sc_height - 2);
441 return (10000); /* infinity */