edit_demo.pp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. Program Edit_Demo;
  2. {---------------------------------------------------------------------------
  3. CncWare
  4. (c) Copyright 1999-2000
  5. ---------------------------------------------------------------------------
  6. Filename..: edit_demo.pp
  7. Programmer: Ken J. Wright, [email protected]
  8. Date......: 12/12/99
  9. Purpose - Demonstrate the use of nCrt unit.
  10. -------------------------------<< REVISIONS >>--------------------------------
  11. Ver | Date | Prog| Description
  12. -------+----------+-----+-----------------------------------------------------
  13. 1.00 | 12/12/99 | kjw | Initial Release.
  14. 1.01 | 12/13/99 | kjw | Changed to use oCrt.
  15. 1.02 | 06/16/00 | kjw | Added help & goto line pop-up screens.
  16. | Changes for control keys.
  17. ------------------------------------------------------------------------------
  18. }
  19. uses oCrt;
  20. var
  21. ss : array[1..25] of string[80];
  22. xp,yp : string;
  23. c : char;
  24. win1,status : tnWindow;
  25. idx : integer;
  26. Finished : boolean;
  27. Procedure Help;
  28. Var
  29. hwin : pnWindow;
  30. Begin
  31. New(hwin,Init(1,1,40,20,62,true,49));
  32. With hwin^ Do Begin
  33. Align(center,center);
  34. PutHeader('Edit_Demo Help',15,center);
  35. FWrite(2, 2,63,0,'Ctrl/Q - Move to column 1');
  36. FWrite(2, 3,63,0,'Ctrl/W - Move to end of line');
  37. FWrite(2, 4,63,0,'Ctrl/A - Move to previous word');
  38. FWrite(2, 5,63,0,'Ctrl/F - Move to next word');
  39. FWrite(2, 6,63,0,'Ctrl/G - Delete character');
  40. FWrite(2, 7,63,0,'Ctrl/H - Destructive Backspace');
  41. FWrite(2, 8,63,0,'Ctrl/D - Move forward one column');
  42. FWrite(2, 9,63,0,'Ctrl/S - Move back one column');
  43. FWrite(2,10,63,0,'Ctrl/I - Toggle Insert/Overwrite');
  44. FWrite(2,11,63,0,'Ctrl/P - Embed control character');
  45. FWrite(2,12,63,0,'Ctrl/L - Goto line number');
  46. FWrite(2,13,63,0,'Ctrl/N - Insert new line');
  47. FWrite(2,14,63,0,'Ctrl/Y - Delete current line');
  48. FWrite(2,15,63,0,'Ctrl/X - Move down one line');
  49. FWrite(2,16,63,0,'Ctrl/E - Move up one line');
  50. FWrite(2,17,63,0,'Esc/1..0 - F1..F10');
  51. Show;
  52. Repeat Until Keypressed;
  53. While KeyPressed Do ReadKey;
  54. Hide;
  55. End;
  56. Dispose(hwin,Done);
  57. End;
  58. Procedure GotoLine(var i : integer);
  59. Var
  60. gwin : pnWindow;
  61. ii : integer;
  62. esc : boolean;
  63. Begin
  64. New(gwin,Init(1,1,40,3,62,true,49));
  65. With gwin^ Do Begin
  66. Align(center,center);
  67. PutHeader('Goto Line Number',15,center);
  68. FWrite(2,1,63,0,'Line: ');
  69. Show;
  70. ii := i;
  71. ec.ClearMode := true;
  72. i := EditNumber(8,1,63,2,0,'',i,1,win1.rows,esc);
  73. If esc or not (i in [1..win1.rows]) Then i := ii;
  74. Hide;
  75. End;
  76. Dispose(gwin,Done);
  77. End;
  78. Begin
  79. Status.Init(1,nStdScr.Rows,nStdScr.Cols,nStdScr.Rows,63,false,0);
  80. nFWrite(1,1,63,80,' [F1-InsLn] [F2-DelLn] [F3-Help] [F10-Exit]');
  81. Status.Show;
  82. fillchar(ss,sizeof(ss),#0);
  83. With win1 Do Begin
  84. Init(1,1,nStdScr.Cols,nStdScr.Rows-1,31,true,31);
  85. PutHeader(' nCrt Editor Demonstration ',15,center);
  86. Show;
  87. GotoXY(1,1);
  88. {--------------------------------------------------------------------
  89. The next line causes sedit to exit after every keystroke so we can
  90. capture the insert mode and cursor positions for display update.
  91. Alternatively, we could setup an ec.Special string to exit only on
  92. certain keystrokes of interest.
  93. --------------------------------------------------------------------}
  94. ec.ExitMode := true;
  95. { too re-assign a built-in key, put it in ec.special,
  96. then use it in the case statement below
  97. win1.ec.Special := win1.ec.Special + #5;
  98. }
  99. { now let's bind some keystrokes to the editor screen }
  100. ec.AddChMap(^a#0#0+char(nKeyCtrlLeft));
  101. ec.AddChMap(^s#0#0+char(nKeyLeft));
  102. ec.AddChMap(^f#0#0+char(nKeyCtrlRight));
  103. ec.AddChMap(^d#0#0+char(nKeyRight));
  104. ec.AddChMap(^e#0#0+char(nKeyUp));
  105. ec.AddChMap(^x#0#0+char(nKeyDown));
  106. ec.AddChMap(^q#0#0+char(nKeyHome));
  107. ec.AddChMap(^w#0#0+char(nKeyEnd));
  108. End;
  109. idx := 1;
  110. Finished := false;
  111. Repeat
  112. With win1 Do Begin
  113. Case ec.InsMode of
  114. true : Status.FWrite(50,1,48,0,'Ins');
  115. false: Status.FWrite(50,1,48,0,'Ovr');
  116. End;
  117. Str(WhereX:0,xp);
  118. Str(WhereY:0,yp);
  119. Status.FWrite(60,1,48,80,'X='+xp+', Y='+yp);
  120. ss[idx] := Edit(1,idx,30,Cols,WhereX,ss[idx],c);
  121. Case ord(c) of
  122. 12 : GotoLine(idx);
  123. {5,}
  124. nKeyUp : dec(idx);
  125. nKeyDown : inc(idx);
  126. nKeyPgUp : idx := 1;
  127. nKeyPgDn : idx := Rows;
  128. nKeyEnter: Begin
  129. inc(idx);
  130. GotoXY(1,WhereY);
  131. End;
  132. 14, { ctrl/n }
  133. nKeyF1 : Begin
  134. InsLine;
  135. system.move(ss[idx],ss[idx+1],(rows-idx)*81);
  136. ss[idx] := '';
  137. End;
  138. 25, { ctrl/y }
  139. nKeyF2 : Begin
  140. DelLine;
  141. system.move(ss[idx+1],ss[idx],(rows-idx)*81);
  142. ss[rows] := '';
  143. End;
  144. nKeyF3 : Help;
  145. nKeyEsc,
  146. nKeyF10 : Finished := true;
  147. End;
  148. If idx > rows Then idx := rows;
  149. If idx < 1 Then idx := 1;
  150. GotoXY(WhereX,idx);
  151. End;
  152. Until Finished;
  153. win1.Done;
  154. Status.Done;
  155. ClrScr;
  156. End.