Annotation of gforth/more.fs, revision 1.4
1.1 anton 1: \ Forth output paging add-on (like more(1))
2:
1.4 ! anton 3: \ Copyright (C) 1996,2000,2003 Free Software Foundation, Inc.
1.1 anton 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 2
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, write to the Free Software
1.2 anton 19: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
1.1 anton 20:
21:
22: \ This add-on is for those poor souls whose terminals cannot scroll
23: \ back but who want to read the output of 'words' at their leisure.
24:
25: \ currently this is very primitive: it just counts newlines, and only
26: \ allows continuing for another page (and of course, terminating
27: \ processing by sending a signal (^C))
28:
29: \ Some things to do:
30: \ allow continuing for one line (Enter)
31: \ count lines produced by wraparound (note tabs and backspaces)
32: \ allow continuing silently
33: \ fancy features like searching, scrollback etc.
34:
35: \ one more-or-less simple way to achieve all this is to
36: \ popen("less","w") and output there. Before getting the next `key`,
37: \ we would perform a pclose. This idea due to Marcel Hendrix.
38:
39: require termsize.fs
40:
41: variable last-#lines 0 last-#lines !
42:
43: :noname ( -- c )
44: 1 last-#lines !
45: defers key ;
46: is key
47:
48: :noname ( c -- )
49: dup defers emit
50: #lf =
51: if
52: 1 last-#lines +!
53: last-#lines @ rows >=
54: if
55: ." ... more ?" key drop 10 backspaces 10 spaces 10 backspaces
56: endif
57: endif ;
58: is emit
59:
60: :noname ( c-addr u -- )
61: bounds
62: ?DO
63: I c@ emit
64: LOOP ;
65: is type
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>