home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l217 / 2.ddi / EXAMPLES / CH20EX09.PRO < prev    next >
Encoding:
Text File  |  1990-03-26  |  1.2 KB  |  38 lines

  1. /*
  2.    Copyright (c) 1986, 90 by Prolog Development Center
  3. */
  4.    
  5. include "CH20EX08.PRE" /* CH20EX08.PRO, excluding the goal */
  6.  
  7. domains
  8.    row, col, length = integer
  9.    field = f(row, col, length)
  10.    position = pos(row, col)
  11.  
  12. predicates
  13.    scr(field, position, key)
  14.  
  15. goal
  16.    Row=10, Col=10, Length=30, cursor(Row, Col),
  17.    makewindow(1, 23, 1, "Example Editor", 0, 0, 25, 80),
  18.    write("Edit the text. Use the arrow keys to move"),
  19.    readkey(Key),
  20.    field_attr(Row, Col, Length, 112),
  21.    scr(f(Row, Col, Length), pos(Row, Col), Key), nl, nl,
  22.    field_str(Row, Col, Length, Contents),
  23.    write("Edited contents: ", Contents).
  24.  
  25. clauses
  26.    scr(_, _, esc) :- !, fail.
  27.    scr(_, _, fkey(10)) :- !.
  28.    scr(f(Row, Col, L), pos(R, C), char(Ch)) :-
  29.       scr_char(R, C, Ch), C1=C+1, C1<Col+L, cursor(R, C1),
  30.    readkey(Key), scr(f(Row, Col, L), pos(R, C1), Key).
  31.    scr(f(Row, Col, L), pos(R, C), Key) :- 
  32.       C1=C+1, C1<Col+L, cursor(R, C1), readkey(Key),
  33.       scr(f(Row, Col, L), pos(R, C1), Key).
  34.    scr(f(Row, Col, L), pos(R, C), Key) :- 
  35.       C1=C-1, C1>=Col, cursor(R, C1),
  36.       readkey(Key), scr(f(Row, Col, L), pos(R, C1), Key).
  37.    scr(Field, Pos, _) :- beep, readkey(Key), scr(Field, Pos, Key).
  38.