Annotation of sbbs/sbbs3/ansiterm.cpp, revision 1.1.1.2

1.1       root        1: /* ansiterm.cpp */
                      2: 
                      3: /* Synchronet ANSI terminal functions */
                      4: 
1.1.1.2 ! root        5: /* $Id: ansiterm.cpp,v 1.10 2003/10/24 21:46:54 rswindell Exp $ */
1.1       root        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:  *                                                                                                                                                     *
1.1.1.2 ! root       11:  * Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html         *
1.1       root       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) {
1.1.1.2 ! root       51: 
        !            52:                /* Special case */
        !            53:                case ANSI_NORMAL:
        !            54:                        return("\x1b[0m");
1.1       root       55:                case BLINK:
                     56:                        return("\x1b[5m");
1.1.1.2 ! root       57: 
        !            58:                /* Foreground */
1.1       root       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");
1.1.1.2 ! root       77: 
        !            78:                /* Background */
        !            79:                case BG_BLACK:
        !            80:                        return("\x1b[40m");
        !            81:                case BG_RED:
1.1       root       82:                        return("\x1b[41m");
1.1.1.2 ! root       83:                case BG_GREEN:
1.1       root       84:                        return("\x1b[42m");
1.1.1.2 ! root       85:                case BG_BROWN:
1.1       root       86:                        return("\x1b[43m");
1.1.1.2 ! root       87:                case BG_BLUE:
1.1       root       88:                        return("\x1b[44m");
1.1.1.2 ! root       89:                case BG_MAGENTA:
1.1       root       90:                        return("\x1b[45m");
1.1.1.2 ! root       91:                case BG_CYAN:
1.1       root       92:                        return("\x1b[46m");
1.1.1.2 ! root       93:                case BG_LIGHTGRAY:
        !            94:                        return("\x1b[47m"); 
        !            95:        }
1.1       root       96: 
                     97:        return("-Invalid use of ansi()-");
                     98: }
                     99: 
                    100: void sbbs_t::ansi_getlines()
                    101: {
                    102:        if(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");
1.1.1.2 ! root      106:                inkey(K_NONE,TIMEOUT_ANSI_GETXY*1000); 
        !           107:        }
1.1       root      108: }
                    109: 
1.1.1.2 ! root      110: bool sbbs_t::ansi_getxy(int* x, int* y)
1.1       root      111: {
                    112:        int     rsp=0, ch;
                    113: 
                    114:     *x=0;
                    115:     *y=0;
                    116: 
1.1.1.2 ! root      117:        putcom("\x1b[6n");      /* Request cusor position */
1.1       root      118: 
                    119:     time_t start=time(NULL);
                    120:     sys_status&=~SS_ABORT;
                    121:     while(online && !(sys_status&SS_ABORT)) {
1.1.1.2 ! root      122:                if((ch=incom(1000))!=NOINP) {
1.1       root      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) {
1.1.1.2 ! root      132:                                if(y!=NULL) {
        !           133:                                (*y)*=10;
        !           134:                                        (*y)+=(ch&0xf);
        !           135:                                }
1.1       root      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) {
1.1.1.2 ! root      143:                                if(x!=NULL) {
        !           144:                        (*x)*=10;
        !           145:                                        (*x)+=(ch&0xf);
        !           146:                                }
1.1       root      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) {
1.1.1.2 ! root      155:                lprintf(LOG_NOTICE,"Node %d !TIMEOUT in ansi_getxy", cfg.node_num);
        !           156:             return(false);
1.1       root      157:         }
                    158:     }
1.1.1.2 ! root      159: 
        !           160:        return(true);
1.1       root      161: }

unix.superglobalmegacorp.com

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