home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / hl10osrc.zoo / Include / Terminal.h < prev    next >
Text File  |  2009-11-06  |  6KB  |  202 lines

  1. /* -*- Mode: C -*- */
  2. /* Terminal.h - Video terminal interface
  3.  *        Inspired by the Terminal class described in "C++,
  4.  *        a guide for C programmers", by Sharam Hekmatpour,
  5.  *        (c) 1990 by Prentice Hall of  Australia Pty Ltd.
  6.  *        This version uses termcap and is not hardwired
  7.  *        for a particular terminal type.  Also, I only
  8.  *        implemented a bare terminal class and did not
  9.  *        include the higher level classes (windows,
  10.  *        menus, and forms).
  11.  * Created by Robert Heller on Fri Dec  6 21:10:04 1991
  12.  *
  13.  * ------------------------------------------------------------------
  14.  * Home Libarian by Deepwoods Software
  15.  * Common Header Files
  16.  * ------------------------------------------------------------------
  17.  * Modification History:
  18.  * ------------------------------------------------------------------
  19.  * Contents:
  20.  * ------------------------------------------------------------------
  21.  * 
  22.  * 
  23.  * Copyright (c) 1991,1992 by Robert heller (D/B/A Deepwoods Software)
  24.  *        All Rights Reserved
  25.  * 
  26.  */
  27. #ifndef _TERMINAL_
  28. #define _TERMINAL_
  29. #include <stream.h>
  30. #include <common.h>
  31. #include <ctype.h>
  32. #ifdef MESSYDOS
  33. #include <gppconio.h>
  34. #include <keybd.h>
  35. #else
  36. #include <termcap.h>
  37. #endif
  38.  
  39. #ifndef MESSYDOS
  40. #define PosCode(buf,r,c) CopyCode(buf,tgoto(CM,c,r))
  41. #endif
  42. class CommandScreen;
  43. class EditForm;
  44. class ScrollPrompt;
  45. class LLScrollPrompt;
  46. // Terminal class.  Based on termcap.
  47. class Terminal    {
  48. // Terminal mode magic
  49. #ifdef OSK
  50.     static sgbuf ttym;            // Vanila terminal modes (OSK)
  51.     static sgbuf xttym;            // Operating terminal modes (OSK)
  52. #endif
  53.     static ErrFun errFun;            // user error function
  54.     const  bufSize = 512;            // buffer size
  55.     static char termBuf[bufSize];        // scratch buffer
  56. #ifndef MESSYDOS
  57.     const TCapsLen = 1024;            // Termcap buffer size
  58.     static char TermType[48];        // terminal type name
  59.     static char TCapBuf[TCapsLen];        // termcap buffer
  60.     static char tcapbuf[TCapsLen];        // copy
  61.     const char* const BELL = "\007";    // bell character
  62. #endif
  63.     static Terminal* term;            // self reference
  64. #ifndef MESSYDOS
  65.     // termcap capabilities
  66.     static char* BC;            // backspace character
  67.     static char* UP;            // up line sequence
  68.     static char* CL;            // clear screen
  69.     static char* CM;            // cursor movement
  70.     static char* CE;            // clear to eol
  71.     static char* CD;            // clear to eos
  72.     static char* SO;            // standout start
  73.     static char* SE;            // standout end
  74.     static char* HO;            // home cursor
  75.     static char* KD;            // down arrow key
  76.     static char* KU;            // up arrow key
  77.     static char* KR;            // right arrow key
  78.     static char* KL;            // left arrow key
  79.     static char* KH;            // home key
  80.     static char* KB;            // backspace key
  81.     static char* TI;            // terminal init
  82.     static char* TE;            // terminal de-init
  83.     static short ospeed;            // baud rate (used for padding)
  84.     static char PC;                // pad character
  85.     // copy code to a buffer
  86.     char*  CopyCode    (char* buf,const char* code)
  87.             {strcpy(buf,code); return buf + strlen(code);}
  88.     // write control codes
  89.     void WriteCode(const char*);
  90.     void WriteCodeLines(const char*,int);
  91. #endif
  92.     static short cline;            // current line
  93.     static short ccol;            // current column
  94.     static short lines;            // screen lines
  95.     static short colms;            // screen columns
  96. public:
  97.     // do various things to the terminal
  98. #ifdef MESSYDOS
  99.     inline void RevsPen    ()    {textbackground(LIGHTGRAY);
  100.                      textcolor(BLACK);}
  101.     inline void PlainPen    ()    {textbackground(BLACK);
  102.                      textcolor(WHITE);}
  103.     inline void InitChars    ()     {};
  104.     inline void ExitChars    ()    {};
  105.     inline void Home    ()    {PenPos(0,0);}
  106.     inline void Clear    ()    {clrscr();gotoxy(ccol+1,cline+1);}
  107.     inline void ClearEOL    ()    {clreol();gotoxy(ccol+1,cline+1);}
  108.     inline void ClearEOS    ()    {clreol();
  109.                      for (int r=cline+1;r<lines;r++)
  110.                      {
  111.                          gotoxy(1,r+1);
  112.                          clreol();
  113.                      }
  114.                      gotoxy(ccol+1,cline+1);}
  115.     void Bell    ();
  116.  
  117.     Terminal &put(unsigned char ch);
  118.     inline Terminal &put(unsigned char *s) {
  119.         while (*s) {put(*s);s++;}
  120.         return(*this);
  121.     }
  122.     inline Terminal &put(unsigned char *s,int n)
  123.             {for (int i=0;i<n;i++) put(*s++);return(*this);}
  124. #else
  125.     void RevsPen    ()    {WriteCode(SO);}
  126.     void PlainPen    ()    {WriteCode(SE);}
  127.     void InitChars    ()    {WriteCode(TI);}
  128.     void ExitChars    ()    {WriteCode(TE);}
  129.     void Home    ()    {WriteCode(HO); cline = 0; ccol = 0;}
  130.     void Clear    ()    {if (CL == 0) {
  131.                     WriteCode(HO);WriteCodeLines(CD,lines);
  132.                  } else WriteCodeLines(CL,lines);
  133.                  char buf[50];
  134.                  PosCode(buf,cline,ccol);
  135.                  WriteCode(buf);}
  136.     void ClearEOL    ()    {WriteCode(CE);}
  137.     void CLearEOS    ()    {WriteCodeLines(CD,lines-cline);}
  138.     void Bell    ()    {WriteCode(BELL);}
  139. #endif
  140.     // error handler reference
  141.     inline ErrFun& ErrorFun ()    {return errFun;}
  142.     // Constructor and descructor
  143.            Terminal ();
  144.           ~Terminal ();
  145.     // set cursor position
  146. #ifdef MESSYDOS
  147.     inline void PenPos     (int row,int col)
  148.         {gotoxy(col+1,row+1);cline = row;ccol = col;}
  149. #else
  150.     void PenPos    (int row,int col);
  151. #endif
  152.     // get a key from the keyboard (no echo, no wait for eol, no editing)
  153.     int  GetKey    ();
  154.     // key available??
  155.     Boolean KeyAvailable ();
  156.     // error handler
  157.     void Error    (ErrKind err,const char* msg);
  158.     // display a message
  159.     void Message    (const char* msg);
  160.     // get a text string from the keyboard.  Allows editing
  161.     int  GetLine    (char* buffer,int bufsize,
  162.              const char* terminators = "\n\r");
  163.     // Put a character on the screen someplace
  164.     void PutCharAt    (int row,int col,int ch);
  165.     // Put a string someplace on the screen
  166.     void PutStrAt    (int row,int col,const char* str);
  167.     void PutStrAt    (int row,int col,const short* str);
  168.     char* PutStrInBox (int row,int col,int width,int height,
  169.                const char* str);
  170.     // get a text string from the keyboard.  Allows editing
  171.     inline int  PromptLine    (int row,int col,const char* prompt,
  172.              char* buffer,int bufsize,
  173.              const char* terminators = "\n\r")
  174.         {PutStrAt(row,col,prompt);return(GetLine(buffer,bufsize,
  175.                              terminators));}
  176.     inline Boolean YorNp(int row,int col,const char* prompt)
  177.         {int key;
  178.          PutStrAt(row,col,prompt);
  179.          while (true) {
  180.              key = GetKey();
  181.              if (key == 'y' || key == 'Y') {
  182.                  PutStrAt(cline,ccol,"Yes");
  183.                  return(true);
  184.              } else if (key == 'n' || key == 'N') {
  185.                  PutStrAt(cline,ccol,"No");
  186.                  return(false);
  187.              } else Bell();
  188.          }
  189.         }
  190.     // fork a sub-process (this is here to handle the terminal modes
  191.     int  forkprog    (const char** argv);
  192.     // handle an interrupt
  193.     friend int Interrupt();
  194.     friend class CommandScreen;
  195.     friend class EditForm;
  196.     friend class ScrollPrompt;
  197.     friend class LLScrollPrompt;
  198. };
  199.  
  200. #endif  _TERMINAL_
  201.  
  202.