Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!mailrus!tut.cis.ohio-state.edu!osu-cis!killer!tness7!bellcore!faline!thumper!ulysses!terminus!rolls!mtuxo!mtfmi!dbrod From: dbrod@mtfmi.UUCP (D.BRODERICK) Newsgroups: comp.lang.prolog Subject: screen control Keywords: screen control tput character based Message-ID: <701@mtfmi.UUCP> Date: 26 May 88 19:18:06 GMT Organization: AT&T, Middletown NJ Lines: 79 If your version of Prolog does not have screen control predicates, but you are familiar with the Unix(tm) tput(1) command (or willing to become so), there is a quick and dirty way to generate some character based screen control predicates. tput(1) makes use of the terminfo database to generate terminal specific escape sequences to control the screen. For example, the following, invoked from the shell, will print out "hello" in standout mode: tput smso; echo hello; tput rmso As you can see, the argument names are intuitively obvious(?). To use this information from Prolog, write a shell script called "get_tput" as follows: -------------------------------------- echo "tput('$2',$1,'`tput -T$1 $2`')." -------------------------------------- This is invoked, for example, as: get_tput vt100 clear >> tput.pl It is easy enough to use a for-loop to generate a prolog terminfo database for all the tput arguments/terminals you want. For an interesting sight, cat the file. ("tput sgr0" sets to normal) To use on a PC running an ansi.sys driver, generate a database for ansi and download. To use: consult('tput.pl'). and call tput(clear). , defined as: tput(Cmd) :- tput(Cmd,_,EscSeq), atomic(EscSeq), write(EscSeq). tput(Cmd) :- tput(Cmd,_,[Esc|Seq]), print_list([Esc|Seq]). tput(Cmd) :- not tput(Cmd,_,_). This assumes you have loaded info only for your current terminal. The reason for the middle clause is that shell tput commands that take more than one parameter return a sequence that needs further parsing. I have not written a general parser, but have done some of these by hand. In what follows, what looks like ^ followed by [ is actually a real Escape char (in case you retype this). % cup - set cursor position. this works for vt100 and ansi tput(cup(Row,Col),att5425,['[',R1,';',C1,'H']) :- R1 is Row+1, C1 is Col+1. % csr - change scroll region tput(csr(Top,Bottom),att5425,['[',T1,';',B1,r]) :- T1 is Top+1, B1 is Bottom+1. % pln - set system function key Not on many terminals tput(pln(Key,Label,Command),att5425, ['[',Key,';',Len,';0;0q',Label16,Command]) :- name(Command,CAscii), length(CAscii,Len), pad_atom(16,Label,Label16). tput(user,att5425,'}'). % switch to user function keys tput(system,att5425,'~'). % switch to system function keys % tsl - write to status line tput(tsl(Col),att5425,['7[25;',Col1,'H']) :- Col1 is Col + 8. % auxiliary predicates print_list([]). print_list([X|Xs]) :- write(X), print_list(Xs). pad_atom(Num,Atom,Padded) :- name(Atom,AAscii), length(AAscii,Len), Pads is Num - Len, pad_blanks(Pads,BString), append(AAscii,BString,PAscii), name(Padded,PAscii). pad_blanks(0,[]). pad_blanks(Num,[32|Blanks]) :- Num > 0, Num1 is Num-1, pad_blanks(Num1,Blanks). % append/3 as usual