oCrt unit Documentation

oCrt is part of the nCrt package. oCrt introduces some new procedures and functions to simplify the use of text mode windowing. Like nCrt, oCrt is based on the ncurses library, so terminal independence is maintained.

oCrt shares a common code base with nCrt so all of the normal nCrt procedures and functions are available without declaring nCrt in the uses clause of your program/unit. Simply use oCrt in place of nCrt in your programs to add a whole new level of capabilities. oCrt provides three different levels of functinality to the programmer.

  1. A complete set of pointer related window procedures and functions.
  2. All common nCrt procedures and functions.
  3. Object based windowing


Level I
Level II
Level III

Level I

Most all of the level I functions use a pointer of type pwindow to identify the window to be affected. The pwindow type is from the ncurses unit and is a pointer to the ncurses data structure that represents a window. The following functions and procedures are available.

nSetActiveWin
nDoNow
nKeypressed
nEcho
nWindow
nNewWindow
nDelWindow
nWinColor
nClrScr
nClrEol
nClrBot
nInsLine
nDelLine
nGotoXY
nWhereX
nWhereY
nReadKey
nReadLn
nWrite
nWriteLn
nWriteScr
nRefresh
nScroll
nDrawBox
nFrame
nRows
nCols
nHL
nVL
nUL
nLL
nUR
nLR
nLT
nRT
nTT
nBT
nPL
nLA
nRA
nUA
nDA
nDI
nCB
nDG
nPM
nBL
nHLine
nVLine
nWriteAC
nIsBold
nSetColorPair
nFWrite
nEdit
nEditNumber
nEditDate
nEditString
nMakeWindow
nCheckPxPicture


nSetActiveWin

Syntax: nSetActiveWin(win : pwindow)

Description: Makes a window current for all further input/output.

Example:

Type
   win1,win2 : pwindow;
   
   nSetActiveWin(win1);
   writeln('this appears in win1');
   nSetActiveWin(win2);
writeln('this appears in win2');

nDoNow

Syntax: nDoNow(donow : boolean)

Description: Toggles the global refresh flag. If donow is true, then changes to any window are posted immediately. If false, then changes are held until a following call to nRefresh.

Example:

   nDoNow(true); { turn on immediate refresh }

nKeypressed

Syntax: nKeypressed(timeout : word) : boolean

Description: nKeypressed is similar to the normal keypressed function with the exception that nKeypressed will only wait for timeout milliseconds. If a key is pressed before the specified amount of time has passed, then nKeypressed will return TRUE, otherwise it will return FALSE.

Example:

   If nKeypressed(1000) Then { wait 1 second for a key to be pressed }
      writeln('a key has been pressed')
   Else
      writeln('no key pressed');

nEcho

Syntax: nEcho(b : boolean)

Description: nEcho is a toggle to switch on/off the display of a character on the console when a key is pressed.

Example:

   nEcho(true) { a keypress will be displayed }
   nEcho(false) { a keypress will not be displayed }

nWindow

Syntax: nWindow(var win : pWindow; x,y,x1,y1 : integer)

Description: nWindow creates a new window which is a sub-window of stdscr (the default window). A pointer to the new window is returned in win. Both stdscr and this new window share the smae memory space, so changes to either window will be reflected in both.

Example:

Var win : pWindow;
 
   nWindow(win,1,1,10,10)

nNewWindow

Syntax: nNewWindow(var win : pWindow; x,y,x1,y1 : integer)

Description: nWindow creates a new window. A pointer to the new window is returned in win. Unlike a window created with nWindow, this new window has it's own memory space.

Example:

Var win : pWindow;
   nNewWindow(win,1,1,10,10)

nDelWindow

Syntax: nDelWindow(var win : pWindow)

Description: nDelWindow releases all memory used by the window win and sets win to nil. The screen space however, is left as is with no changes. If you need to clear the screen space, then use nClrScr first before deleting the window.

Example:

Var win : pWindow;
   nDelWindow(win)

nWinColor

Syntax: nWinColor(win : pWindow; att : integer)

Description: nWinColor changes the color for all following screen writes to the window win. Any text currently written to this window will remain unchanged until overwritten by new text.

Example:

Var win : pWindow;
   nWinColor(win,31) { change to white on blue }

nClrScr

Syntax: nClrScr(win : pWindow; att : integer)

Description: nClrScr erases all text from the window win and sets the window color to att.

Example:

Var win : pWindow;
   nClrScr(win,31);

nClrEol

Syntax: nClrEol(win : pWindow)

Description: nClrEol erases all text from the current cursor position in window win to the end of the same line.

Example:

Var win : pWindow;
   nClrEol(win);

nClrBot

Syntax: nClrBot(win : pWindow)

Description: nClrBot erases all text from the current cursor position in window win to the end of the window.

Example:

Var win : pWindow;
   nClrBot(win);

nInsLine

Syntax: nInsLine(win : pWindow)

Description: nInsLine inserts a new blank line at the current line in window win. The current line is where the cursor is present. All lines including the current line and all lines below, are scrolled down one row. The bottom most line in the window disappears.

Example:

Var win : pWindow;
   nInsLine(win);

nDelLine

Syntax: nDelLine(win : pWindow)

Description: nDelLine deletes the current line in window win. The current line is where the cursor is present. All lines below the current line, are scrolled up one row. The last line in the window will be blank.

Example:

Var win : pWindow;
   nDelLine(win);

nGotoXY

Syntax: nGotoXY(win : pWindow; x,y : integer)

Description: nGotoXY moves the cursor to the column and row in window win defined by x and y. If either x or y are outside of the limits of the window size, the cursor will not be moved.

Example:

Var win : pWindow;
   nGotoXY(win,1,20);

nWhereX

Syntax: nWhereX(win : pWindow) : integer

Description: nWhereX returns the current column position of the cursor in window win.

Example:

Var win : pWindow;
   nGotoXY(win,1,20);
   nWhereX(win); { returns 1 }

nWhereY

Syntax: nWhereY(win : pWindow) : integer

Description: nWhereY returns the current row position of the cursor in window win.

Example:

Var win : pWindow;
   nGotoXY(win,1,20);
   nWhereY(win); { returns 20 }

nReadKey

Syntax: nReadkey(win : pWindow) : char

Description: nReadKey waits for a key to be pressed in window win. If nEcho(true) has been called prior to this call, then the character will be echoed to the display, otherwise the pressed key does not display. nEcho(false) is the default. nReadKey returns the same values as Borland Pascal's Readkey function.

Example:

Var
   c : char;
   win : pWindow;
   
   c := nReadKey(win);

nReadLn

Syntax: nReadLn(win : pWindow) : string

Description: nReadLn reads input from the keyboard in window win. If nEcho(true) has been called prior to this call, then the characters typed will be echoed to the display, otherwise the characters do not display. nEcho(false) is the default. nReadLn returns all input as a string.

Example:

Var
  s : string;
  win : pWindow;
  
  s := nReadLn(win);

nWrite

Syntax: nWrite(win : pWindow; s : string)

Description: nWrite writes the contents of string s in window win at the current cursor position.

Example:

Var
  s : string;
  win : pWindow; 

  s := 'Hello!';
  nWrite(win,s);

nWriteLn

Syntax: nWriteLn(win : pWindow; s : string)

Description: nWrite writes the contents of string s in window win at the current cursor position, followed by a newline.

Example:

Var
  s : string;
  win : pWindow; 

  s := 'Hello!';
  nWrite(win,s);

nWriteScr

Syntax: nWriteSrc(win : pWindow; x,y,att : integer; s : string)

Description: nWriteScr writes the contents of string s in window win at the position x, y with the color value of att. The cursor postion is not updated in the window and the written string does not display until the next refresh of the window.

Example:

Var
  s : string;
  win : pWindow; 

  s := 'Hello!';
  { display Hello! at x5,y10 using white on a blue background }
  nWriteScr(win,5,10,31,s);

nRefresh

Syntax: nRefresh(win : pWindow)

Description: nRefresh updates the window win with all current changes. Basically a repaint of current window contents.

Example:

Var
  win : pWindow; 

  nRefresh(win);

nScroll

Syntax: nScroll(win : pWindow; lines : integer; dir : tnUpDown)

Description: nScroll scrolls the window win up or down, the specified number of lines.

Example:

Var win : pWindow; 

   nScroll(win,5,up);   { scroll up 5 lines }
   nScroll(win,5,down); { scroll down 5 lines }

nDrawBox

Syntax: nDrawBox(win : pWindow; LinesStyle,x1,y1,x2,y2,att : integer)

Description: nDrawBox draws a colored box in the window win with or without a border, with upper lh corner at x1,y1, lower rh corner at x2,y2 using color att. A LineStyle value of 1 or 2 will produce a single line border around the outer edges of the window.

Example:

Var win : pWindow; 

   nDrawBox(win,1,1,1,80,25);

nFrame

Syntax: nFrame(win : pWindow)

Description: nFrame adds a frame to the window win. The existing window color is used and the frame does not display until a following refresh of the window.

Example:

Var win : pWindow; 

   nFrame(win);

nRows

Syntax: nRows(win : pWindow) : integer

Description: nRows returns the number of rows in the window win.

Example:

Var
   win : pWindow;
   y : integer;

   nWindow(win,1,1,10,5);
   y := nRows(win); {returns 5}

nCols

Syntax: nCols(win : pWindow) : integer

Description: nCols returns the number of columns in the window win.

Example:

Var
   win : pWindow;
   x : integer;

   nWindow(win,1,1,10,5);
   x := nCols(win); {returns 10}

nHL

Syntax: nHL : longint

Description: Returns the value of the horizontal line character.

Example:

Var win : pWindow;

   nWriteAC(win,1,1,nHL);

nVL

Syntax: nVL : longint

Description: Returns the value of the vertical line character.

Example:

Var win : pWindow;

   nWriteAC(win,1,1,nVL);

nUL

Syntax: nUL : longint

Description: Returns the value of the upper left corner character.

Example:

Var win : pWindow;

   nWriteAC(win,1,1,nUL);

nLL

Syntax: nLL : longint

Description: Returns the value of the lower left corner character.

Example:

Var win : pWindow;

   nWriteAC(win,1,1,nLL);

nUR

Syntax: nUR : longint

Description: Returns the value of the upper right corner character.

Example:

Var win : pWindow;

   nWriteAC(win,1,1,nUR);

nLR

Syntax: nLR : longint

Description: Returns the value of the lower right corner character.

Example:

Var win : pWindow;

   nWriteAC(win,1,1,nLR);

nLT

Syntax: nLT : longint

Description: Returns the value of the left tee character.

Example:

Var win : pWindow;

   nWriteAC(win,1,1,nLT);

nRT

Syntax: nRT : longint

Description: Returns the value of the right tee character.

Example:

Var win : pWindow;

    nWriteAC(win,1,1,nRT);

nTT

Syntax: nTT : longint

Description: Returns the value of the top tee character.

Example:

Var win : pWindow;

   nWriteAC(win,1,1,nTT);

nBT

Syntax: nBT : longint

Description: Returns the value of the bottom tee character.

Example:

Var win : pWindow;

   nWriteAC(win,1,1,nBT);

nPL

Syntax: nPL : longint

Description: Returns the value of the plus character.

Example:

Var win : pWindow;

   nWriteAC(win,1,1,nPL);

nLA

Syntax: nLA : longint

Description: Returns the value of the left arrow character.

Example:

Var win : pWindow;

   nWriteAC(win,1,1,nLA);

nRA

Syntax: nRA : longint

Description: Returns the value of the right arrow character.

Example:

Var win : pWindow;

   nWriteAC(win,1,1,nRA);

nUA

Syntax: nUA : longint

Description: Returns the value of the up arrow character.

Example:

Var win : pWindow;

   nWriteAC(win,1,1,nUA);

nDA

Syntax: nDA : longint

Description: Returns the value of the down arrow character.

Example:

Var win : pWindow;

   nWriteAC(win,1,1,nDA);

nDI

Syntax: nDI : longint

Description: Returns the value of the diamond character.

Example:

Var win : pWindow;

   nWriteAC(win,1,1,nDI);

nCB

Syntax: nCB : longint

Description: Returns the value of the checkerboard character.

Example:

Var win : pWindow;

   nWriteAC(win,1,1,nCB);

nDG

Syntax: nDG : longint

Description: Returns the value of the degree character.

Example:

Var win : pWindow;

   nWriteAC(win,1,1,nDG);

nPM

Syntax: nPM : longint

Description: Returns the value of the plus/minus character.

Example:

Var win : pWindow;

   nWriteAC(win,1,1,nPM);

nBL

Syntax: nBL : longint

Description: Returns the value of the bullet character.

Example:

Var win : pWindow;

   nWriteAC(win,1,1,nBL);

nHLine

Syntax: nHLine(win : pWindow; col,row,attr,x : integer)

Description: Draws a horizontal line in the window win starting at position col/row, using color attr, ending at column x.

Example:

Var win : pWindow;

   { draw a line across the top of the window }
nHLine(win,1,1,31,80);

nVLine

Syntax: nVLine(win : pWindow; col,row,attr,y : integer)

Description: Draws a vertical line in the window win starting at position col/row, using color attr, ending at row y.

Example:

Var win : pWindow;

   { draw a line down the left edge of the window }
nVLine(win,1,1,31,25);

nWriteAC

Syntax: nWriteAC(win : pWindow; x,y : integer; att,acs_char : longint)

Description: Writes acs_char (a character from the alternate character set) at position x,y using the color value att. A normal value from the ncurses alternate character set is larger than $400000. If the value of acs_char is between 128 and 255, then we assume it to be the ordinal value from the IBM extended character set, and try to map it to curses correctly. If it does not map, then we just make it an alternate character and hope the output is what the programmer expected. Note: this will work on the Linux console just fine, but for other terminals the passed value must match the termcap definition for the alternate character. The cursor position is not updated.

Example:

Var
  win : pWindow;
    x : integer;

     { write a short horizontal line the slow way! }
     For x := 1 to 10 Do nWriteAC(win,x,1,31,nHL);
     { or }
     For x := 1 to 10 Do nWriteAC(win,x,1,31,196);

nIsBold

Syntax: nIsBold(att : integer) : boolean

Description: Returns TRUE if att represents a high intensity color attribute, otherwise returns FALSE.

Example:

{ the following will output "true" } If nIsBold(15) Then writeln('true') else writeln('false');

nSetColorPair

Syntax: nSetColorPair(att : integer) : integer

Description: Initialize an ncurses color pair using the color att. Returns the index of the color pair. This is primarily used by nCrt for internal color mapping.

Example:

Var i : integer;

   i := nSetColorPair(31);

nFWrite

Syntax: nFWrite(win : pwindow; x,y,att,x1 : integer; s : string)

Description: Write the string s to the window win at position x,y using the color value att. If x1 is greater than 0, then the line is cleared to that column using the color att. The cursor position is not updated. Omitting the win parameter will cause the string to be written to the current active window.

Example:

Var s : string;

    nFWrite(win,1,1,31,80,'Clear this line to the end');
    { or using the current active window... }
    nFWrite(1,1,31,80,'Clear this line to the end');

nEdit

Syntax: nEdit(win : pwindow; x,y,att,x1,cp : integer; s : string,var c : integer) : string

Description: Edit the string s in the window win at position x,y using the color value att. If x1 is greater than 0, then the edit field is limited to, and cleared to that column using the color att, otherwise the field width is limited to the window width. When nEdit exits, it returns the ordinal value, or an nkXX constant of the character pressed that caused nEdit to exit, in the variable c. The cursor is initially position at column cp. Omitting the win parameter will cause nEdit to work in the current active window. nEdit initializes to the string value passed in s. The value of s does not change but rather the edited value is returned by nEdit. nEdit uses an edit control object (tnEC) to modify it's default behavior.

{------------------------------------------------------------------------
  ClearMode = true : passed string is initialized to ''.
   IsHidden = true : causes a string of '*' to display in place of
                     the actual characters typed.
    InsMode        : toggle for insert/overwrite mode.
   ExitMode = true : nEdit exits after every keystroke.
            = false: nEdit only exits when #27,#13, or any extended
                     key *except* for Home,End,RArrow,LArrow.
    Special        : If a pressed key is found in this string, then
                     nEdit exits without processing.
    Picture        : An input mask string. See pxpic.txt for an
                     explanation of picture strings.
  CtrlColor        : The highlight color for embedded control characters.
      ChMap        : An array of character triplets describing a character
                     that is typed and what it should map to.
 ------------------------------------------------------------------------}
tnEC = Object
   ClearMode,
   IsHidden,
   InsMode,
   ExitMode,
   AppendMode : boolean;
   Special : string;
   Picture : string;
   CtrlColor : integer;
   ChMap : nChMap;
   Function AddChMap(_in,_out : integer) : integer;
   Procedure ClrChMap(idx : integer);
End;

Example:

Var
   s : string;
   c : integer;

   { force exit on tab }
   nEC.Special := Chr(nkTab);
   { make Ctrl/X = F10 }
   nEC.AddChMap(ord(^X),nkF10);
   
   Repeat
      s := nEdit(win,1,1,31,40,1,'Let us edit this string',c);
      Case c of
         nkF1 : DoF1Thing;
         nkF10 : DoF10Thing;
         nkTab : Do TabThing;
      End;
   Until c in [nkEnter,nkEsc];

Level III

nMakeWindow


nMakeWindow

Syntax: nMakeWindow( var win : tnWindow; { or pnWindow } x1,y1, x2,y2, ta,ba,ha : integer; hasframe : boolean; hdrpos : tnJustify; hdrtxt : string);

Description: This is a procedural wrapper to create a new instance of a tnWindow object. win can be a variable of either type tnWindow or pnWindow. If a variable of type tnWindow is used, then the object is simply initialized. If a variable of type pnWindow is used, then win is a pointer to the new object.

x1,y1 = upper lh corner on the window
x2,y2 = lower rh corner of the window.
ta = text color attribute.
ba = border color attribute.
ha = header color attribute.
hasframe - Set to true to create a single line border around the window.
hdrpos - Justify the header text using one of (left,center,right).
hdrtxt = A text string written to the top line of a bordered window.

Example:

Var
   win : tnWindow;
   
   { make a full screen in-active, non-displayed console window }
   { with a frame and header }
   nMakeWindow(win,1,1,25,80,31,30,14,true,center,'A New Window');
   { display and make active }
   win.Show;
   writeln('this appears in win');
   { hide it }
   win.Hide;
   { destroy it }
   win.Done;