* updated to latest ncrt package from Ken

This commit is contained in:
peter 2000-07-08 18:06:36 +00:00
parent 289e5d6567
commit 5ecf9b9cd0
8 changed files with 1101 additions and 254 deletions

View File

@ -185,14 +185,13 @@ endif
# Targets
override UNITOBJECTS+=ncurses panel ncrt ocrt
override EXAMPLEOBJECTS+=firework testn ocrt_demo edit_demo
override EXAMPLEOBJECTS+=firework testn ocrt_demo edit_demo db_demo
# Clean
# Install
EXAMPLESUBDIR=ncurses
ZIPTARGET=install
# Defaults

View File

@ -4,14 +4,12 @@
[targets]
units=ncurses panel ncrt ocrt
examples=firework testn ocrt_demo edit_demo
[install]
examplesubdir=ncurses
examples=firework testn ocrt_demo edit_demo db_demo
[dirs]
fpcdir=../..
[rules]
testn$(EXEEXT): testn$(PASEXT) ncurses$(PPUEXT)

View File

@ -1,7 +1,7 @@
Program Edit_Demo;
{---------------------------------------------------------------------------
CncWare
(c) Copyright 1999
(c) Copyright 1999-2000
---------------------------------------------------------------------------
Filename..: edit_demo.pp
Programmer: Ken J. Wright, ken@cncware.com
@ -14,46 +14,120 @@ Program Edit_Demo;
-------+----------+-----+-----------------------------------------------------
1.00 | 12/12/99 | kjw | Initial Release.
1.01 | 12/13/99 | kjw | Changed to use oCrt.
1.02 | 06/16/00 | kjw | Added help & goto line pop-up screens.
| Changes for control keys.
------------------------------------------------------------------------------
}
uses oCrt;
var
ss : array[1..25] of string[80];
xp,yp,
s : string;
xp,yp : string;
c : char;
win1,status : tnWindow;
idx : integer;
Finished : boolean;
Procedure Help;
Var
hwin : pnWindow;
Begin
Status.Init(1,25,80,25,63,false,0);
Status.FWrite(1,1,63,80,' [F1-InsLn] [F2-DelLn] [F10-Exit]');
New(hwin,Init(1,1,40,20,62,true,49));
With hwin^ Do Begin
Align(center,center);
PutHeader('Edit_Demo Help',15,center);
FWrite(2, 2,63,0,'Ctrl/Q - Move to column 1');
FWrite(2, 3,63,0,'Ctrl/W - Move to end of line');
FWrite(2, 4,63,0,'Ctrl/A - Move to previous word');
FWrite(2, 5,63,0,'Ctrl/F - Move to next word');
FWrite(2, 6,63,0,'Ctrl/G - Delete character');
FWrite(2, 7,63,0,'Ctrl/H - Destructive Backspace');
FWrite(2, 8,63,0,'Ctrl/D - Move forward one column');
FWrite(2, 9,63,0,'Ctrl/S - Move back one column');
FWrite(2,10,63,0,'Ctrl/I - Toggle Insert/Overwrite');
FWrite(2,11,63,0,'Ctrl/P - Embed control character');
FWrite(2,12,63,0,'Ctrl/L - Goto line number');
FWrite(2,13,63,0,'Ctrl/N - Insert new line');
FWrite(2,14,63,0,'Ctrl/Y - Delete current line');
FWrite(2,15,63,0,'Ctrl/X - Move down one line');
FWrite(2,16,63,0,'Ctrl/E - Move up one line');
FWrite(2,17,63,0,'Esc/1..0 - F1..F10');
Show;
Repeat Until Keypressed;
While KeyPressed Do ReadKey;
Hide;
End;
Dispose(hwin,Done);
End;
Procedure GotoLine(var i : integer);
Var
gwin : pnWindow;
ii : integer;
esc : boolean;
Begin
New(gwin,Init(1,1,40,3,62,true,49));
With gwin^ Do Begin
Align(center,center);
PutHeader('Goto Line Number',15,center);
FWrite(2,1,63,0,'Line: ');
Show;
ii := i;
ec.ClearMode := true;
i := EditNumber(8,1,63,2,0,'',i,1,win1.rows,esc);
If esc or not (i in [1..win1.rows]) Then i := ii;
Hide;
End;
Dispose(gwin,Done);
End;
Begin
Status.Init(1,nStdScr.Rows,nStdScr.Cols,nStdScr.Rows,63,false,0);
nFWrite(1,1,63,80,' [F1-InsLn] [F2-DelLn] [F3-Help] [F10-Exit]');
Status.Show;
fillchar(ss,sizeof(ss),#0);
win1.Init(1,1,80,24,31,true,31);
win1.PutHeader(' nCrt Editor Demonstration ',15,center);
win1.Show;
win1.GotoXY(1,1);
{--------------------------------------------------------------------
The next line causes sedit to exit after every keystroke so we can
capture the insert mode and cursor positions.
--------------------------------------------------------------------}
win1.ec.ExitMode := true;
With win1 Do Begin
Init(1,1,nStdScr.Cols,nStdScr.Rows-1,31,true,31);
PutHeader(' nCrt Editor Demonstration ',15,center);
Show;
GotoXY(1,1);
{--------------------------------------------------------------------
The next line causes sedit to exit after every keystroke so we can
capture the insert mode and cursor positions for display update.
Alternatively, we could setup an ec.Special string to exit only on
certain keystrokes of interest.
--------------------------------------------------------------------}
ec.ExitMode := true;
{ too re-assign a built-in key, put it in ec.special,
then use it in the case statement below
win1.ec.Special := win1.ec.Special + #5;
}
{ now let's bind some keystrokes to the editor screen }
ec.AddChMap(^a#0#0+char(nKeyCtrlLeft));
ec.AddChMap(^s#0#0+char(nKeyLeft));
ec.AddChMap(^f#0#0+char(nKeyCtrlRight));
ec.AddChMap(^d#0#0+char(nKeyRight));
ec.AddChMap(^e#0#0+char(nKeyUp));
ec.AddChMap(^x#0#0+char(nKeyDown));
ec.AddChMap(^q#0#0+char(nKeyHome));
ec.AddChMap(^w#0#0+char(nKeyEnd));
End;
idx := 1;
Finished := false;
Repeat
With win1 Do Begin
Case ec.InsMode of
true : Status.FWrite(40,1,48,0,'Ins');
false: Status.FWrite(40,1,48,0,'Ovr');
true : Status.FWrite(50,1,48,0,'Ins');
false: Status.FWrite(50,1,48,0,'Ovr');
End;
Str(WhereX:0,xp);
Str(WhereY:0,yp);
Status.FWrite(50,1,48,80,'X='+xp+', Y='+yp);
ss[idx] := SEdit(1,idx,30,Cols,WhereX,ss[idx],c);
Status.FWrite(60,1,48,80,'X='+xp+', Y='+yp);
ss[idx] := Edit(1,idx,30,Cols,WhereX,ss[idx],c);
Case ord(c) of
nKeyUp : dec(idx);
12 : GotoLine(idx);
{5,}
nKeyUp : dec(idx);
nKeyDown : inc(idx);
nKeyPgUp : idx := 1;
nKeyPgDn : idx := Rows;
@ -61,16 +135,19 @@ Begin
inc(idx);
GotoXY(1,WhereY);
End;
14, { ctrl/n }
nKeyF1 : Begin
InsLine;
system.move(ss[idx],ss[idx+1],(rows-idx)*81);
ss[idx] := '';
End;
25, { ctrl/y }
nKeyF2 : Begin
DelLine;
system.move(ss[idx+1],ss[idx],(rows-idx)*81);
ss[rows] := '';
End;
nKeyF3 : Help;
nKeyEsc,
nKeyF10 : Finished := true;
End;
@ -81,5 +158,5 @@ Begin
Until Finished;
win1.Done;
Status.Done;
halt(1);
ClrScr;
End.

View File

@ -1,6 +1,6 @@
{---------------------------------------------------------------------------
CncWare
(c) Copyright 1999
(c) Copyright 1999-2000
Portions copyright the FreePascal Team
---------------------------------------------------------------------------
Filename..: ncrt.inc
@ -36,6 +36,23 @@
| 2) Added prev_textattr to detect a change in
| TextAttr value so current color gets updated.
| 3) See ocrt.pp
2.08 | 06/09/00 | kjw | See ocrt.pp
2.08.01 | 06/11/2000 | kjw | See ocrt.pp
2.09.00 | 06/16/2000 | kjw | See ocrt.pp
2.10.00 | 06/16/2000 | kjw | See ocrt.pp
2.11.00 | 06/27/2000 | kjw
| 1) See ocrt.pp
| 2) Now uses ncurses for CrtRead so console control characters
| work correctly (i.e., <ctrl/h>, <backspace>, etc.).
2.12.00 | 06/29/2000 | kjw | See ocrt.pp
2.13.00 | 06/30/2000 | kjw
| Added nStop and nStart procedures.
2.14.00 | 07/05/2000 | kjw
| 1) Added nCursor and nEscDelay functions.
| 2) Added nInit and moved code from ncrt.pp & ocrt.pp to it.
| 3) KEY_ALTMINUS & KEYALTEQUAL were reversed, but mapping ended
| up correct.
------------------------------------------------------------------------------
}
@ -60,13 +77,17 @@ Procedure TextMode(mode : word);
Function WhereX : integer;
Function WhereY : integer;
Procedure Window(x,y,x1,y1 : integer);
Procedure nStop;
Procedure nStart;
Function nCursor(c : integer) : integer;
Function nEscDelay(d : longint) : longint;
Const
NCRT_VERSION_MAJOR = 2;
NCRT_VERSION_MINOR = 7;
NCRT_VERSION_MINOR = 14;
NCRT_VERSION_PATCH = 0;
NCRT_VERSION = '2.07.00';
NCRT_VERSION = '2.14.00';
{ CRT modes }
BW40 = 0; { 40x25 B/W on Color Adapter }
@ -141,10 +162,15 @@ Const
KEY_ALT8 = 498; { alt/8 }
KEY_ALT9 = 499; { alt/9 }
KEY_ALT0 = 500; { alt/0 }
KEY_ALTEQUAL = 501; { alt/- }
KEY_ALTMINUS = 502; { alt/= }
KEY_ALTMINUS = 501; { alt/- }
KEY_ALTEQUAL = 502; { alt/= }
KEY_ALTTAB = 503; { alt/tab }
{ cursor type }
cOFF = 0; { invisible cursor }
cON = 1; { normal cursor }
cBIG = 2; { very visible cursor }
var
CheckBreak,
CheckEOF,
@ -237,17 +263,17 @@ Begin
{ alt/a .. atl/z }
for i := ord('a') to ord('z') do Begin
s := #27+chr(i)+#0;
define_key(@s[1],400+i-32);
define_key(@s[1],(KEY_ALTA-97)+i);
End;
{ alt/1 .. alt/9 }
for i := 1 to 9 do Begin
s := #27+chr(i)+#0;
define_key(@s[1],490+i);
define_key(@s[1],(KEY_ALT1-1)+i);
End;
s := #27+'0'+#0; define_key(@s[1],500); { alt/0 }
s := #27+'-'+#0; define_key(@s[1],501); { alt/- }
s := #27+'='+#0; define_key(@s[1],502); { alt/= }
s := #27+#9+#0; define_key(@s[1],503); { alt/tab }
s := #27+'0'+#0; define_key(@s[1],KEY_ALT0); { alt/0 }
s := #27+'-'+#0; define_key(@s[1],KEY_ALTMINUS); { alt/- }
s := #27+'='+#0; define_key(@s[1],KEY_ALTEQUAL); { alt/= }
s := #27+#9+#0; define_key(@s[1],KEY_ALTTAB); { alt/tab }
End;
End;
@ -262,6 +288,25 @@ Begin
tcSetAttr(STDIN,TCSANOW,tios);
End;
{--------------------------------------------------------
This disables any curses activity until a refresh.
Use this BEFORE any shelling (shell,exec,execv,etc)
to put the terminal temporarily back into cooked mode.
--------------------------------------------------------}
Procedure nStop;
Begin
endwin;
End;
{---------------------------------------------
Simply a refresh to re-establish the curses
terminal settings following an nStop.
---------------------------------------------}
Procedure nStart;
Begin
refresh;
End;
{ see if the specified attribute is high intensity }
Function IsBold(att : integer) : boolean;
Begin
@ -494,8 +539,8 @@ Begin
KEY_ALT8 : c := #127; { alt/8 }
KEY_ALT9 : c := #128; { alt/9 }
KEY_ALT0 : c := #129; { alt/0 }
KEY_ALTEQUAL : c := #130; { alt/- }
KEY_ALTMINUS : c := #131; { alt/= }
KEY_ALTMINUS : c := #130; { alt/- }
KEY_ALTEQUAL : c := #131; { alt/= }
KEY_ALTTAB : c := #15; { alt/tab }
Else
Begin
@ -583,23 +628,21 @@ Function CrtRead(Var F: TextRec): Integer;
{
Read from CRT associated file.
}
var
i : longint;
Begin
F.BufEnd:=fdRead(F.Handle, F.BufPtr^, F.BufSize);
{ fix #13 only's -> #10 to overcome terminal setting }
for i:=1to F.BufEnd do
begin
if (F.BufPtr^[i-1]=#13) and (F.BufPtr^[i]<>#10) then
F.BufPtr^[i-1]:=#10;
end;
F.BufPos:=F.BufEnd;
CrtWrite(F);
{ let's use ncurses instead! }
FillChar(F.BufPtr^, F.BufSize, #0);
wgetnstr(ActiveWn,F.BufPtr^, F.BufSize-1);
F.BufEnd := Length(StrPas(F.BufPtr^))+1;
F.BufPtr^[F.BufEnd-1] := #10;
F.BufPos:=0;
{ CrtWrite(F);}
CrtRead:=0;
End;
Function CrtReturn(Var F:TextRec):Integer;
Begin
F.BufEnd := 0;
F.BufPos:= 0;
CrtReturn:=0;
end;
@ -755,7 +798,7 @@ End;
function Keypressed : boolean;
var
l : longint;
fd : fdSet;
{ fd : fdSet;}
Begin
Keypressed := FALSE;
nodelay(ActiveWn,bool(TRUE));
@ -810,6 +853,40 @@ Begin
ClrScr;
End;
{ Set the cursor visibility. Returns the previous value }
{ or (-1) if value c is not supported by the terminal. }
Function nCursor(c : integer) : integer;
Begin
nCursor := curs_set(c);
End;
{ Set the <esc> key delay time in milliseconds. }
{ Use d=(-1) to return current value without updating. }
Function nEscDelay(d : longint) : longint;
Begin
nEscDelay := ESCDELAY;
If d >= 0 Then ESCDELAY := d;
End;
{ unit initialization, following ncurses init }
Procedure nInit;
Begin
SubWn := nil;
TextMode(LastMode);
{ Redirect the standard output }
assigncrt(Output);
Rewrite(Output);
TextRec(Output).Handle:=StdOutputHandle;
{ Redirect the standard input }
assigncrt(Input);
Reset(Input);
TextRec(Input).Handle:=StdInputHandle;
nEscDelay(500); { default is 1000 (1 second) }
nCursor(cON); { normal cursor }
End;
{ exit procedure to ensure curses is closed up cleanly }
Procedure nExit;
Begin

View File

@ -1,7 +1,7 @@
Unit nCrt;
{---------------------------------------------------------------------------
CncWare
(c) Copyright 1999
(c) Copyright 1999-2000
Portions copyright the FreePascal Team
---------------------------------------------------------------------------
Filename..: ncrt.pp
@ -25,6 +25,15 @@ Unit nCrt;
2.05 | 01/06/00 | kjw | See ncrt.inc, ocrt.pp
2.06 | 01/11/00 | kjw | See ncrt.inc.
2.07 | 01/31/00 | kjw | See ncrt.inc, ocrt.pp
2.08 | 06/09/00 | kjw | See ocrt.pp
2.08.01 | 06/11/00 | kjw | See ocrt.pp
2.09.00 | 06/16/00 | kjw | See ocrt.pp
2.10.00 | 06/23/00 | kjw | See ocrt.pp
2.11.00 | 06/27/00 | kjw | See ocrt.pp
2.12.00 | 06/29/00 | kjw | See ocrt.pp
2.13.00 | 06/30/00 | kjw | See ncrt.inc
2.14.00 | 07/05/00 | kjw | See ncrt.inc
------------------------------------------------------------------------------
}
Interface
@ -40,17 +49,8 @@ Begin
If Not StartCurses(ActiveWn) Then
Halt;
SubWn := nil;
TextMode(LastMode);
{ Redirect the standard output }
assigncrt(Output);
Rewrite(Output);
TextRec(Output).Handle:=StdOutputHandle;
{ Redirect the standard input }
assigncrt(Input);
Reset(Input);
TextRec(Input).Handle:=StdInputHandle;
{ crtassign }
nInit;
{ set the unit exit procedure }
ExitSave := ExitProc;

View File

@ -201,6 +201,7 @@ Var
LINES : longint;external name 'LINES';
COLS : longint;external name 'COLS';
TABSIZE : longint;external name 'TABSIZE';
ESCDELAY: longint;external name 'ESCDELAY';
Function define_key(_para1:pchar; _para2:longint):longint; cdecl;external;
Function keyok(_para1:longint; _para2:bool):longint; cdecl;external;
@ -1674,7 +1675,10 @@ end;
end.
{
$Log$
Revision 1.7 2000-05-31 09:36:26 jonas
Revision 1.8 2000-07-08 18:06:36 peter
* updated to latest ncrt package from Ken
Revision 1.7 2000/05/31 09:36:26 jonas
* restored (version included with ncrt 2.06 was outdated)
Revision 1.5 2000/02/27 14:40:41 peter

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
Program ocrt_demo;
{---------------------------------------------------------------------------
CncWare
(c) Copyright 1999
(c) Copyright 1999-2000
---------------------------------------------------------------------------
Filename..: ocrt_demo.pp
Programmer: Ken J. Wright
@ -18,6 +18,7 @@ Program ocrt_demo;
| 2) Renamed from ncrt_demo to ocrt_demo.
| 3) Added some standard crt code at beginning.
1.03 | 01/06/00 | kjw | Some minor changes for ncrt mods.
1.04 | 06/27/00 | kjw | Changes for ncrt mods.
------------------------------------------------------------------------------
}
uses oCrt;
@ -39,14 +40,14 @@ Begin
TextAttr := TextAttr + blink;
ClrScr;
GotoXY(2,35);
Writeln(1.0:0:4,' This is a test!');
Writeln(1.0:0:4,' This should be blinking text');
Window(10,10,70,15);
TextAttr := TextAttr - blink;
TextBackground(2);
ClrScr;
s := ' : ';
for i := 1 to 6 do
writeln(i:0,s,'this is a test');
writeln(i:0,s,'No blinking here');
writeln('Press Enter');
readln(s);
TextBackground(3);
@ -72,21 +73,21 @@ Begin
stdscr := nscreen;
nClrScr(stdscr,7);
nDrawBox(stdscr,btSingle,1,1,80,3,31);
FWrite(27,2,30,0,'nCrt Demonstration Program');
nFWrite(27,2,30,0,'nCrt Demonstration Program');
nNewWindow(win1,9,9,71,16);
nClrScr(win1,95);
nWriteScr(win1,3,2,95,'This is a background window.');
nWriteScr(win1,10,3,95,'It was built first, then displayed later.');
FWrite(1,24,15,80,'Enter some text, press [Enter]');
nFWrite(stdscr,1,24,15,80,'Enter some text, press [Enter]');
nWindow(win,10,10,70,15);
nClrScr(win,31);
nGotoXY(win,1,1);
s := nReadln(win);
If s <> 'oop' Then Begin { skip right to OOP section? }
FWrite(1,24,15,80,'Enter some more text, press [Enter]');
nFWrite(stdscr,1,24,15,80,'Enter some more text, press [Enter]');
nGotoXY(win,nWhereX(win),nWhereY(win));
s := nReadln(win);
FWrite(1,24,79,80,'Please wait...');
nFWrite(stdscr,1,24,79,80,'Please wait...');
nGotoXY(win,1,1);
Delay(500);
nDelLine(win);
@ -101,10 +102,10 @@ Begin
{ force nCrt to use full screen }
nSetActiveWin(stdscr);
ClrScr;
FWrite(1,24,14,80,'Enter even more text, press [Enter]');
nFWrite(1,24,14,80,'Enter even more text, press [Enter]');
s := nReadln(stdscr);
nClrScr(win,47);
FWrite(1,24,11,80,'Press some keys, followed by [Esc]');
nFWrite(1,24,11,80,'Press some keys, followed by [Esc]');
nGotoXY(win,5,1);
x := nWhereX(win);
y := nWhereY(win);
@ -120,6 +121,8 @@ Begin
InsLine;
dec(i);
End;
{ turn on oCrt keyboard echo }
nEcho(true);
str(x:0,s);
nWrite(win,'x = '+s+', ');
str(y:0,s);
@ -127,7 +130,7 @@ Begin
nWriteln(stdscr,'press a key...');
readkey;
nDrawBox(stdscr,btSingle,11,11,69,14,63);
FWrite(30,11,79,49,' nCrt Demo Program');
nFWrite(30,11,79,49,' nCrt Demo Program');
nDelWindow(win);
nDelWindow(win1);
nWindow(win,2,2,79,24);
@ -137,45 +140,47 @@ Begin
End;
{ and now for some object oCrt }
win := nscreen;
New(win11,Init(1,1,80,25,31,true,30));
New(win11,Init(1,1,nStdScr.Cols,nStdScr.Rows,31,true,30));
win11^.PutHeader(' Now for some OOP with nCrt! ',79,center);
win11^.DrawBox(1,1,1,78,3,62);
New(win22,Init(20,7,60,17,47,false,0));
win33.Init(30,15,50,20,79,true,78);
win33.PutHeader(' Little Window ',15,right);
win33.Writeln('And here is window #3');
Writeln('And here is window #3');
win11^.Show;
win11^.GotoXY(2,2);
win11^.Write('Please press a key...');
win11^.ReadKey;
GotoXY(2,2);
Write('Please press a key...');
ReadKey;
msgbox.init(25,11,55,13,47,true,47);
s := 'Please enter a string';
msgbox.FWrite((msgbox.cols-length(s)) div 2,1,46,0,s);
msgbox.Show;
win11^.GotoXY(1,10);
win11^.Active;
GotoXY(1,10);
msgbox.Show;
{ turn on oCrt keyboard echo }
nEcho(true);
s := win11^.Readln;
win11^.Active;
Readln(s);
msgbox.Hide;
win22^.Show;
win22^.Writeln(s);
Writeln(s);
Delay(2000);
win11^.Hide;
win22^.Writeln('Hiding window 1...');
win22^.Active;
Writeln('Hiding window 1...');
Delay(2000);
win33.Show;
Delay(2000);
win11^.Show;
win11^.Writeln('Showing window 1');
Writeln('Showing window 1');
win22^.Show;
win22^.Writeln('Showing window 2');
Writeln('Showing window 2');
win33.Show;
win33.Write('Showing window 3');
Write('Showing window 3');
nKeypressed(2000);
While Keypressed Do Readkey;
win11^.Hide;
win33.Write('Hiding window 1');
win33.Active;
Write('Hiding window 1');
win22^.PutFrame(62);
win22^.PutHeader(' New frame color ',63,center);
win22^.Show;
@ -183,7 +188,8 @@ Begin
nKeypressed(3000);
While Keypressed Do Readkey;
win22^.Hide;
win33.Write('Hiding window 2');
win33.Active;
Write('Hiding window 2');
nKeypressed(2000);
While Keypressed Do Readkey;
win33.SetColor(47);
@ -197,8 +203,8 @@ Begin
dec(y);
str(i:0,s);
win33.Move(x,y);
win33.Writeln('Moved by '+s);
FWrite(1,25,63,80,'Moved by '+s);
Writeln('Moved by '+s);
nFWrite(stdscr,1,nStdScr.Rows,63,80,'Moved by '+s);
Delay(250);
End;
win33.Align(center,none);
@ -215,5 +221,5 @@ Begin
Dispose(win22,Done);
win33.Done;
msgbox.Done;
ClrScr;
End.