home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / c / curses / src / _doecho.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-30  |  3.3 KB  |  108 lines

  1. /* -*-C-*-
  2.  *
  3.  *
  4.  * Filename : _doecho.c
  5.  *
  6.  * Author   : Simon J Raybould.    (sie@fulcrum.bt.co.uk).
  7.  *
  8.  * Date     : Friday 23rd August 1991.
  9.  *
  10.  * Desc     : Echos one character.
  11.  *
  12.  *
  13.  * THIS CODE IS NOT PUBLIC DOMAIN
  14.  * ==============================
  15.  * 
  16.  * This code is copyright Simon J Raybould 1991, all rights are reserved.
  17.  * All code, ideas, data structures and algorithms remain the property of the
  18.  * author. Neither the whole nor sections of this code may be used as part
  19.  * of other code without the authors consent. If you wish to use some of this
  20.  * code then please email me at (sie@fulcrum.bt.co.uk).
  21.  *
  22.  * This source is not public domain, so you do not have any right to alter it
  23.  * or sell it for personal gain. The source is provided purely for reference
  24.  * purposes. You may re-compile the source with any compiler you choose.
  25.  * You must not distribute altered copies without the authors consent. My
  26.  * intention is that the source will help people isolate any bugs much more
  27.  * effectivly.
  28.  *
  29.  * Disclaimer
  30.  * ==========
  31.  *
  32.  * No implication is made as to this code being fit for any purpose at all.
  33.  * I (the author) shall not be held responsible for any loss of data or damage 
  34.  * to property that may result from its use or misuse.
  35.  *
  36.  *
  37.  * Revision History
  38.  * ================
  39.  *
  40.  * $Log:    _doecho.c,v $
  41.  * Revision 1.4  92/06/10  23:45:10  sie
  42.  * Added serial support.
  43.  * 
  44.  * Revision 1.3  91/12/30  10:31:24  sie
  45.  * Removed LRLine and LRATTRS.
  46.  * The speed increase caused by them was too insignificant.
  47.  * 
  48.  * Revision 1.2  91/12/28  14:02:00  sie
  49.  * Removed WinStat.
  50.  * Renamed LineElement as lnel.
  51.  * 
  52.  * Revision 1.1  91/09/07  11:52:57  sie
  53.  * Initial revision
  54.  * 
  55.  *
  56.  */
  57.  
  58. static char *rcsid = "$Header: SRC:lib/curses/src/RCS/_doecho.c,v 1.4 92/06/10 23:45:10 sie Exp $";
  59.  
  60. #include "acurses.h"
  61.  
  62.  
  63. void DoEcho(WINDOW *WinPtr, char c)
  64. {
  65.   short x, y;
  66.   char Buffer[ANSIBUFSIZ];
  67.   
  68.   if(c == BS || c == CR)        /* Don't echo Backspace or Return */
  69.     return;
  70.  
  71.   if(CursesType == CUST_CURSES) {
  72.     x = CursorCol * 8;
  73.     y = 6 + CursorLine * 8;
  74.     ZapCursor();
  75.     SetDrMd(RPort, JAM2);
  76.     SetAPen(RPort, WinPtr->_attrs & A_CLRPART);
  77.     Move(RPort, x, y);
  78.     Text(RPort, &c, 1);
  79.     DrawCursor();
  80.   } else if(CursesType == ANSI_CURSES) {
  81.     ANSIMove(CursorLine, CursorCol);
  82.     if(WinPtr->LnArry[CursorLine].ATTRS[CursorCol] & A_ATRPART) {
  83.       sprintf(Buffer, "\033[0;%d;40m", WinPtr->LnArry[CursorLine].ATTRS[CursorCol] & A_CLRPART+30);
  84.       if(WinPtr->LnArry[CursorLine].ATTRS[CursorCol] & A_BOLD)
  85.     Buffer[2] = '1';
  86.       if(WinPtr->LnArry[CursorLine].ATTRS[CursorCol] & A_UNDERLINE)
  87.     Buffer[2] = '4';
  88.       if(WinPtr->LnArry[CursorLine].ATTRS[CursorCol] & A_STANDOUT)
  89.     Buffer[2] = '7';
  90.     }
  91.     write(1, &c, 1);
  92.     if(WinPtr->LnArry[CursorLine].ATTRS[CursorCol] & A_ATRPART)
  93.       write(1, "\033[0m", 4);
  94.   }
  95.   /* Update curscr */
  96.   if(WinPtr != curscr) {
  97.     wmove(curscr, CursorLine, CursorCol);
  98.     waddch(curscr, c);
  99.   }
  100.   /* Update Line structure */
  101.   WinPtr->LnArry[CursorLine-WinPtr->_begy].Line[CursorCol-WinPtr->_begx] = c;
  102.   WinPtr->LnArry[CursorLine-WinPtr->_begy].ATTRS[CursorCol-WinPtr->_begx] = WinPtr->_attrs;
  103.   /* Move current position one to the right */
  104.   if(++WinPtr->_curx > WinPtr->_maxx)
  105.     WinPtr->_curx = WinPtr->_maxx;
  106.   mvcur(CursorLine, CursorCol, CursorLine, CursorCol + 1);
  107. }
  108.