Annotation of sbbs/src/sbbs3/ansiterm.cpp, revision 1.1.1.1

1.1       root        1: /* ansiterm.cpp */
                      2: 
                      3: /* Synchronet ANSI terminal functions */
                      4: 
                      5: /* $Id: ansiterm.cpp,v 1.11 2006/08/23 01:33:29 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 2006 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: 
                     52:                /* Special case */
                     53:                case ANSI_NORMAL:
                     54:                        return("\x1b[0m");
                     55:                case BLINK:
                     56:                        return("\x1b[5m");
                     57: 
                     58:                /* Foreground */
                     59:                case HIGH:
                     60:                        return("\x1b[1m");
                     61:                case BLACK:
                     62:                        return("\x1b[30m");
                     63:                case RED:
                     64:                        return("\x1b[31m");
                     65:                case GREEN:
                     66:                        return("\x1b[32m");
                     67:                case BROWN:
                     68:                        return("\x1b[33m");
                     69:                case BLUE:
                     70:                        return("\x1b[34m");
                     71:                case MAGENTA:
                     72:                        return("\x1b[35m");
                     73:                case CYAN:
                     74:                        return("\x1b[36m");
                     75:                case LIGHTGRAY:
                     76:                        return("\x1b[37m");
                     77: 
                     78:                /* Background */
                     79:                case BG_BLACK:
                     80:                        return("\x1b[40m");
                     81:                case BG_RED:
                     82:                        return("\x1b[41m");
                     83:                case BG_GREEN:
                     84:                        return("\x1b[42m");
                     85:                case BG_BROWN:
                     86:                        return("\x1b[43m");
                     87:                case BG_BLUE:
                     88:                        return("\x1b[44m");
                     89:                case BG_MAGENTA:
                     90:                        return("\x1b[45m");
                     91:                case BG_CYAN:
                     92:                        return("\x1b[46m");
                     93:                case BG_LIGHTGRAY:
                     94:                        return("\x1b[47m"); 
                     95:        }
                     96: 
                     97:        return("-Invalid use of ansi()-");
                     98: }
                     99: 
                    100: void sbbs_t::ansi_getlines()
                    101: {
                    102:        if(sys_status&SS_USERON && useron.misc&ANSI && !useron.rows /* Auto-detect rows */
                    103:                && online==ON_REMOTE) {                                                                 /* Remote */
                    104:                SYNC;
                    105:                putcom("\x1b[s\x1b[99B\x1b[6n\x1b[u");
                    106:                inkey(K_NONE,TIMEOUT_ANSI_GETXY*1000); 
                    107:        }
                    108: }
                    109: 
                    110: bool sbbs_t::ansi_getxy(int* x, int* y)
                    111: {
                    112:        int     rsp=0, ch;
                    113: 
                    114:     *x=0;
                    115:     *y=0;
                    116: 
                    117:        putcom("\x1b[6n");      /* Request cusor position */
                    118: 
                    119:     time_t start=time(NULL);
                    120:     sys_status&=~SS_ABORT;
                    121:     while(online && !(sys_status&SS_ABORT)) {
                    122:                if((ch=incom(1000))!=NOINP) {
                    123:                        if(ch==ESC && rsp==0) {
                    124:                rsp++;
                    125:                                start=time(NULL);
                    126:                        }
                    127:             else if(ch=='[' && rsp==1) {
                    128:                rsp++;
                    129:                                start=time(NULL);
                    130:                        }
                    131:             else if(isdigit(ch) && rsp==2) {
                    132:                                if(y!=NULL) {
                    133:                                (*y)*=10;
                    134:                                        (*y)+=(ch&0xf);
                    135:                                }
                    136:                                start=time(NULL);
                    137:             }
                    138:             else if(ch==';' && rsp>=2) {
                    139:                rsp++;
                    140:                                start=time(NULL);
                    141:                        }
                    142:             else if(isdigit(ch) && rsp==3) {
                    143:                                if(x!=NULL) {
                    144:                        (*x)*=10;
                    145:                                        (*x)+=(ch&0xf);
                    146:                                }
                    147:                                start=time(NULL);
                    148:             }
                    149:             else if(ch=='R' && rsp)
                    150:                break;
                    151:                        else
                    152:                                ungetkey(ch);
                    153:         }
                    154:        if(time(NULL)-start>TIMEOUT_ANSI_GETXY) {
                    155:                lprintf(LOG_NOTICE,"Node %d !TIMEOUT in ansi_getxy", cfg.node_num);
                    156:             return(false);
                    157:         }
                    158:     }
                    159: 
                    160:        return(true);
                    161: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.