Skip to content
Snippets Groups Projects
Commit adb151ee authored by deuce's avatar deuce
Browse files

Remove OpenDoors in favour of new stdio ANSI personality.

parent 3c288dd9
No related branches found
No related tags found
No related merge requests found
......@@ -3,12 +3,10 @@
# XCURSES = Use XCurses
# NEED_CIOWRAP = Set flage suitable for using with ciowrap lib
# NO_X = Don't use X version of ciowrap
# INCLUDE_OPENDOOR = Include support for OpenDoors library
# You really should set this first.
CONIO_SRC ?= $(XPDEV)../conio/
UIFC_SRC ?= $(XPDEV)../uifc/
OPENDOOR_SRC ?= $(XPDEV)../odoors/
CIOWRAP_CFLAGS += -I$(CONIO_SRC)
# ciowrap stuff
......@@ -20,11 +18,11 @@ ifndef NO_X
else
CIOWRAP_CFLAGS += -DNO_X
endif
#ifdef INCLUDE_OPENDOOR
CIOWRAP_OBJS += $(LIBODIR)/od_cio.o
CIOWRAP_CFLAGS += -I$(OPENDOOR_SRC) -DINCLUDE_OPENDOOR
CIOWRAP_LDFLAGS += -L$(OPENDOOR_SRC) -lODoors
#endif
ifdef USE_ANSI
CIOWRAP_CFLAGS += -DUSE_ANSI
CIOWRAP_LDFLAGS += -pthread
CIOWRAP_OBJS += $(LIBODIR)/ansi_cio.o $(LIBODIR)/threadwrap.o
endif
CIOWRAP_OBJS += $(LIBODIR)/curs_cio.o $(LIBODIR)/conio.o
CIOWRAP_CFLAGS += -I$(UIFC_SRC)
......
#include <fcntl.h>
#include <stdarg.h>
#include <genwrap.h>
#include <threadwrap.h>
#ifdef __unix__
#include <termios.h>
#endif
#include "conio.h"
#include "ansi_cio.h"
WORD ansi_curr_attr=0x07<<8;
int ansi_rows=24;
int ansi_cols=80;
int ansi_nextchar;
int ansi_got_row=0;
int ansi_got_col=0;
int ansi_esc_delay=25;
const int ansi_tabs[10]={9,17,25,33,41,49,57,65,73,80};
const int ansi_colours[8]={0,4,2,6,1,5,3,7};
static WORD ansi_inch;
static char ansi_raw_inch;
struct termios tio_default; /* Initial term settings */
WORD *vmem;
int ansi_row=0;
int ansi_col=0;
int force_move=1;
/* Control sequence table definitions. */
typedef struct
{
char *pszSequence;
int chExtendedKey;
} tODKeySequence;
#define ANSI_KEY_UP 72<<8
#define ANSI_KEY_DOWN 80<<8
#define ANSI_KEY_RIGHT 0x4d<<8
#define ANSI_KEY_LEFT 0x4b<<8
#define ANSI_KEY_HOME 0x47<<8
#define ANSI_KEY_END 0x4f<<8
#define ANSI_KEY_F1 0x3b<<8
#define ANSI_KEY_F2 0x3c<<8
#define ANSI_KEY_F3 0x3d<<8
#define ANSI_KEY_F4 0x3e<<8
#define ANSI_KEY_F5 0x3f<<8
#define ANSI_KEY_F6 0x40<<8
#define ANSI_KEY_F7 0x41<<8
#define ANSI_KEY_F8 0x42<<8
#define ANSI_KEY_F9 0x43<<8
#define ANSI_KEY_F10 0x44<<8
#define ANSI_KEY_PGUP 0x49<<8
#define ANSI_KEY_PGDN 0x51<<8
#define ANSI_KEY_INSERT 0x52<<8
#define ANSI_KEY_DELETE 0x53<<8
tODKeySequence aKeySequences[] =
{
/* VT-52 control sequences. */
{"\033A", ANSI_KEY_UP},
{"\033B", ANSI_KEY_DOWN},
{"\033C", ANSI_KEY_RIGHT},
{"\033D", ANSI_KEY_LEFT},
{"\033H", ANSI_KEY_HOME},
{"\033K", ANSI_KEY_END},
{"\033P", ANSI_KEY_F1},
{"\033Q", ANSI_KEY_F2},
{"\033?w", ANSI_KEY_F3},
{"\033?x", ANSI_KEY_F4},
{"\033?t", ANSI_KEY_F5},
{"\033?u", ANSI_KEY_F6},
{"\033?q", ANSI_KEY_F7},
{"\033?r", ANSI_KEY_F8},
{"\033?p", ANSI_KEY_F9},
/* Control sequences common to VT-100/VT-102/VT-220/VT-320/ANSI. */
{"\033[A", ANSI_KEY_UP},
{"\033[B", ANSI_KEY_DOWN},
{"\033[C", ANSI_KEY_RIGHT},
{"\033[D", ANSI_KEY_LEFT},
{"\033[M", ANSI_KEY_PGUP},
{"\033[H\x1b[2J", ANSI_KEY_PGDN},
{"\033[H", ANSI_KEY_HOME},
{"\033[K", ANSI_KEY_END},
{"\033OP", ANSI_KEY_F1},
{"\033OQ", ANSI_KEY_F2},
{"\033OR", ANSI_KEY_F3},
{"\033OS", ANSI_KEY_F4},
/* VT-220/VT-320 specific control sequences. */
{"\033[17~", ANSI_KEY_F6},
{"\033[18~", ANSI_KEY_F7},
{"\033[19~", ANSI_KEY_F8},
{"\033[20~", ANSI_KEY_F9},
{"\033[21~", ANSI_KEY_F10},
/* ANSI-specific control sequences. */
{"\033[L", ANSI_KEY_HOME},
{"\033Ow", ANSI_KEY_F3},
{"\033Ox", ANSI_KEY_F4},
{"\033Ot", ANSI_KEY_F5},
{"\033Ou", ANSI_KEY_F6},
{"\033Oq", ANSI_KEY_F7},
{"\033Or", ANSI_KEY_F8},
{"\033Op", ANSI_KEY_F9},
/* PROCOMM-specific control sequences (non-keypad alternatives). */
{"\033OA", ANSI_KEY_UP},
{"\033OB", ANSI_KEY_DOWN},
{"\033OC", ANSI_KEY_RIGHT},
{"\033OD", ANSI_KEY_LEFT},
{"\033OH", ANSI_KEY_HOME},
{"\033OK", ANSI_KEY_END},
/* Terminator */
{"",0}
};
void ansi_sendch(char ch)
{
struct text_info ti;
if(!ch)
ch=' ';
if(ansi_row<ansi_rows-1 || ansi_col<ansi_cols-1) {
fwrite(&ch,1,1,stdout);
if(ch<' ')
force_move=1;
}
}
void ansi_sendstr(char *str,int len)
{
if(len==-1)
len=strlen(str);
fwrite(str,len,1,stdout);
}
int ansi_puttext(int sx, int sy, int ex, int ey, unsigned char *fill)
{
int x,y;
unsigned char *out;
WORD sch;
struct text_info ti;
int attrib;
gettextinfo(&ti);
if( sx < 1
|| sy < 1
|| ex < 1
|| ey < 1
|| sx > ti.screenwidth
|| sy > ti.screenheight
|| sx > ex
|| sy > ey
|| ex > ti.screenwidth
|| ey > ti.screenheight
|| fill==NULL)
return(0);
out=fill;
attrib=ti.attribute;
if((ey-sy+1)*(ex-sx+1)>32)
force_move=1;
for(y=sy-1;y<ey;y++) {
for(x=sx-1;x<ex;x++) {
sch=*(out++);
if(sch==27)
sch=' ';
if(sch==0)
sch=' ';
sch |= (*(out++))<<8;
if(vmem[y*ansi_cols+x]==sch)
continue;
vmem[y*ansi_cols+x]=sch;
ansi_gotoxy(x+1,y+1);
if(attrib!=sch>>8) {
textattr(sch>>8);
attrib=sch>>8;
}
ansi_sendch(sch&0xff);
ansi_col++;
if(ansi_col>=ansi_cols) {
ansi_col=0;
ansi_row++;
if(ansi_row>=ansi_rows) {
ansi_col=ansi_cols-1;
ansi_row=ansi_rows-1;
}
}
}
}
if((ey-sy+1)*(ex-sx+1)>32)
force_move=1;
gotoxy(ti.curx,ti.cury);
if(attrib!=ti.attribute)
textattr(ti.attribute);
}
int ansi_gettext(int sx, int sy, int ex, int ey, unsigned char *fill)
{
int x,y;
unsigned char *out;
WORD sch;
struct text_info ti;
gettextinfo(&ti);
if( sx < 1
|| sy < 1
|| ex < 1
|| ey < 1
|| sx > ti.screenwidth
|| sy > ti.screenheight
|| sx > ex
|| sy > ey
|| ex > ti.screenwidth
|| ey > ti.screenheight
|| fill==NULL)
return(0);
out=fill;
for(y=sy-1;y<ey;y++) {
for(x=sx-1;x<ex;x++) {
sch=vmem[y*ansi_cols+x];
*(out++)=sch & 0xff;
*(out++)=sch >> 8;
}
}
}
void ansi_textattr(unsigned char attr)
{
char str[16];
int fg,ofg;
int bg,obg;
int bl,obl;
int br,obr;
int oa;
bl=attr>>7;
bg=(attr>>4)&0x7;
fg=attr&0x07;
br=(attr>>3)&0x01;
oa=ansi_curr_attr>>8;
obl=oa>>7;
obg=(oa>>4)&0x7;
ofg=oa&0x07;
obr=(oa>>3)&0x01;
ansi_curr_attr=attr<<8;
ansi_sendstr(str,sprintf(str,"%c[%d;%d;3%d;4%dm",27,bl?0:5,br?1:2,ansi_colours[fg],ansi_colours[bg]));
}
static void ansi_keyparse(void *par)
{
int gotesc=0;
char seq[64];
int ch;
int waited=0;
int i;
char *p;
for(;;) {
while(!ansi_raw_inch
&& (gotesc || (!gotesc && !seq[0]))) {
waited++;
if(waited>=ansi_esc_delay) {
waited=0;
gotesc=0;
}
else
SLEEP(1);
}
if(!gotesc && seq[0]) {
while(ansi_inch)
SLEEP(1);
ch=seq[0];
for(p=seq;*p;*p=*(++p));
ansi_inch=ch;
continue;
}
else {
ch=ansi_raw_inch;
ansi_raw_inch=0;
}
switch(gotesc) {
case 1: /* Escape */
waited=0;
if(strlen(seq)>=sizeof(seq)-2) {
gotesc=0;
break;
}
seq[strlen(seq)+1]=0;
seq[strlen(seq)]=ch;
if((ch<'0' || ch>'9') /* End of ESC sequence */
&& ch!=';'
&& ch!='?'
&& (strlen(seq)==2?ch != '[':1)
&& (strlen(seq)==2?ch != 'O':1)) {
for(i=0;aKeySequences[i].pszSequence[0];i++) {
if(!strcmp(seq,aKeySequences[i].pszSequence)) {
gotesc=0;
seq[0]=0;
while(ansi_inch)
SLEEP(1);
ansi_inch=aKeySequences[i].chExtendedKey;
break;
}
}
if(!aKeySequences[i].pszSequence[0])
gotesc=0;
}
break;
default:
if(ch==27) {
seq[0]=27;
seq[1]=0;
gotesc=1;
waited=0;
break;
}
while(ansi_inch)
SLEEP(1);
ansi_inch=ch;
break;
}
}
}
static void ansi_keythread(void *params)
{
_beginthread(ansi_keyparse,1024,NULL);
for(;;) {
if(!ansi_raw_inch)
ansi_raw_inch=fgetc(stdin);
else
SLEEP(1);
}
}
int ansi_kbhit(void)
{
return(ansi_inch);
}
void ansi_delay(long msec)
{
SLEEP(msec);
}
int ansi_wherey(void)
{
return(ansi_row+1);
}
int ansi_wherex(void)
{
return(ansi_col+1);
}
/* Put the character _c on the screen at the current cursor position.
* The special characters return, linefeed, bell, and backspace are handled
* properly, as is line wrap and scrolling. The cursor position is updated.
*/
int ansi_putch(unsigned char ch)
{
struct text_info ti;
WORD sch;
int i;
char buf[2];
buf[0]=ch;
buf[1]=ansi_curr_attr>>8;
gettextinfo(&ti);
switch(ch) {
case '\r':
gotoxy(1,wherey());
break;
case '\n':
if(wherey()==ti.winbottom-ti.wintop+1)
wscroll();
else
gotoxy(wherex(),wherey()+1);
break;
case '\b':
if(ansi_col>ti.winleft-1) {
buf[0]=' ';
gotoxy(wherex()-1,wherey());
puttext(ansi_col+1,ansi_row+1,ansi_col+1,ansi_row+1,buf);
}
break;
case 7: /* Bell */
ansi_sendch(7);
break;
case '\t':
for(i=0;i<10;i++) {
if(ansi_tabs[i]>ansi_col+1) {
while(ansi_col+1<ansi_tabs[i]) {
putch(' ');
}
break;
}
}
if(i==10) {
putch('\r');
putch('\n');
}
break;
default:
if(wherey()==ti.winbottom-ti.wintop+1
&& wherex()==ti.winright-ti.winleft+1) {
gotoxy(1,wherey());
puttext(ansi_col+1,ansi_row+1,ansi_col+1,ansi_row+1,buf);
wscroll();
}
else {
if(wherex()==ti.winright-ti.winleft+1) {
gotoxy(1,ti.cury+1);
puttext(ansi_col+1,ansi_row+1,ansi_col+1,ansi_row+1,buf);
}
else {
gotoxy(ti.curx+1,ti.cury);
puttext(ansi_col+1,ansi_row+1,ansi_col+1,ansi_row+1,buf);
}
}
break;
}
return(ch);
}
void ansi_gotoxy(int x, int y)
{
struct text_info ti;
char str[16];
if(x < 1
|| x > ansi_cols
|| y < 1
|| y > ansi_rows)
return;
if(force_move) {
force_move=0;
sprintf(str,"%c[%d;%dH",27,y,x);
}
else {
if(x==1 && ansi_col != 0) {
ansi_sendch('\r');
force_move=0;
ansi_col=0;
}
if(x==ansi_col+1) {
if(y==ansi_row+1) {
str[0]=0;
}
else {
if(y<ansi_row+1) {
if(y==ansi_row)
strcpy(str,"\033[A");
else
sprintf(str,"%c[%dA",27,ansi_row+1-y);
}
else {
if(y==ansi_row+2)
strcpy(str,"\033[B");
else
sprintf(str,"%c[%dB",27,y-ansi_row-1);
}
}
}
else {
if(y==ansi_row+1) {
if(x<ansi_col+1) {
if(x==ansi_col)
strcpy(str,"\033[D");
else
sprintf(str,"%c[%dD",27,ansi_col+1-x);
}
else {
if(x==ansi_col+2)
strcpy(str,"\033[C");
else
sprintf(str,"%c[%dC",27,x-ansi_col-1);
}
}
else {
sprintf(str,"%c[%d;%dH",27,y,x);
}
}
}
ansi_sendstr(str,-1);
ansi_row=y-1;
ansi_col=x-1;
}
void ansi_gettextinfo(struct text_info *info)
{
info->currmode=3;
info->screenheight=ansi_rows;
info->screenwidth=ansi_cols;
info->curx=wherex();
info->cury=wherey();
info->attribute=ansi_curr_attr>>8;
}
void ansi_setcursortype(int type)
{
switch(type) {
case _NOCURSOR:
case _SOLIDCURSOR:
default:
break;
}
}
int ansi_getch(void)
{
int ch;
while(!ansi_inch)
SLEEP(1);
ch=ansi_inch&0xff;
ansi_inch=ansi_inch>>8;
return(ch);
}
int ansi_getche(void)
{
int ch;
if(ansi_nextchar)
return(ansi_getch());
ch=ansi_getch();
if(ch)
putch(ch);
return(ch);
}
int ansi_beep(void)
{
putch(7);
return(0);
}
void ansi_textmode(int mode)
{
}
#ifdef __unix__
void ansi_fixterm(void)
{
tcsetattr(STDIN_FILENO,TCSANOW,&tio_default);
}
#endif
void ansi_initciowrap(long inmode)
{
int i;
char *init="\033[2J\033[1;1H\033[0m";
#ifdef _WIN32
_setmode(fileno(stdout),_O_BINARY);
_setmode(fileno(stdin),_O_BINARY);
setvbuf(stdout, NULL, _IONBF, 0);
#else
struct termios tio_raw;
if (isatty(STDIN_FILENO)) {
tcgetattr(STDIN_FILENO,&tio_default);
tio_raw = tio_default;
cfmakeraw(&tio_raw);
tcsetattr(STDIN_FILENO,TCSANOW,&tio_raw);
setvbuf(stdout, NULL, _IONBF, 0);
atexit(ansi_fixterm);
}
#endif
vmem=(WORD *)malloc(ansi_rows*ansi_cols*sizeof(WORD));
ansi_sendstr(init,-1);
for(i=0;i<ansi_rows*ansi_cols;i++)
vmem[i]=0x0720;
_beginthread(ansi_keythread,1024,NULL);
}
/* $Id$ */
#ifdef __unix__
#include "conio.h"
#ifdef __cplusplus
extern "C" {
#endif
int ansi_puttext(int sx, int sy, int ex, int ey, unsigned char *fill);
int ansi_gettext(int sx, int sy, int ex, int ey, unsigned char *fill);
void ansi_textattr(unsigned char attr);
int ansi_kbhit(void);
void ansi_delay(long msec);
int ansi_wherey(void);
int ansi_wherex(void);
int ansi_putch(unsigned char ch);
void ansi_gotoxy(int x, int y);
void ansi_initciowrap(long inmode);
void ansi_gettextinfo(struct text_info *info);
void ansi_setcursortype(int type);
int ansi_getch(void);
int ansi_getche(void);
int ansi_beep(void);
void ansi_textmode(int mode);
#ifdef __cplusplus
}
#endif
#endif
......@@ -11,8 +11,8 @@
#undef getch
#endif
#ifdef INCLUDE_OPENDOOR
#include "od_cio.h"
#ifdef USE_ANSI
#include "ansi_cio.h"
#endif
cioapi_t cio_api;
......@@ -50,25 +50,24 @@ void initciowrap(int mode)
fprintf(stderr,"X init failed\n");
#endif /* NO_X */
#endif /* !(_WIN32) */
#ifdef INCLUDE_OPENDOOR
OD_initciowrap(mode);
cio_api.mode=OPENDOOR_MODE;
cio_api.puttext=OD_puttext;
cio_api.gettext=OD_gettext;
cio_api.textattr=OD_textattr;
cio_api.kbhit=OD_kbhit;
cio_api.delay=OD_delay;
cio_api.wherey=OD_wherey;
cio_api.wherex=OD_wherex;
cio_api.putch=OD_putch;
cio_api.gotoxy=OD_gotoxy;
cio_api.gettextinfo=OD_gettextinfo;
cio_api.setcursortype=OD_setcursortype;
cio_api.getch=OD_getch;
cio_api.getche=OD_getche;
cio_api.beep=OD_beep;
cio_api.textmode=OD_textmode;
#ifdef USE_ANSI
ansi_initciowrap(mode);
cio_api.mode=ANSI_MODE;
cio_api.puttext=ansi_puttext;
cio_api.gettext=ansi_gettext;
cio_api.textattr=ansi_textattr;
cio_api.kbhit=ansi_kbhit;
cio_api.delay=ansi_delay;
cio_api.wherey=ansi_wherey;
cio_api.wherex=ansi_wherex;
cio_api.putch=ansi_putch;
cio_api.gotoxy=ansi_gotoxy;
cio_api.gettextinfo=ansi_gettextinfo;
cio_api.setcursortype=ansi_setcursortype;
cio_api.getch=ansi_getch;
cio_api.getche=ansi_getche;
cio_api.beep=ansi_beep;
cio_api.textmode=ansi_textmode;
#else
#ifndef _WIN32
curs_initciowrap(mode);
......@@ -89,7 +88,7 @@ void initciowrap(int mode)
cio_api.beep=beep;
cio_api.textmode=curs_textmode;
#endif /* !(_WIN32) */
#endif
#endif /* ANSI */
#ifndef _WIN32
#ifndef NO_X
}
......
......@@ -59,7 +59,7 @@ enum
{
X_MODE
,CURSES_MODE
,OPENDOOR_MODE
,ANSI_MODE
};
struct text_info {
......
#include <stdarg.h>
#include <stdio.h>
#include <OpenDoor.h>
#include "conio.h"
#include "od_cio.h"
unsigned int OD_nextch;
int OD_attr;
const int OD_tabs[10]={9,17,25,33,41,49,57,65,73,80};
int OD_puttext(int sx, int sy, int ex, int ey, unsigned char *fill)
{
struct text_info ti;
gettextinfo(&ti);
if( sx < 1
|| sx > ti.screenwidth
|| sy < 1
|| sy > ti.screenheight
|| ex < sx
|| ey < sy
|| ex < 1
|| ex > ti.screenwidth
|| ey < 1
|| ey > ti.screenheight)
return(0);
return(od_puttext(sx,sy,ex,ey,fill));
}
int OD_gettext(int sx, int sy, int ex, int ey, unsigned char *fill)
{
struct text_info ti;
gettextinfo(&ti);
if( sx < 1
|| sx > ti.screenwidth
|| sy < 1
|| sy > ti.screenheight
|| ex < sx
|| ey < sy
|| ex < 1
|| ex > ti.screenwidth
|| ey < 1
|| ey > ti.screenheight)
return(0);
return(od_gettext(sx,sy,ex,ey,fill));
}
void OD_textattr(unsigned char attr)
{
OD_attr=attr;
od_set_attrib(attr);
}
int parsekey(int ch)
{
switch(ch) {
case OD_KEY_F1:
OD_nextch=0x3b<<8;
break;
case OD_KEY_F2:
OD_nextch=0x3c<<8;
break;
case OD_KEY_F3:
OD_nextch=0x3d<<8;
break;
case OD_KEY_F4:
OD_nextch=0x3e<<8;
break;
case OD_KEY_F5:
OD_nextch=0x3f<<8;
break;
case OD_KEY_F6:
OD_nextch=0x40<<8;
break;
case OD_KEY_F7:
OD_nextch=0x41<<8;
break;
case OD_KEY_F8:
OD_nextch=0x42<<8;
break;
case OD_KEY_F9:
OD_nextch=0x43<<8;
break;
case OD_KEY_F10:
OD_nextch=0x44<<8;
break;
case OD_KEY_UP:
OD_nextch=0x48<<8;
break;
case OD_KEY_DOWN:
OD_nextch=0x50<<8;
break;
case OD_KEY_LEFT:
OD_nextch=0x4b<<8;
break;
case OD_KEY_RIGHT:
OD_nextch=0x4d<<8;
break;
case OD_KEY_INSERT:
OD_nextch=0x52<<8;
break;
case OD_KEY_DELETE:
OD_nextch=0x53<<8;
break;
case OD_KEY_HOME:
OD_nextch=0x47<<8;
break;
case OD_KEY_END:
OD_nextch=0x4f<<8;
break;
case OD_KEY_PGUP:
OD_nextch=0x49<<8;
break;
case OD_KEY_PGDN:
OD_nextch=0x51<<8;
break;
case OD_KEY_SHIFTTAB:
OD_nextch=0;
break;
}
}
int OD_kbhit(void)
{
int ch;
tODInputEvent ie;
if(OD_nextch)
return(1);
if(!od_get_input(&ie,5,GETIN_NORMAL))
return(0);
if(ie.EventType==EVENT_CHARACTER) {
OD_nextch=ie.chKeyPress;
return(1);
}
parsekey(ie.chKeyPress);
if(OD_nextch)
return(1);
return(0);
}
void OD_delay(long msec)
{
usleep(msec*1000);
}
int OD_wherey(void)
{
int row,col;
struct text_info ti;
od_get_cursor(&row,&col);
return(row);
}
int OD_wherex(void)
{
int row,col;
struct text_info ti;
od_get_cursor(&row,&col);
return(col);
}
/* Put the character _c on the screen at the current cursor position.
* The special characters return, linefeed, bell, and backspace are handled
* properly, as is line wrap and scrolling. The cursor position is updated.
*/
int OD_putch(unsigned char ch)
{
struct text_info ti;
int ret;
int i;
ret=ch;
switch(ch) {
case '\r':
gotoxy(1,wherey());
break;
case '\n':
gettextinfo(&ti);
if(wherey()==ti.winbottom-ti.wintop+1) {
wscroll();
}
else {
gotoxy(wherex(),wherey()+1);
}
break;
case 0x07:
cio_api.beep();
break;
case 0x08:
gotoxy(wherex()-1,wherey());
putch(' ');
gotoxy(wherex()-1,wherey());
break;
case '\t':
for(i=0;i<10;i++) {
if(OD_tabs[i]>wherex()) {
while(wherex()<OD_tabs[i]) {
putch(' ');
}
break;
}
}
if(i==10) {
putch('\r');
putch('\n');
}
break;
default:
gettextinfo(&ti);
if(OD_wherey()==ti.screenheight
&& OD_wherex()==ti.screenwidth) {
if(_wscroll) {
od_putch(ch);
gotoxy(ti.winleft,ti.cury);
}
}
else {
if(wherey()==ti.winbottom-ti.wintop+1
&& wherex()==ti.winright-ti.winleft+1) {
od_putch(ch);
wscroll();
gotoxy(ti.winleft,ti.cury);
}
else {
if(wherex()==ti.winright-ti.winleft+1) {
od_putch(ch);
gotoxy(ti.winleft,ti.cury+1);
}
else {
od_putch(ch);
gotoxy(ti.curx+1,ti.cury);
}
}
}
break;
}
return(ch);
}
void OD_gotoxy(int x, int y)
{
struct text_info ti;
char ansi[16];
gettextinfo(&ti);
if(x>ti.screenwidth
|| x < 1
|| y>ti.screenheight
|| y<1)
return;
sprintf(ansi,"%c[%d;%dH",27,y,x);
od_set_cursor(y,x);
}
void OD_gettextinfo(struct text_info *info)
{
info->currmode=3;
info->screenheight=od_control.user_screen_length?od_control.user_screen_length:23;
info->screenwidth=od_control.user_screenwidth?od_control.user_screenwidth:80;
info->curx=wherex();
info->cury=wherey();
info->attribute=OD_attr;
}
void OD_setcursortype(int type)
{
}
int OD_getch(void)
{
int ch;
tODInputEvent ie;
while(1) {
if(OD_nextch) {
ch=OD_nextch&0xff;
OD_nextch>>=8;
return(ch);
}
od_get_input(&ie,OD_NO_TIMEOUT,GETIN_NORMAL);
if(ie.EventType==EVENT_CHARACTER) {
return(ie.chKeyPress);
}
parsekey(ie.chKeyPress);
}
}
int OD_getche(void)
{
int ch;
if(OD_nextch)
return(OD_getch());
ch=OD_getch();
if(ch)
putch(ch);
return(ch);
}
int OD_beep(void)
{
od_putch(7);
return(0);
}
void OD_textmode(int mode)
{
}
ODAPIDEF void ODCALL OD_pers(BYTE btOperation)
{
switch(btOperation) {
case PEROP_UPDATE1:
case PEROP_DISPLAY1:
ODScrnSetAttribute(0x70);
ODScrnSetCursorPos(1, 25);
ODScrnDisplayString("Design me a better ONE-LINE Status Bar! (Include Custom Keys Descriptions etc) ");
}
}
void OD_initciowrap(long mode)
{
od_control.od_mps=INCLUDE_MPS;
od_add_personality("CONIO",1,24,OD_pers);
od_set_personality("CONIO");
od_init();
}
/* $Id$ */
#ifdef __unix__
#include "conio.h"
#ifdef __cplusplus
extern "C" {
#endif
int OD_puttext(int sx, int sy, int ex, int ey, unsigned char *fill);
int OD_gettext(int sx, int sy, int ex, int ey, unsigned char *fill);
void OD_textattr(unsigned char attr);
int OD_kbhit(void);
void OD_delay(long msec);
int OD_wherey(void);
int OD_wherex(void);
int OD_putch(unsigned char ch);
void OD_gotoxy(int x, int y);
void OD_gettextinfo(struct text_info *info);
void OD_setcursortype(int type);
int OD_getch(void);
int OD_getche(void);
int OD_beep(void);
void OD_textmode(int mode);
void OD_initciowrap(long inmode);
#ifdef __cplusplus
}
#endif
#endif
......@@ -88,12 +88,12 @@ void x_delay(long msec)
int x_wherey(void)
{
return(CursRow0)+1;
return(CursRow0+1);
}
int x_wherex(void)
{
return(CursCol0)+1;
return(CursCol0+1);
}
/* Put the character _c on the screen at the current cursor position.
......@@ -110,7 +110,8 @@ int x_putch(unsigned char ch)
switch(ch) {
case '\r':
CursCol0=0;
gettextinfo(&ti);
CursCol0=ti.winleft-1;
break;
case '\n':
gettextinfo(&ti);
......@@ -120,10 +121,9 @@ int x_putch(unsigned char ch)
CursRow0++;
break;
case '\b':
sch=0x0700;
if(CursCol0>0)
CursCol0--;
vmem[CursCol0+CursRow0*DpyCols]=sch;
vmem[CursCol0+CursRow0*DpyCols]=x_curr_attr|' ';
break;
case 7: /* Bell */
tty_beep();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment