ansiprsr.cpp
来自「一个类似windows」· C++ 代码 · 共 1,477 行 · 第 1/3 页
CPP
1,477 行
buf[iParam[0]] = 0;
if ( fast_write )
Console.WriteStringFast(buf, iParam[0]);
else
Console.WriteString(buf, iParam[0]);
// } /* IF */
break;
// Go to line p
// Added by I.Ioannou 06 April, 1997
case 'd':
if (iCurrentParam < 1) // Alter Default
iParam[0] = 0;
// this was backward, and we should subtract 1 from y
// (Paul Brannan 5/27/98)
ConSetCursorPos(Console.GetCursorX(), iParam[0] - 1);
break;
// iBCS2 tab erase
// Added by I.Ioannou 06 April, 1997
case 'g':
if (iCurrentParam < 1) // Alter Default
iParam[0] = 0;
switch (iParam[0]) {
case 0:
{
// Clear the horizontal tab stop at the current active position
for(int j = 0; j < MAX_TAB_POSITIONS; j++) {
int x = Console.GetCursorX();
if(tab_stops[j] == x) tab_stops[j] = tab_stops[x + 1];
}
}
break;
case 2:
// I think this might be "set as default?"
break;
case 3:
{
// Clear all tab stops
for(int j = 0; j < MAX_TAB_POSITIONS; j++)
tab_stops[j] = -1;
}
break;
}
break;
// Set extended mode
case 'h':
{
for (int i = 0; i < iCurrentParam; i++) {
// Changed to a switch statement (Paul Brannan 5/27/98)
if(flag & FLAG_QMARK) {
switch(iParam[i]) {
case 1: // App cursor keys
KeyTrans.set_ext_mode(APP_KEY);
break;
case 2: // VT102 mode
vt52_mode = 0;
KeyTrans.unset_ext_mode(APP2_KEY);
break;
case 3: // 132 columns
if(ini.get_wide_enable()) {
Console.SetWindowSize(132, -1);
}
break;
case 4: // smooth scrolling
break;
case 5: // Light background
Console.Lightbg();
break;
case 6: // Stay in margins
ignore_margins = 0;
break;
case 7:
Console.setLineWrap(true);
break;
case 8: // Auto-repeat keys
break;
case 18: // Send FF to printer
break;
case 19: // Entire screen legal for printer
break;
case 25: // Visible cursor
break;
case 66: // Application numeric keypad
break;
default:
#ifdef DEBUG
Console.Beep();
#endif
break;
}
} else {
switch(iParam[i]) {
case 2: // Lock keyboard
break;
case 3: // Act upon control codes (PB 12/5/98)
print_ctrl = 0;
break;
case 4: // Set insert mode
Console.InsertMode(1);
break;
case 12: // Local echo off
break;
case 20: // Newline sends cr/lf
KeyTrans.set_ext_mode(APP4_KEY);
newline_mode = true;
break;
default:
#ifdef DEBUG
Console.Beep();
#endif
break;
}
}
}
}
break;
// Print Screen
case 'i':
if (iCurrentParam < 1)
iParam[0]=0;
switch (iParam[0]){
case 0: break; // Print Screen
case 1: break; // Print Line
// Added I.Ioannou 06 April, 1997
case 4:
// Stop Print Log
InPrintMode = 0;
if ( printfile != NULL )
fclose(printfile);
break;
case 5:
// Start Print Log
printfile = fopen(ini.get_printer_name(), "ab");
if (printfile != NULL) InPrintMode = 1;
break;
}
break;
// Unset extended mode
case 'l':
{
for (int i = 0; i < iCurrentParam; i++) {
// Changed to a switch statement (Paul Brannan 5/27/98)
if(flag & FLAG_QMARK) {
switch(iParam[i]) {
case 1: // Numeric cursor keys
KeyTrans.unset_ext_mode(APP_KEY);
break;
case 2: // VT52 mode
vt52_mode = 1;
KeyTrans.set_ext_mode(APP2_KEY);
break;
case 3: // 80 columns
if(ini.get_wide_enable()) {
Console.SetWindowSize(80, -1);
}
break;
case 4: // jump scrolling
break;
case 5: // Dark background
Console.Darkbg();
break;
case 6: // Ignore margins
ignore_margins = 1;
break;
case 7:
Console.setLineWrap(false);
break;
case 8: // Auto-repeat keys
break;
case 19: // Only send scrolling region to printer
break;
case 25: // Invisible cursor
break;
case 66: // Numeric keypad
break;
default:
#ifdef DEBUG
Console.Beep();
#endif
break;
}
} else {
switch(iParam[i]) {
case 2: // Unlock keyboard
break;
case 3: // Display control codes (PB 12/5/98)
print_ctrl = 1;
break;
case 4: // Set overtype mode
Console.InsertMode(0);
break;
case 12: // Local echo on
break;
case 20: // sends lf only
KeyTrans.unset_ext_mode(APP4_KEY);
newline_mode = false;
break;
default:
#ifdef DEBUG
Console.Beep();
#endif
break;
}
}
}
}
break;
// Set color
case 'm':
if(missing_param) Console.Normal();
if(iCurrentParam == 0) {
Console.Normal();
} else {
for(int i = 0; i < iCurrentParam; i++)
ConSetAttribute(iParam[i]);
}
break;
// report cursor position Row X Col
case 'n':
if (iCurrentParam == 1 && iParam[0]==5) {
// report the cursor position
Network.WriteString("\x1B[0n", 6);
break;
}
if (iCurrentParam == 1 && iParam[0]==6){
// report the cursor position
// The cursor position needs to be sent as a single string
// (Paul Brannan 6/27/98)
char szCursorReport[40] = "\x1B[";
itoa(Console.GetCursorY() + 1,
&szCursorReport[strlen(szCursorReport)], 10);
strcat(szCursorReport, ";");
itoa(Console.GetCursorX() + 1,
&szCursorReport[strlen(szCursorReport)], 10);
strcat(szCursorReport, "R");
Network.WriteString(szCursorReport, strlen(szCursorReport));
}
break;
// Miscellaneous weird sequences (Paul Brannan 6/27/98)
case 'p':
// Set conformance level
if(flag & FLAG_QUOTE) {
break;
}
// Soft terminal reset
if(flag & FLAG_EXCLAM) {
break;
}
// Report mode settings
if(flag & FLAG_DOLLAR) {
break;
}
break;
// Scroll Screen
case 'r':
if (iCurrentParam < 1) {
// Enable scrolling for entire display
Console.SetScroll(-1, -1);
break;
}
if (iCurrentParam >1) {
// Enable scrolling from row1 to row2
Console.SetScroll(iParam[0] - 1, iParam[1] - 1);
// If the cursor is outside the scrolling range, fix it
// (Paul Brannan 6/26/98)
// if(Console.GetRawCursorY() < iParam[0] - 1) {
// Console.SetRawCursorPosition(Console.GetCursorX(),
// iParam[0] - 1);
// }
// if(Console.GetRawCursorY() > iParam[1] - 1) {
// Console.SetRawCursorPosition(Console.GetCursorX(),
// iParam[1] - 1);
// }
}
// Move the cursor to the home position (Paul Brannan 12/2/98)
Console.SetCursorPosition(0, 0);
break;
// Save cursor position
case 's':
SaveCurY(Console.GetRawCursorY());
SaveCurX(Console.GetRawCursorX());
break;
// Restore cursor position
case 'u':
Console.SetRawCursorPosition(iSavedCurX, iSavedCurY);
break;
// DEC terminal report (Paul Brannan 6/28/98)
case 'x':
if(iParam[0])
Network.WriteString("\033[3;1;1;128;128;1;0x", 20);
else
Network.WriteString("\033[2;1;1;128;128;1;0x", 20);
break;
default:
#ifdef DEBUG
Console.Beep();
#endif
break;
}
return pszBuffer;
}
#ifdef MTE_SUPPORT
// Added by Frediano Ziglio, 5/31/2000
// MTE extension
// initially copied from ParseEscapeANSI
char* TANSIParser::ParseEscapeMTE(char* pszBuffer, char* pszBufferEnd)
{
// The buffer contains something like <ESC>~pA
// where p is an optional decimal number specifying the count by which the
// appropriate action should take place.
// The pointer pszBuffer points us to the p, <ESC> and ~ are
// already 'consumed'
// TITUS: Simplification of the code: Assume default count of 1 in case
// there are no parameters.
char tmpc;
const int nParam = 10; // Maximum number of parameters
int iParam[nParam] = {1, 0, 0, 0, 0}; // Assume 1 parameter, Default 1
int iCurrentParam = 0;
char sRepeat[2];
// Get parameters from escape sequence.
while ((tmpc = *pszBuffer) <= '?') {
if(tmpc < '0' || tmpc > '9') {
// Check for parameter delimiter.
if(tmpc == ';') {
pszBuffer++;
continue;
}
pszBuffer++;
}
// Got Numerical Parameter.
iParam[iCurrentParam] = strtoul(pszBuffer, &pszBuffer, 10);
if (iCurrentParam < nParam)
iCurrentParam++;
}
//~~~ TITUS: Apparently the digit is optional (look at termcap or terminfo)
// So: If there is no digit, assume a count of 1
switch ((unsigned char)*pszBuffer++) {
case 'A':
// set colors
if (iCurrentParam < 2 )
break;
if (iParam[0] <= 15 && iParam[1] <= 15)
Console.SetAttrib( (iParam[1] << 4) | iParam[0] );
break;
case 'R':
// define region
mteRegionXF = -1;
if (iCurrentParam < 2 )
break;
mteRegionXF = iParam[1]-1;
mteRegionYF = iParam[0]-1;
break;
case 'F':
// fill with char
{
if (mteRegionXF == -1 || iCurrentParam < 1)
break;
sRepeat[0] = (char)iParam[0];
sRepeat[1] = '\0';
int xi = Console.GetCursorX(),yi = Console.GetCursorY();
int xf = mteRegionXF;
int yf = mteRegionYF;
mteRegionXF = -1;
for(int y=yi;y<=yf;++y)
{
Console.SetCursorPosition(xi,y);
for(int x=xi;x<=xf;++x)
Console.WriteStringFast(sRepeat,1);
}
}
break;
case 'S':
// Scroll region
{
if (mteRegionXF == -1 || iCurrentParam < 2)
break;
int /*x = Console.GetCursorX(),*/y = Console.GetCursorY();
// int xf = mteRegionXF;
int yf = mteRegionYF;
mteRegionXF = -1;
// !!! don't use x during scroll
int diff = (iParam[0]-1)-y;
if (diff<0)
Console.ScrollDown(y-1,yf,diff);
else
Console.ScrollDown(y,yf+1,diff);
}
break;
// Meridian main version ??
case 'x':
// disable echo and line mode
Network.set_local_echo(0);
Network.set_line_mode(0);
// Meridian Server handle cursor itself
Console.SetCursorSize(0);
break;
// query ??
case 'Q':
if (iParam[0] == 1)
Network.WriteString("\033vga.",5);
break;
default:
#ifdef DEBUG
Console.Beep();
#endif
break;
}
return pszBuffer;
}
#endif
char* TANSIParser::ParseEscape(char* pszBuffer, char* pszBufferEnd) {
char *pszChar;
// Check if we have enough characters in buffer.
if ((pszBufferEnd - pszBuffer) < 2)
return pszBuffer;
// I.Ioannou 04 Sep 1997
// there is no need for pszBuffer++; after each command
// Decode the command.
pszBuffer++;
switch (*pszBuffer++) {
case 'A': // Cursor up
Console.MoveCursorPosition(0, -1);
break;
// Cursor down
case 'B':
Console.MoveCursorPosition(0, 1);
break;
// Cursor right
case 'C':
Console.MoveCursorPosition(1, 0);
break;
// LF *or* cursor left (Paul Brannan 6/27/98)
case 'D':
if(vt52_mode)
Console.MoveCursorPosition(-1, 0);
else
Console.index();
break;
// CR/LF (Paul Brannan 6/26/98)
case 'E':
Console.WriteCtrlString("\r\n", 2);
break;
// Special graphics char set (Paul Brannan 6/27/98)
case 'F':
Charmap.setmap('0');
break;
// ASCII char set (Paul Brannan 6/27/98)
case 'G':
Charmap.setmap('B');
break;
// Home cursor/tab set
case 'H':
if(ini.get_vt100_mode()) {
int x = Console.GetCursorX();
if(x != 0) {
int t = tab_stops[x - 1];
for(int j = x - 1; j >= 0 && tab_stops[j] == t; j--)
tab_stops[j] = x;
}
} else {
// I.Ioannou 04 Sep 1997 (0,0) not (1,1)
ConSetCursorPos(0, 0);
}
break;
// Reverse line feed (Paul Brannan 6/27/98)
// FIX ME!!! reverse_index is wrong to be calling here
// (Paul Brannan 12/2/98)
case 'I':
Console.reverse_index();
break;
// Erase end of screen
case 'J':
Console.ClearEOScreen();
break;
// Erase EOL
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?