2 * Copyright (C) 1984-2012 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;
25 extern int top_scroll;
27 extern int sc_width, sc_height;
28 extern int plusoption;
29 extern int forw_scroll;
30 extern int back_scroll;
31 extern int ignore_eoi;
33 extern int final_attr;
36 extern char *tagoption;
40 * Sound the bell to indicate user is trying to move past end of file.
45 if (quiet == NOT_QUIET)
52 * Check to see if the end of file is currently displayed.
62 if (ch_length() == NULL_POSITION)
64 * If the file length is not known,
65 * we can't possibly be displaying EOF.
70 * If the bottom line is empty, we are at EOF.
71 * If the bottom line ends at the file length,
72 * we must be just at EOF.
74 pos = position(BOTTOM_PLUS_ONE);
75 return (pos == NULL_POSITION || pos == ch_length());
79 * Check to see if the entire file is currently displayed.
82 entire_file_displayed()
86 /* Make sure last line of file is displayed. */
90 /* Make sure first line of file is displayed. */
92 return (pos == NULL_POSITION || pos == 0);
96 * If the screen is "squished", repaint it.
97 * "Squished" means the first displayed line is not at the top
98 * of the screen; this can happen when we display a short file
111 * Display n lines, scrolling forward,
112 * starting at position pos in the input file.
113 * "force" means display the n lines even if we hit end of file.
114 * "only_last" means display only the last screenful if n > screen size.
115 * "nblank" is the number of blank lines to draw before the first
116 * real line. If nblank > 0, the pos must be NULL_POSITION.
117 * The first real line after the blanks will start at ch_zero().
120 forw(n, pos, force, only_last, nblank)
130 static int first_time = 1;
135 * do_repaint tells us not to display anything till the end,
136 * then just repaint the entire screen.
137 * We repaint if we are supposed to display only the last
138 * screenful and the request is for more than a screenful.
139 * Also if the request exceeds the forward scroll limit
140 * (but not if the request is for exactly a screenful, since
141 * repainting itself involves scrolling forward a screenful).
143 do_repaint = (only_last && n > sc_height-1) ||
144 (forw_scroll >= 0 && n > forw_scroll && n != sc_height-1);
148 if (top_scroll && n >= sc_height - 1 && pos != ch_length())
151 * Start a new screen.
152 * {{ This is not really desirable if we happen
153 * to hit eof in the middle of this screen,
154 * but we don't yet know if that will happen. }}
163 if (pos != position(BOTTOM_PLUS_ONE) || empty_screen())
166 * This is not contiguous with what is
167 * currently displayed. Clear the screen image
168 * (position table) and start a new screen.
177 } else if (!first_time)
179 putstr("...skipping...\n");
187 * Read the next line of input.
192 * Still drawing blanks; don't get a line
194 * If this is the last blank line, get ready to
195 * read a line starting at ch_zero() next time.
202 * Get the next line from the file.
204 pos = forw_line(pos);
205 if (pos == NULL_POSITION)
208 * End of file: stop here unless the top line
209 * is still empty, or "force" is true.
210 * Even if force is true, stop when the last
211 * line in the file reaches the top of screen.
214 if (!force && position(TOP) != NULL_POSITION)
216 if (!empty_lines(0, 0) &&
217 !empty_lines(1, 1) &&
218 empty_lines(2, sc_height-1))
223 * Add the position of the next line to the position table.
224 * Display the current line on the screen.
231 * If this is the first screen displayed and
232 * we hit an early EOF (i.e. before the requested
233 * number of lines), we "squish" the display down
234 * at the bottom of the screen.
235 * But don't do this if a + option or a -t option
236 * was given. These options can cause us to
237 * start the display after the beginning of the file,
238 * and it is not appropriate to squish in that case.
240 if (first_time && pos == NULL_POSITION && !top_scroll &&
252 * Can't call clear_eol here. The cursor might be at end of line
253 * on an ignaw terminal, so clear_eol would clear the last char
254 * of the current line instead of all of the next line.
255 * If we really need to do this on clear_bg terminals, we need
256 * to find a better way.
259 if (clear_bg && apply_at_specials(final_attr) != AT_NORMAL)
262 * Writing the last character on the last line
263 * of the display may have scrolled the screen.
264 * If we were in standout mode, clear_bg terminals
265 * will fill the new line with the standout color.
266 * Now we're in normal mode again, so clear the line.
279 (void) currline(BOTTOM);
283 * Display n lines, scrolling backward.
286 back(n, pos, force, only_last)
296 do_repaint = (n > get_back_scroll() || (only_last && n > sc_height-1));
300 * Get the previous line of input.
302 pos = back_line(pos);
303 if (pos == NULL_POSITION)
306 * Beginning of file: stop here unless "force" is true.
312 * Add the position of the previous line to the position table.
313 * Display the line on the screen.
331 (void) currline(BOTTOM);
335 * Display n more lines, forward.
336 * Start just after the line currently displayed at the bottom of the screen.
339 forward(n, force, only_last)
346 if (get_quit_at_eof() && eof_displayed() && !(ch_getflags() & CH_HELPFILE))
349 * If the -e flag is set and we're trying to go
350 * forward from end-of-file, go on to the next file.
357 pos = position(BOTTOM_PLUS_ONE);
358 if (pos == NULL_POSITION && (!force || empty_lines(2, sc_height-1)))
363 * ignore_eoi is to support A_F_FOREVER.
364 * Back up until there is a line at the bottom
373 back(1, position(TOP), 1, 0);
374 pos = position(BOTTOM_PLUS_ONE);
375 } while (pos == NULL_POSITION);
383 forw(n, pos, force, only_last, 0);
387 * Display n more lines, backward.
388 * Start just before the line currently displayed at the top of the screen.
391 backward(n, force, only_last)
399 if (pos == NULL_POSITION && (!force || position(BOTTOM) == 0))
404 back(n, pos, force, only_last);
408 * Get the backwards scroll limit.
409 * Must call this function instead of just using the value of
410 * back_scroll, because the default case depends on sc_height and
411 * top_scroll, as well as back_scroll.
418 if (back_scroll >= 0)
419 return (back_scroll);
421 return (sc_height - 2);
422 return (10000); /* infinity */