📄 console.cpp
字号:
else if (c == ';') { if (++mpEscParam < mEscParam + MAX_ESC_PARAMS) *mpEscParam = 0; } else { DoEscape(c); } break; case NONSTD: DoEscape(c); break; default: break; } //switch}//send c to buffervoid Console::SendChar(char c) { if (mHistMode) { mHistMode = false; //restore saved Buffer memcpy(mpText, mpSavTextBuf, mConMaxCols * mConMaxRows); memcpy(mpAttr, mpSavAttrBuf, mConMaxCols * mConMaxRows); ResetFlagAll(); // Redraw(); // why need? called by write } if (mNeedWrap) { Cr(); Lf(); } assert(mInsertMode == false); if (mCharSet == PRIMARY) { // txtDblCode could be code1, code2, even ASCII // It will be identified in UpdateScreen() if (gpDecoder->IsCode1(c) || gpDecoder->IsCode2(c)) { PutChar(mAttr,txtDblCode | txtPrimary | txtUpdated,c); } else { PutChar(mAttr,txtASCII | txtPrimary | txtUpdated,c); } } else { // always table line char PutChar(mAttr,txtASCII | txtUpdated,c); } //update cursor if (Col() == mConEndCol) mNeedWrap = mAutoWrap; else Goto(Col() + 1, Row());}//#include <sys/time.h>//#include <sys/types.h>//#include <unistd.h> //for debug/** Write num chars in pBuf to console */void Console::Write(const char *pBuf, int num) { SelClear(); // hide mouse bool isCursorOn = CursorOnOff(); // turn off cursor for rapid display if (isCursorOn) CursorHide(); char c; for (; num; pBuf++, num--) { c = *pBuf; //debug<<c<<flush; if (mEscState != NORMAL) ParseEscape(c); else if (c < ' ') DoControl(c); else { SendChar(c);//for debug// Redraw();// fd_set set;// struct timeval tv;// FD_ZERO(&set);// tv.tv_sec = 0;// tv.tv_usec = 10000; // 0.1 sec// select(FD_SETSIZE, &set, NULL, NULL, &tv); } } Redraw(); if (isCursorOn) CursorShow();}/** do ANSI control function */void Console::DoControl(char c) { switch (c) { case 0: return; case 7: Beep(); return; case 8: //backspace if (Col()) { Goto(Col()-1, Row()); mNeedWrap = false; } return; case 9: //tab while (Col() < mConEndCol) { Goto(Col() + 1, Row()); if (mTabStop[Col() >> 5] & (1 << (Col() & 31))) break; } return; case 10: //'\n' case 11: case 12: Lf(); return; case 13: //'\r' Cr(); return; case 14: //charset = 1; //translate = set_translate(G1_charset,currcons); //disp_ctrl = 1; return; case 15: //charset = 0; //translate = set_translate(G0_charset,currcons); //disp_ctrl = 0; return; case 24://graph arrows case 26: assert(mEscState == NORMAL); break; case 27: //ESC mEscState = ESC; return; case 127: //del(currcons); return; case 128 + 27: mEscState = SQUARE; assert(!"128+27"); return; default: break;//assert(!"unknown control char reached!"); }//switch //send out unknown control char SendChar(c);}//Copy lines from r1 to r2void Console::CopyLines(int r1, int r2, int count) { assert(r1 >= 0 && r1 < mMaxRows && r2 >= 0 && r2 < mMaxRows); if (count == 0 || r1 == r2) return; int si, di; si = Index(0, r1); di = Index(0, r2); int n; if (r2 + count < mConMaxRows) n = count * mConMaxCols; else n = (mConMaxRows - r2) * mConMaxCols; memmove(&mpText[di], &mpText[si], n); memmove(&mpAttr[di], &mpAttr[si], n); memmove(&mpFlag[di], &mpFlag[si], n); for (int i = 0; i < n; i++) mpFlag[di + i] |= txtUpdated;}//insert n blank line at cursorvoid Console::InsertLine(int n) { assert(Row() + 1 <= mScrollEnd && Row() >= mScrollStart); if (n < 1) n = 1; if (n > mScrollEnd - Row()) n = mScrollEnd - Row(); CopyLines(Row(), Row() + n, mScrollEnd - Row() - n); Clear(0, Row(), mConEndCol, Row() + n - 1, mAttr); mNeedWrap = false;}//delete n lines at cursor//append blank linesvoid Console::DeleteLine(int n) { assert(Row() + 1 <= mScrollEnd && Row() >= mScrollStart); if (n < 1) n = 1; if (n > mScrollEnd - Row()) n = mScrollEnd - Row(); CopyLines(Row() + n, Row(), mScrollEnd - Row() - n); Clear(0, mScrollEnd - n, mConEndCol, mScrollEnd - 1, mAttr); mNeedWrap = false;}//insert n blank char at current positionvoid Console::InsertBlank(int n) { if (n < 1) n = 1; if (Col() + n > mConEndCol) n = mConEndCol - Col(); int count = mConEndCol - (Col() - 1) - n; for (int s = mConEndCol - n, d = mConEndCol; count--;) CopyChar(s--, Row(), d--, Row()); Clear(Col(), Row(), Col() + n - 1, Row(), mAttr); mNeedWrap = false;}//delete n chars at current position//append blank char at the end of linevoid Console::DeleteChar(int n) { if (n < 1) n = 1; if (Col() + n > mConEndCol) n = mConEndCol - Col(); int count = mConEndCol - (Col() - 1) - n; for (int d = Col(), s = d + n; count--;) { assert(s <= mEndCol); CopyChar(s++, Row(), d++, Row()); } //append blank Clear(mConEndCol - n + 1, Row(), mConEndCol, Row(), mAttr); mNeedWrap = false;}//copy a char from (r1,c1) to (r2,c2)void Console::CopyChar(int c1, int r1, int c2, int r2) { assert(r1 >= 0 && r1 <= mEndRow && r2 >= 0 && r2 <= mEndRow); int si, di; si = Index(c1, r1); di = Index(c2, r2); mpText[di] = mpText[si]; mpAttr[di] = mpAttr[si]; mpFlag[di] = mpFlag[si] | txtUpdated;}//scroll screen up or down one line//in view: [mScrollStart,mScrollEnd)void Console::ScrollScr(DIR dir) { assert(mScrollEnd > mScrollStart); int count = (mScrollEnd - mScrollStart - 1) * mConMaxCols; int si, di, blank; if (dir == UP) { si = (mScrollStart + 1) * mConMaxCols; di = si - mConMaxCols; blank = mScrollEnd - 1; PushHistoryLine(); } else { si = mScrollStart * mConMaxCols; di = si + mConMaxCols; blank = mScrollStart; } memmove(&mpText[di], &mpText[si], count); memmove(&mpAttr[di], &mpAttr[si], count); memmove(&mpFlag[di], &mpFlag[si], count); for (int i = 0; i < count; i++) mpFlag[di + i] |= txtUpdated; Clear(0, blank, mConEndCol, blank, mAttr);}void Console::DefaultAttr() { mIntensity = 1; mBlink = false; mUnderline = false; mReverse = false; mColor = mDefColor;}void Console::Reset() { DefaultAttr(); UpdateAttr(); mTabStop[0] = 0x01010100; mTabStop[1] = mTabStop[2] = mTabStop[3] = mTabStop[4] = 0x01010101; mEscQuestion = false; mNeedWrap = false; mCharSet = PRIMARY; mInsertMode = false; mDecom = false; mAutoWrap = true; mScrollStart = 0; mScrollEnd = mConMaxRows; int size = mConMaxCols * mConMaxRows; memset(mpText, ' ', size); memset(mpAttr, mAttr, size); memset(mpFlag, txtASCII | txtUpdated, size); ConGoto(0, 0);}void Console::SaveCursor() { mOldCol = Col(); mOldRow = Row(); mOldColor = mColor; mOldBlink = mBlink; mOldUnderline = mUnderline; mOldIntensity = mIntensity; mOldReverse = mReverse; mOldCharSet = mCharSet;}void Console::UnSaveCursor() { ConGoto(mOldCol, mOldRow); mColor = mOldColor; mBlink = mOldBlink; mUnderline = mOldUnderline; mBold = mOldBold; mReverse = mOldReverse; mCharSet = mOldCharSet; UpdateAttr(); mNeedWrap = false;}void Console::SetMode(bool f) { if (mEscQuestion) switch (mEscParam[0]) { /* DEC private modes set/reset */ case 1: /* Cursor keys send ^[Ox/^[[x */ assert(!"set_dec_cursor_keys(tty, on_off)"); break; case 3: /* 80/132 mode switch unimplemented */ break; case 4: /* soft scroll/Jump scroll toggle, unimplemented yet */ break; case 5: /* Inverted screen on/off */ //not implemented break; case 6: mDecom = f; AbsGoto(0, 0); case 7: /* Autowrap on/off */ mAutoWrap = f; case 8: /* Autorepeat on/off not implemented yet */ break; case 25: /* Cursor on/off */ //deccm = on_off; if (f) CursorShow(); else CursorHide(); break; } else switch (mEscParam[0]) { /* ANSI modes set/reset */ case 4: /* Insert Mode on/off */ mInsertMode = f; //decim = f; break; case 20: /* Lf, Enter == CrLf/Lf */ // set_lf_mode(tty, on_off); assert(!"Lf, Enter == CrLf/Lf"); break; }}void Console::ConGoto(int c, int r) { int col, row; if (c < 0) col = 0; else if (c > mConEndCol) col = mConEndCol; else col = c; int min_y, max_y; if (mDecom) { min_y = mScrollStart; max_y = mScrollEnd; } else { min_y = 0; max_y = mConMaxRows; } if (r < min_y) row = min_y; else if (r >= max_y) row = max_y - 1; else row = r; Goto(col, row); mNeedWrap = false;}//for absolute user moves, when decom is setvoid Console::AbsGoto(int c, int r) { ConGoto(c, mDecom ? (mScrollStart + r) : r);}void Console::Lf() { /* don't scroll if above bottom of scrolling region, or * if below scrolling region */ if (Row() + 1 == mScrollEnd) ScrollScr(UP); else if (Row() < mConEndRow) Goto(Col(), Row() + 1); mNeedWrap = false;}void Console::Cr() { Goto(0, Row()); mNeedWrap = false;}//push top line into history buffersvoid Console::PushHistoryLine() { int s = mConMaxCols; memcpy(mpHistText + mHistCurRow * s, mpText, s); memcpy(mpHistAttr + mHistCurRow * s, mpAttr, s); memcpy(mpHistFlag + mHistCurRow * s, mpFlag, s); mHistCurRow = (mHistCurRow + 1) % HISTORY_LINES;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -