1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
/*
* term.cc -- simple split mode terminal
*
* Copyright (C) 1999-2004 Pawel Jalocha, SP9VRC
*
* This file is part of MT63.
*
* MT63 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MT63 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MT63; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <stdio.h>
#include <string.h>
#define NODELAY_HACK 1 // nodelay() does not work in ncurses of Linux ?!
// we hack it with a routine from stdinr.cc
#ifdef __MSDOS__
#include <conio.h>
#else
#include <curses.h>
#ifdef NODELAY_HACK
#include "stdinr.h"
#endif
#endif
#include "term.h"
#ifdef __MSDOS__
SplitTerm::SplitTerm() { Init=0; }
SplitTerm::~SplitTerm() { }
void SplitTerm::Close(void)
{ textcolor(LIGHTGRAY); textbackground(BLACK);
_setcursortype(_NORMALCURSOR);
window(1,1,Width,Height); clrscr(); }
int SplitTerm::Preset(int TxLines)
{
Width=80; Height=25;
TxLen=TxLines;
if(TxLen==0) { RxLen=Height-TxLen-2; }
else { RxLen=Height-TxLen-4; }
RxPos=2;
TxPos=RxPos+RxLen+2;
StatPos[0]=1;
StatPos[1]=RxPos+RxLen;
StatPos[2]=RxPos+RxLen+1;
StatPos[3]=TxPos+TxLen;
window(1,1,Width,Height); clrscr();
RxCurX=1; RxCurY=1; RxAct=0;
TxCurX=1; TxCurY=1; TxAct=0;
return 0;
}
int SplitTerm::UserInp(int &key)
{ if(kbhit()) { key=getch(); return 1; }
return 0; }
void SplitTerm::RxOut(char ch)
{ if(!RxAct)
{ window(1,RxPos,Width,RxPos+RxLen-1);
gotoxy(RxCurX,RxCurY); RxAct=1; TxAct=0; _setcursortype(_NORMALCURSOR); }
ChOut(ch); RxCurX=wherex(); RxCurY=wherey(); }
void SplitTerm::TxOut(char ch)
{ if(!TxAct)
{ window(1,TxPos,Width,TxPos+TxLen-1);
gotoxy(TxCurX,TxCurY); TxAct=1; RxAct=0; _setcursortype(_NORMALCURSOR); }
ChOut(ch); TxCurX=wherex(); TxCurY=wherey(); }
void SplitTerm::ChOut(char ch)
{ if(ch=='\0') return;
textcolor(LIGHTGRAY); textbackground(BLACK);
if((ch&0x80)||(ch>=' ')||(ch==0x08)||(ch==0x09)) putch(ch);
else if(ch=='\n') { if(wherey()>1) putch(ch); }
else if(ch=='\r') { putch(ch); putch('\n'); }
else { textcolor(BLACK); textbackground(LIGHTGRAY); putch(ch+'@'); }
}
void SplitTerm::Status(int Stat, char *Str)
{ int i,y=StatPos[Stat];
RxAct=0; TxAct=0; window(1,y,Width,y);
textcolor(BLACK); textbackground(LIGHTGRAY); _setcursortype(_NOCURSOR);
cprintf("%s",Str); for(i=strlen(Str); i<Width-1; i++) putch(' '); }
#else // Linux code with ncurses
SplitTerm::SplitTerm()
{ Init=0; }
SplitTerm::~SplitTerm()
{ if(Init) { erase(); refresh(); endwin(); } }
void SplitTerm::Close(void)
{ if(Init) { erase(); refresh(); endwin(); Init=0; } }
int SplitTerm::Preset(int TxLines)
{
if(Init) endwin();
initscr(); cbreak(); noecho(); nonl(); // raw();
// nodelay(stdscr,TRUE); // nodelay() has no effect, what's wrong ?!
// halfdelay(1); // half-delay seem to work, but it waits for too long...
intrflush(stdscr,FALSE); keypad(stdscr,TRUE);
scrollok(stdscr,TRUE);
erase();
Init=1;
Width=COLS; Height=LINES;
TxLen=TxLines;
if(TxLen==0) { RxLen=Height-TxLen-2; }
else { RxLen=Height-TxLen-4; }
RxPos=1;
TxPos=RxPos+RxLen+2;
StatPos[0]=0;
StatPos[1]=RxPos+RxLen;
StatPos[2]=RxPos+RxLen+1;
StatPos[3]=TxPos+TxLen;
RxCurX=0; RxCurY=RxPos; RxAct=0;
TxCurX=0; TxCurY=TxPos; TxAct=0;
refresh();
return 0;
}
#ifdef NODELAY_HACK
int SplitTerm::UserInp(int &key)
{ if(StdinReady()) { key=getch(); return 1; }
else return 0; }
#else
int SplitTerm::UserInp(int &key)
{ key=getch(); return key==ERR ? 0 : 1; }
#endif
void SplitTerm::ChOut(char ch)
{ int x,y;
if(ch=='\0') return;
attrset(A_NORMAL);
if((ch&0x80)||(ch>=' ')||(ch==0x08)||(ch==0x09)) addch(ch);
else if(ch=='\n') { getyx(stdscr,y,x); if(x>0) addch(ch); }
else if(ch=='\r') { addch('\n'); }
else { attrset(A_REVERSE); addch(ch+'@'); }
}
void SplitTerm::RxOut(char ch)
{ if(!RxAct)
{ setscrreg(RxPos,RxPos+RxLen-1);
move(RxCurY,RxCurX); RxAct=1; TxAct=0; }
ChOut(ch); getyx(stdscr,RxCurY,RxCurX); refresh(); }
void SplitTerm::RxStr(char *str)
{ if(!RxAct)
{ setscrreg(RxPos,RxPos+RxLen-1);
move(RxCurY,RxCurX); RxAct=1; TxAct=0; }
attrset(A_NORMAL); addstr(str);
getyx(stdscr,RxCurY,RxCurX); refresh(); }
void SplitTerm::TxOut(char ch)
{ if(!TxAct)
{ setscrreg(TxPos,TxPos+TxLen-1);
move(TxCurY,TxCurX); TxAct=1; RxAct=0; }
ChOut(ch); getyx(stdscr,TxCurY,TxCurX); refresh(); }
void SplitTerm::Status(int Stat, char *Str)
{ int i,y=StatPos[Stat];
RxAct=0; TxAct=0; move(y,0);
attrset(A_REVERSE);
for(i=0; Str[i]; i++) addch(Str[i]);
for( ; i<Width-1; i++) addch(' ');
refresh(); }
#endif
|