|
|
1.1 root 1: /* ansiterm.cpp */
2:
3: /* Synchronet ANSI terminal functions */
4:
5: /* $Id: ansiterm.cpp,v 1.1.1.1 2000/10/10 11:24:09 rswindell Exp $ */
6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
11: * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html *
12: * *
13: * This program is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU General Public License for more details: gpl.txt or *
18: * http://www.fsf.org/copyleft/gpl.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #include "sbbs.h"
39:
40: #define TIMEOUT_ANSI_GETXY 5 // Seconds
41:
42: /****************************************************************************/
43: /* Returns the ANSI code to obtain the value of atr. Mixed attributes */
44: /* high intensity colors, or background/forground cobinations don't work. */
45: /* A call to attr is more appropriate, being it is intelligent */
46: /****************************************************************************/
47: char *sbbs_t::ansi(int atr)
48: {
49:
50: switch(atr) {
51: case BLINK:
52: return("\x1b[5m");
53: case HIGH:
54: return("\x1b[1m");
55: case BLACK:
56: return("\x1b[30m");
57: case RED:
58: return("\x1b[31m");
59: case GREEN:
60: return("\x1b[32m");
61: case BROWN:
62: return("\x1b[33m");
63: case BLUE:
64: return("\x1b[34m");
65: case MAGENTA:
66: return("\x1b[35m");
67: case CYAN:
68: return("\x1b[36m");
69: case LIGHTGRAY:
70: return("\x1b[37m");
71: case (RED<<4):
72: return("\x1b[41m");
73: case (GREEN<<4):
74: return("\x1b[42m");
75: case (BROWN<<4):
76: return("\x1b[43m");
77: case (BLUE<<4):
78: return("\x1b[44m");
79: case (MAGENTA<<4):
80: return("\x1b[45m");
81: case (CYAN<<4):
82: return("\x1b[46m");
83: case (LIGHTGRAY<<4):
84: return("\x1b[47m"); }
85:
86: return("-Invalid use of ansi()-");
87: }
88:
89: void sbbs_t::ansi_getlines()
90: {
91: if(useron.misc&ANSI && !useron.rows /* Auto-detect rows */
92: && online==ON_REMOTE) { /* Remote */
93: SYNC;
94: putcom("\x1b[s\x1b[99B\x1b[6n\x1b[u");
95: while(online && !rioctl(RXBC) /* && !lkbrd(1) */)
96: checkline();
97: inkey(0); }
98: }
99:
100:
101: void sbbs_t::ansi_getxy(int* x, int* y)
102: {
103: int rsp=0, ch;
104:
105: *x=0;
106: *y=0;
107:
108: rputs("\x1b[6n"); /* Request cusor position */
109:
110: time_t start=time(NULL);
111: sys_status&=~SS_ABORT;
112: while(online && !(sys_status&SS_ABORT)) {
113: if((ch=incom())!=NOINP) {
114: if(ch==ESC && rsp==0) {
115: rsp++;
116: start=time(NULL);
117: }
118: else if(ch=='[' && rsp==1) {
119: rsp++;
120: start=time(NULL);
121: }
122: else if(isdigit(ch) && rsp==2) {
123: (*y)*=10;
124: (*y)+=(ch&0xf);
125: start=time(NULL);
126: }
127: else if(ch==';' && rsp>=2) {
128: rsp++;
129: start=time(NULL);
130: }
131: else if(isdigit(ch) && rsp==3) {
132: (*x)*=10;
133: (*x)+=(ch&0xf);
134: start=time(NULL);
135: }
136: else if(ch=='R' && rsp)
137: break;
138: else
139: ungetkey(ch);
140: }
141: if(time(NULL)-start>TIMEOUT_ANSI_GETXY) {
142: lprintf("!Node %d: TIMEOUT in ansi_getxy", cfg.node_num);
143: break;
144: }
145: }
146: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.