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
)
133 static int first_time
= 1;
138 * do_repaint tells us not to display anything till the end,
139 * then just repaint the entire screen.
140 * We repaint if we are supposed to display only the last
141 * screenful and the request is for more than a screenful.
142 * Also if the request exceeds the forward scroll limit
143 * (but not if the request is for exactly a screenful, since
144 * repainting itself involves scrolling forward a screenful).
146 do_repaint
= (only_last
&& n
> sc_height
-1) ||
147 (forw_scroll
>= 0 && n
> forw_scroll
&& n
!= sc_height
-1);
150 prep_hilite(pos
, pos
+ 3*size_linebuf
, ignore_eoi
? 1 : -1);
151 pos
= next_unfiltered(pos
);
156 if (top_scroll
&& n
>= sc_height
- 1 && pos
!= ch_length())
159 * Start a new screen.
160 * {{ This is not really desirable if we happen
161 * to hit eof in the middle of this screen,
162 * but we don't yet know if that will happen. }}
171 if (pos
!= position(BOTTOM_PLUS_ONE
) || empty_screen())
174 * This is not contiguous with what is
175 * currently displayed. Clear the screen image
176 * (position table) and start a new screen.
185 } else if (!first_time
)
187 putstr("...skipping...\n");
195 * Read the next line of input.
200 * Still drawing blanks; don't get a line
202 * If this is the last blank line, get ready to
203 * read a line starting at ch_zero() next time.
210 * Get the next line from the file.
212 pos
= forw_line(pos
);
214 pos
= next_unfiltered(pos
);
216 if (pos
== NULL_POSITION
)
219 * End of file: stop here unless the top line
220 * is still empty, or "force" is true.
221 * Even if force is true, stop when the last
222 * line in the file reaches the top of screen.
224 if (!force
&& position(TOP
) != NULL_POSITION
)
226 if (!empty_lines(0, 0) &&
227 !empty_lines(1, 1) &&
228 empty_lines(2, sc_height
-1))
233 * Add the position of the next line to the position table.
234 * Display the current line on the screen.
241 * If this is the first screen displayed and
242 * we hit an early EOF (i.e. before the requested
243 * number of lines), we "squish" the display down
244 * at the bottom of the screen.
245 * But don't do this if a + option or a -t option
246 * was given. These options can cause us to
247 * start the display after the beginning of the file,
248 * and it is not appropriate to squish in that case.
250 if (first_time
&& pos
== NULL_POSITION
&& !top_scroll
&&
262 * Can't call clear_eol here. The cursor might be at end of line
263 * on an ignaw terminal, so clear_eol would clear the last char
264 * of the current line instead of all of the next line.
265 * If we really need to do this on clear_bg terminals, we need
266 * to find a better way.
269 if (clear_bg
&& apply_at_specials(final_attr
) != AT_NORMAL
)
272 * Writing the last character on the last line
273 * of the display may have scrolled the screen.
274 * If we were in standout mode, clear_bg terminals
275 * will fill the new line with the standout color.
276 * Now we're in normal mode again, so clear the line.
284 if (nlines
== 0 && same_pos_bell
)
289 (void) currline(BOTTOM
);
293 * Display n lines, scrolling backward.
296 back(n
, pos
, force
, only_last
)
306 do_repaint
= (n
> get_back_scroll() || (only_last
&& n
> sc_height
-1));
308 prep_hilite((pos
< 3*size_linebuf
) ? 0 : pos
- 3*size_linebuf
, pos
, -1);
313 * Get the previous line of input.
316 pos
= prev_unfiltered(pos
);
319 pos
= back_line(pos
);
320 if (pos
== NULL_POSITION
)
323 * Beginning of file: stop here unless "force" is true.
329 * Add the position of the previous line to the position table.
330 * Display the line on the screen.
342 if (nlines
== 0 && same_pos_bell
)
348 (void) currline(BOTTOM
);
352 * Display n more lines, forward.
353 * Start just after the line currently displayed at the bottom of the screen.
356 forward(n
, force
, only_last
)
363 if (get_quit_at_eof() && eof_displayed() && !(ch_getflags() & CH_HELPFILE
))
366 * If the -e flag is set and we're trying to go
367 * forward from end-of-file, go on to the next file.
374 pos
= position(BOTTOM_PLUS_ONE
);
375 if (pos
== NULL_POSITION
&& (!force
|| empty_lines(2, sc_height
-1)))
380 * ignore_eoi is to support A_F_FOREVER.
381 * Back up until there is a line at the bottom
390 back(1, position(TOP
), 1, 0);
391 pos
= position(BOTTOM_PLUS_ONE
);
392 } while (pos
== NULL_POSITION
);
400 forw(n
, pos
, force
, only_last
, 0);
404 * Display n more lines, backward.
405 * Start just before the line currently displayed at the top of the screen.
408 backward(n
, force
, only_last
)
416 if (pos
== NULL_POSITION
&& (!force
|| position(BOTTOM
) == 0))
421 back(n
, pos
, force
, only_last
);
425 * Get the backwards scroll limit.
426 * Must call this function instead of just using the value of
427 * back_scroll, because the default case depends on sc_height and
428 * top_scroll, as well as back_scroll.
435 if (back_scroll
>= 0)
436 return (back_scroll
);
438 return (sc_height
- 2);
439 return (10000); /* infinity */