1: \ Forth output paging add-on (like more(1))
2:
3: \ Copyright (C) 1996,2000,2003 Free Software Foundation, Inc.
4:
5: \ This file is part of Gforth.
6:
7: \ Gforth is free software; you can redistribute it and/or
8: \ modify it under the terms of the GNU General Public License
9: \ as published by the Free Software Foundation, either version 3
10: \ of the License, or (at your option) any later version.
11:
12: \ This program is distributed in the hope that it will be useful,
13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: \ GNU General Public License for more details.
16:
17: \ You should have received a copy of the GNU General Public License
18: \ along with this program. If not, see http://www.gnu.org/licenses/.
19:
20:
21: \ This add-on is for those poor souls whose terminals cannot scroll
22: \ back but who want to read the output of 'words' at their leisure.
23:
24: \ currently this is very primitive: it just counts newlines, and only
25: \ allows continuing for another page (and of course, terminating
26: \ processing by sending a signal (^C))
27:
28: \ Some things to do:
29: \ allow continuing for one line (Enter)
30: \ count lines produced by wraparound (note tabs and backspaces)
31: \ allow continuing silently
32: \ fancy features like searching, scrollback etc.
33:
34: \ one more-or-less simple way to achieve all this is to
35: \ popen("less","w") and output there. Before getting the next `key`,
36: \ we would perform a pclose. This idea due to Marcel Hendrix.
37:
38: require termsize.fs
39:
40: variable last-#lines 0 last-#lines !
41:
42: :noname ( -- c )
43: 1 last-#lines !
44: defers key ;
45: is key
46:
47: :noname ( c -- )
48: dup defers emit
49: #lf =
50: if
51: 1 last-#lines +!
52: last-#lines @ rows >=
53: if
54: ." ... more ?" key drop 10 backspaces 10 spaces 10 backspaces
55: endif
56: endif ;
57: is emit
58:
59: :noname ( c-addr u -- )
60: bounds
61: ?DO
62: I c@ emit
63: LOOP ;
64: is type
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>