⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 console.cpp

📁 linux文本方式下的外挂中文环境,很好用,有源码.功能很全.我都用它
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// vi:ts=4:shiftwidth=4:expandtab/***************************************************************************                          console.cpp  -  description                             -------------------    begin                : Sun Mar 18 2001    copyright            : (C) 2001 by ejoy    email                : ejoy@users.sourceforge.net ***************************************************************************//*************************************************************************** *                                                                         * *   This program 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.                                   * *                                                                         * ***************************************************************************/#include <cassert>#include "debug.h"#include <unistd.h>#include <string.h>#include <algorithm>#include "console.h"int Console::mColorTable[16] ={ 0, 4, 2, 6, 1, 5, 3, 7, 8, 12, 10, 14, 9, 13, 11, 15 };Console::Console(int x1, int y1, int x2, int y2):Window(x1, y1, x2, y2, WS_DEF), // set window console pointermHistMode(false),mDefColor(0x07),mUlColor(0x0f),mHalfColor(0x08),mEscState(NORMAL){    mConMaxCols = mMaxCols;    mConMaxRows = mMaxRows;    mConEndCol = mEndCol;    mConEndRow = mEndRow;    int size = mMaxCols * mMaxRows;    mpSavTextBuf = new char[size];    mpSavAttrBuf = new char[size];    mpSavFlagBuf = new char[size];    Reset();    Show();    CursorShow();    size = mMaxCols * HISTORY_LINES;    mpHistText = new char[size];    mpHistAttr = new char[size];    mpHistFlag = new char[size];    memset(mpHistText, ' ', size);    memset(mpHistAttr, mAttr, size);    memset(mpHistFlag, txtASCII | txtUpdated, size);    mHistCurRow = 0;    mMouseMask = 0x77;  // 0x80 when mono    mMouseIdx = -1;    mSelStart = -1;  // cleared by clear_selection    mpSelBuf = NULL;}Console::~Console() {    delete[] mpHistText;    delete[] mpHistAttr;    delete[] mpHistFlag;    delete[] mpSavTextBuf;    delete[] mpSavAttrBuf;    delete[] mpSavFlagBuf;    delete[] mpSelBuf;}/** handle ansi esc command */void Console::DoEscape(char c) {    if (mEscIntro == '\0') {        //ESC seen        switch (c) {            case 'D':                Lf();                break;            case 'E':                Cr();                Lf();                break;            case 'H':  // Set Tab <ESC>H                mTabStop[Row() >> 5] |= (1 << (Row() & 31));                break;            case 'M':  // Reverse Index,Scroll Up            case 'T':  // FreeBSD, cons25                if (Row() == mScrollStart)                    ScrollScr(DOWN);                else if (Row())                    ConGoto(Col(), Row() - 1);                mNeedWrap = false;                break;            case 'c':                Reset();                // Redraw(); // why need? called by write                break;            case '>':                assert(!">");                break;            case '=':                assert(!"=");                break;            case '7':  // Save Cursor & Attrs <ESC>7                SaveCursor();                break;            case '8':  // Restore Cursor & Attrs  <ESC>8                UnSaveCursor();                break;            default:                break;        }    }    else if (mEscIntro == '[') {        //ESC [ seen        int num;                                       //param count        num = mpEscParam - mEscParam + 1;        switch (c) {            case 'A':  // Restore Cursor & Attrs  <ESC>8                if (!mEscParam[0])                    mEscParam[0]++;                ConGoto(Col(), Row() - mEscParam[0]);                break;            case 'B':  // Cursor Down <ESC>[{COUNT}B            case 'e':                if (!mEscParam[0])                    mEscParam[0]++;                ConGoto(Col(), Row() + mEscParam[0]);                break;            case 'C':  // Cursor Forward <ESC>[{COUNT}C            case 'a':                if (!mEscParam[0])                    mEscParam[0]++;                ConGoto(Col() + mEscParam[0], Row());                break;            case 'D':  // Cursor Backward <ESC>[{COUNT}D                if (!mEscParam[0])                    mEscParam[0]++;                ConGoto(Col() - mEscParam[0], Row());                break;            case 'E':                if (!mEscParam[0])                    mEscParam[0]++;                ConGoto(0, Row() + mEscParam[0]);                break;            case 'F':                if (!mEscParam[0])                    mEscParam[0]++;                ConGoto(0, Row() - mEscParam[0]);                break;            case 'G':  // Cursor Horizontal Absolute            case '`':                if (mEscParam[0])                    mEscParam[0]--;                ConGoto(mEscParam[0], Row());                break;            case 'H':  // ESC [m;nH moves cursor to (m,n)            case 'f':                if (mEscParam[0])                    mEscParam[0]--;                if (mEscParam[1])                    mEscParam[1]--;                AbsGoto(mEscParam[1], mEscParam[0]);                break;            case 'J':  // ESC [sJ clears in display                switch (mEscParam[0]) {                    case 0:  // clear from cursor to end of screen                        Clear(Col(), Row(), mConEndCol, Row(), mAttr);                        if (Row() < mConEndRow)                            Clear(0, Row() + 1, mConEndCol, mConEndRow, mAttr);                        break;                    case 1:  // clear from start to cursor                        Clear(0, Row(), Col(), Row(), mAttr);                        if (Row() > 0)                            Clear(0, 0, mConEndCol, Row() - 1, mAttr);                        break;                    case 2:  // clear whole screen                        Clear(0, 0, mConEndCol, mConEndRow, mAttr);                        break;                    default:  // do nothing                        break;                }                mNeedWrap = false;                break;            case 'K':  // ESC [sK clears lines from cursor                switch (mEscParam[0]) {                    case 0:  // clear from cursor to end of line                        Clear(Col(), Row(), mConEndCol, Row(), mAttr);                        break;                    case 1:  // clear from beinning of line to cursor                        Clear(0, Row(), Col(), Row(), mAttr);                        break;                    case 2:  // clear whole line                        Clear(0, Row(), mConEndCol, Row(), mAttr);                        break;                    default:  // do nothing                        break;                }                mNeedWrap = false;                break;            case 'L':  // ESC [nL inserts n lines at cursor                InsertLine(mEscParam[0]);                break;            case 'M':  // ESC [nM deletes n lines at cursor                DeleteLine(mEscParam[0]);                break;            case 'P':  // ESC [nP deletes n chars at cursor                DeleteChar(mEscParam[0]);                break;            case 'X':                {                    int n = mEscParam[0];                    if (!n)                        n++;                    Clear(Col(), Row(),                          Col() + n > mConEndCol ? mConEndCol : Col() + n,                          Row(),                          mAttr);                    mNeedWrap = false;                }                break;            case '@':  // ESC [n@ insert n chars at cursor                InsertBlank(mEscParam[0]);                break;            case ']':                assert(!"]");                break;            case 'c':                if (mEscQuestion) {                    if (mEscParam[0])                        SetCursorType(mEscParam[0] | (mEscParam[1]<<8) | (mEscParam[2]<<16));                    else                        SetCursorType(CUR_DEFAULT);                }                break;            case 'd':                if (mEscParam[0])                    mEscParam[0]--;                AbsGoto(Col(), mEscParam[0]);                break;            case 'g':  // Clear Tab  <ESC>[{3}g                if (num == 0)                    mTabStop[Col() >> 5] &= ~(1 << (Col() & 31));                else if (mEscParam[0] == 3)                    fill_n(mTabStop, 5, 0);                break;            case 'h':                SetMode(true);                break;            case 'l':                SetMode(false);                break;            case 'm':  // ESC [nm set attribute                for (int i = 0; i < num; i++) {                    int value = mEscParam[i];                    switch (value) {                        case 0:                            DefaultAttr();                            break;                        case 1:                            mIntensity = 2;                            break;                        case 2:                            mIntensity = 0;                            break;                        case 4:  // underline                            mUnderline = true;                            break;                        case 5:  // blinking                            mBlink = true;                            break;                        case 7:  // reverse                            mReverse = true;                            break;                        case 8:  // hidden                            break;                        case 10:                            /* ANSI X3.64-1979 (SCO-ish?)                             * Select primary font, don't display                             * control chars if defined, don't set                             * bit 8 on output.                             */                            mCharSet = PRIMARY;                            break;                        case 11:                            /* ANSI X3.64-1979 (SCO-ish?)                             * Select first alternate font, lets                             * chars < 32 be displayed as ROM chars.                             */                            mCharSet = ALT1;                            break;                        case 12:                            /* ANSI X3.64-1979 (SCO-ish?)                             * Select second alternate font, toggle                             * high bit before displaying as ROM char.                             */                            mCharSet = ALT2;                            break;                        case 21:                        case 22:                            mIntensity = 1;                        case 24:                            mUnderline = false;                            break;                        case 25:                            mBlink = false;                            break;                        case 27:                            mReverse = false;                            break;                        case 38:                            /* ANSI X3.64-1979 (SCO-ish?)                             * Enables underscore, white foreground                             * with white underscore (Linux - use                             * default foreground).                             */                            mColor = BuildColor(FgColor(mDefColor),BgColor(mColor));                            mUnderline = true;                            break;                        case 39:                            /* ANSI X3.64-1979 (SCO-ish?)                             * Disable underline option.                             * Reset colour to default? It did this                             * before...                             */                            mColor = BuildColor(FgColor(mDefColor),BgColor(mColor));                            mUnderline = false;                            break;                        case 49:                            mColor = BuildColor(FgColor(mColor),BgColor(mDefColor));                            break;                        default:                            //color                            if (value >= 30 && value <= 37)                                mColor = BuildColor(mColorTable[(value - 30)],                                    BgColor(mColor));                            else if (value >= 40 && value <= 47)                                mColor = BuildColor(FgColor(mColor),                                    mColorTable[(value - 40)]);                            else {                                //what to do?                            }                            break;                    }//switch                }//for                UpdateAttr();                break;            case 'n':  // not implemented                assert(!"n");                break;            case 'p':  // Define Key                assert(!"Define Key not implemented yet!");                break;            case 'q':                assert(!"esc q");                break;            case 'r':  // set scrolling range                if (!mEscParam[0])                    mEscParam[0]++;                if (!mEscParam[1])                    mEscParam[1] = mConMaxRows;                /* Minimum allowed region is 2 lines */                if (mEscParam[0] < mEscParam[1] &&                    mEscParam[1] <= mConMaxRows) {                    mScrollStart = mEscParam[0] - 1;                    mScrollEnd = mEscParam[1];                    AbsGoto(0, 0);                }                break;            case 's':  // Save Cursor <ESC>[s                SaveCursor();                break;            case 'u':  // Unsave Cursor <ESC>[u                UnSaveCursor();        } //switch    }    else if (mEscIntro == ']') {        //unfinished    }    mEscState = NORMAL;}void Console::ParseEscape(char c) {    switch (mEscState) {        case ESC:            mEscIntro = '\0';          //ESC seen            mEscQuestion = false;            mpEscParam = mEscParam;            for (int i = 0; i < MAX_ESC_PARAMS; i++)                mEscParam[i] = 0;            switch (c) {                case '#':  // DEC obsolete hacks                    //anyone want to implement them?                    break;                case '[':              //control sequence introducer                    mEscIntro = c;                    mEscState = SQUARE;                    break;                case ']':                    mEscIntro = c;                    mEscState = NONSTD;                    break;                case '%':  // unfinished                    break;                case '(':              //Char Set G0                case ')':              //Char Set G1                    //unfinished                    //charset change not implemented                    break;                default:                    DoEscape(c);            }                          //swicth            break;        case SQUARE:                   //ESC [ seen            if (c == '?')                mEscQuestion = true;            else if (c >= '0' && c <= '9') {                if (mpEscParam < mEscParam + MAX_ESC_PARAMS)                    *mpEscParam = *mpEscParam * 10 + (c - '0');            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -