home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 341.img / TCS161S.ZIP / SCRNINPT.PAS < prev    next >
Pascal/Delphi Source File  |  1989-07-31  |  4KB  |  194 lines

  1. {$R-,S-,I-,D-,V-,B-}
  2.  
  3. unit scrninpt;
  4.  
  5. interface
  6.  
  7. uses dos,crt,
  8.      scrnunit;
  9.  
  10. var scrnin:text;         { For input }
  11.     buflen:integer;
  12.  
  13.  
  14. procedure setinputregion (left,right,line:integer);
  15. procedure setdefaultinput (x:string);
  16. procedure setinputcolor (attr:integer);
  17.  
  18. implementation
  19.  
  20. var scrninbuf:array [0..257] of char;
  21.     x1,x2,y:integer;
  22.     oldinput:string;
  23.  
  24. {$F+}
  25.  
  26. function donothing (var t:textrec):integer;
  27. begin
  28. {  t.bufend:=0;
  29.   t.bufpos:=0;  }
  30.   donothing:=0
  31. end;
  32.  
  33. function scrninchars (var t:textrec):integer;
  34. var s:string;
  35.     len:byte absolute s;
  36.     cx,lx,wid:integer;
  37.     k:char;
  38.     tracking:boolean;
  39.  
  40. const letters:set of char=['A'..'Z','a'..'z'];
  41.  
  42.   procedure drawit;
  43.   var cnt:integer;
  44.   begin
  45.     gotoxy (x1,y);
  46.     write (scrn,copy(s,lx,wid));
  47.     for cnt:=1 to wid-len+lx-1 do write (' ');
  48.     gotoxy (cx-lx+x1,y);
  49.     movecsr
  50.   end;
  51.  
  52.   procedure insert (k:char);
  53.   begin
  54.     if len>=buflen then exit;
  55.     s:=copy(s,1,cx-1)+k+copy(s,cx,255);
  56.     cx:=cx+1
  57.   end;
  58.  
  59.   procedure del;
  60.   begin
  61.     if cx<=len then s:=copy(s,1,cx-1)+copy(s,cx+1,255)
  62.   end;
  63.  
  64.   procedure backspace;
  65.   begin
  66.     if cx>1 then begin
  67.       cx:=cx-1;
  68.       del
  69.     end
  70.   end;
  71.  
  72.   procedure wordleft;
  73.   begin
  74.     if cx=1 then exit;
  75.     cx:=cx-1;
  76.     while (cx>1) and ((s[cx-1] in letters) or (not (s[cx] in letters))) do
  77.       cx:=cx-1
  78.   end;
  79.  
  80.   procedure wordright;
  81.   begin
  82.     if cx>len then exit;
  83.     cx:=cx+1;
  84.     while (cx<=len) and ((s[cx-1] in letters) or (not (s[cx] in letters))) do
  85.       cx:=cx+1;
  86.   end;
  87.  
  88.   procedure delword;
  89.   begin
  90.     while (cx<=len) and (s[cx] in letters) do del;
  91.     while (cx<=len) and (not (s[cx] in letters)) do del
  92.   end;
  93.  
  94.   procedure extended (key:integer);
  95.   begin
  96.     case key of
  97.       71,73:cx:=1;
  98.       75:cx:=cx-1;
  99.       77:cx:=cx+1;
  100.       79,81:cx:=len+1;
  101.       83:del;
  102.       115:wordleft;
  103.       116:wordright;
  104.       117:len:=cx-1;
  105.     end
  106.   end;
  107.  
  108.   procedure normal (k:char);
  109.   begin
  110.     case ord(k) of
  111.       32..126:if len<buflen then insert(k);
  112.       8:backspace;
  113.       27:len:=0;
  114.       127,20:delword
  115.     end
  116.   end;
  117.  
  118. begin
  119.   scrninchars:=0;
  120.   if t.bufend<>t.bufpos then exit;
  121.   pushdarea;
  122.   setcursortracking (false);
  123.   setcolor (curwindowptr^.inputcolor);
  124.   s:=oldinput;
  125.   if x1=0 then begin
  126.     x1:=wherex;
  127.     y:=wherey;
  128.     x2:=curwindowptr^.xsize
  129.   end;
  130.   lx:=1;
  131.   cx:=1;
  132.   wid:=x2-x1+1;
  133.   repeat
  134.     if cx<1 then cx:=1;
  135.     if cx>len then cx:=len+1;
  136.     if lx>cx-5 then lx:=cx-5;
  137.     if lx<cx-wid+5 then lx:=cx-wid+5;
  138.     if lx>len-wid+1 then lx:=len-wid+1;
  139.     if lx>cx then lx:=cx;
  140.     if lx<cx-wid then lx:=cx-wid;
  141.     if lx<1 then lx:=1;
  142.     if not keypressed then drawit;
  143.     k:=readkey;
  144.     if k=#0 then extended(ord(readkey)) else normal(k)
  145.   until k=#13;
  146.   drawit;
  147.   s:=s+#13#10;
  148.   move (s[1],t.bufptr^,length(s));
  149.   x1:=0;
  150.   buflen:=80;
  151.   oldinput:='';
  152.   t.bufpos:=0;
  153.   t.bufend:=len;
  154.   popdarea
  155. end;
  156.  
  157. {$F-}
  158.  
  159. procedure setinputregion (left,right,line:integer);
  160. begin
  161.   x1:=left;
  162.   x2:=right;
  163.   y:=line
  164. end;
  165.  
  166. procedure setdefaultinput (x:string);
  167. begin
  168.   oldinput:=x
  169. end;
  170.  
  171. procedure setinputcolor (attr:integer);
  172. begin
  173.   curwindowptr^.inputcolor:=attr
  174. end;
  175.  
  176. begin
  177.   x1:=0;          { Initialize input stuff }
  178.   buflen:=80;
  179.   oldinput:='';
  180.   with textrec(scrnin) do begin
  181.     mode:=fminput;
  182.     bufptr:=@scrninbuf;
  183.     bufsize:=258;
  184.     openfunc:=@donothing;
  185.     closefunc:=@donothing;
  186.     inoutfunc:=@scrninchars;
  187.     flushfunc:=@donothing;
  188.     bufpos:=0;
  189.     bufend:=0
  190.   end;
  191.   move (scrnin,input,sizeof(textrec))
  192. end.
  193.  
  194.