📄 term.h
字号:
/* term.h
* Copyright (c) 1997 David Cole
*
* Control and manage the terminal window
*/
#ifndef __term_h
#define __term_h
/* Constants for windows size limits - Khader Alatrash */
#define TERM_MIN_X 10
#define TERM_MAX_X 222
#define TERM_MIN_Y 2
#define TERM_MAX_Y 222
#define MAX_TERM_LINES 2000; // must be >= TERM_MAX_Y
/* Why 222 and not 255? Because mouse events are encoded in x+20h,y+20h form
* and coordinates are 1-based. So 223+32+1 would overflow a byte (256).
* Besides, the one who wants 200+ columns/rows probably have an extremely big
* monitor screen and using tiny fonts. (Superior vision?)
* 2001/01/11 -- Mark Melvin
*/
/* Implement a state machine to decode the terminal escape sequences
*/
typedef enum {
consNormal,
consEscape,
consHash,
consOpenSquare,
consCloseSquare,
consGetTitle,
consGetParams,
consOpenParen,
consCloseParen,
consHaveParams,
consDCS,
consDCS1,
consDCS2
} ConsoleState;
/* Define the colors in the order they appear in the palette
*/
enum AttrColor {
Black, Red, Green, Yellow, Blue, Magenta, Cyan, White
};
#define BOLD 8
#define GET_BOLD(a) ((a) & BOLD)
#define FG_MASK (0x07)
#define FG(c) (c)
#define GET_FGC(a) ((a) & 0x07)
#define GET_FG(a) ((a) & 0x0f)
#define BG_MASK (0x70)
#define BG(c) ((c) << 4)
#define GET_BG(a) (((a) & BG_MASK) >> 4)
#define REVERSE(a) (BG(GET_FGC(a)) | FG(GET_BG(a)) | GET_BOLD(a))
#define NO_ATTRIBS (FG(White)+BG(Black))
/* Keep all lines in an array of pointers to lines.
* Each line has the following attributes;
* len - need to known where the end of line is for selection
* text - array of [len] characters representing the line text
* attr - array of [len + 1] bytes representing the attributes of
* the characters in the line. The last attribute byte defines
* attrib to width of window
*/
#define MaxLineLen 256
#define MAXSPARAM 128 /* Maximum length of string-parameters like 'Answerback message' */
#define DTCHAR_ASCII 0 /* 0x00..0x7f charset-independent */
#define DTCHAR_OEM 255 /* 0x80..0xff OEM charset, eg grafical-characters */
#define DTCHAR_ANSI 254 /* 0x80..0xff ANSI charset */
typedef struct DtChar {
unsigned char cType; /* DTCHAR_xxx */
unsigned char cCode;
} DtChar;
typedef struct {
int len; /* length of the line */
int wrapped; /* suppress end of line in Paste */
DtChar text[MaxLineLen]; /* text in the line */
char attr[MaxLineLen]; /* attributes of each character */
} Line;
/* Cursor styles
*/
typedef enum {
cursorBlock,
cursorUnderLine,
cursorVertLine
} CursorStyle;
typedef struct {
HFONT font; /* terminal font */
HFONT oemfont; /* terminal OEM font */
BYTE fontCharSet; /* character set of terminal font */
SIZE charSize; /* size of the character cell */
SIZE winSize; /* current terminal size (in characters) */
SIZE winInitPos; /* initial window position (in pixels) */
BOOL useInitPos; /* override initial placement? */
RECT cursorRect; /* cursor rect, relative to charSize */
HBITMAP caretBitmap; /* the caret bitmap */
Line** lineList; /* all lines in buffer */
int topVisibleLine; /* top visible line on window (line index) */
int numLinesUsed; /* number of lines in buffer */
int maxLines; /* maximum number of lines to remember */
POINT selectFrom; /* start of selection (line index) */
POINT selectTo; /* end of selection (line index) */
BOOL selectWords; /* select words, not characters */
BOOL haveSelection; /* do we have a selection at the moment? */
ConsoleState state; /* emulation state */
BOOL seenQuestion; /* seen '?' in escape sequence? */
POINT cursor; /* current cursor position (terminal) */
BOOL cursorVisible; /* is cursor visible? */
BOOL cursorRelative; /* cursor address relative(T) / absolute(F) */
char blankAttr; /* clear screen character attribute */
char currAttr; /* current character attribute */
BOOL inverseVideo; /* is inverse video set? */
BOOL lineWrap; /* should we wrap lines */
BOOL insertMode; /* should we insert characters */
BOOL newLineMode; /* CR key returns '\r\n'(T) or '\n'(F) */
BOOL ansiCursorKeys; /* ANSI cursor key sequences? */
BOOL autoRepeat; /* should keys auto repeat? */
BOOL flowStartAny; /* does any key restart flow? */
BOOL echoKeystrokes; /* should we echo keystrokes? */
unsigned char tabStops[MaxLineLen]; /* 1 == tabstop */
int params[20]; /* escape sequence parameters */
int numParams; /* number of parameters defined */
char sparam[MAXSPARAM]; /* string param */
int numSParam; /* bytes collected in 'sparam' */
int stateSParam; /* 0/1/2 = waiting: normal bytes/hex first half/hex sencond half */
char dcschar; /* when in a DCS-sequence, the controlling code */
BOOL haveRegion; /* do we have a scrolling region? */
int scrollTop; /* top of scrolling region (terminal) */
int scrollBottom; /* bottom of scrolling region (terminal) */
int charSet; /* current character set 0/1 */
unsigned char* G0CharSet; /* current G0 character set */
unsigned char* G1CharSet; /* current G1 character set */
POINT savedCursor; /* saved cursor */
char savedAttr; /* saved attributes */
int savedCharSet; /* saved character set */
unsigned char* savedG0CharSet;/* saved G0 character set */
unsigned char* savedG1CharSet;/* saved G1 character set */
BOOL savedInverseVideo; /* saved is inverse video set? */
BOOL mouseReporting; /* are we in mouse reporting mode ? */
char title[128]; /* application set title */
BOOL attachedPrinter; /* enables xterm-style attached printer */
BOOL enablePrintScreen; /* enables screen dump operation */
} Terminal;
extern Terminal term; /* the one and only terminal */
/* Copy the selection onto the clipboard */
void termSelectCopy(void);
/* Paste the current clipboard contents into the terminal */
void termSelectPaste(void);
/* Return whether or not there currently is a selection */
BOOL termHaveSelection(void);
/* Return whether or not the user is currently performing a selection */
BOOL termSelectInProgress(void);
/* Return the state of auto-copy on selection */
BOOL termAutoCopy(void);
/* Toggle the state of auto-copy on selection */
void termToggleAutoCopy(void);
/* Return the state of mouse event reporting */
BOOL termMouseReporting(void);
/* Toggle the state of mouse event reporting */
void termToggleMouseReporting(void);
/* Return the state of xterm-style attached printer */
BOOL termAttachedPrinter(void);
/* Toggle the state of xterm-style attached printer */
void termToggleAttachedPrinter(void);
/* Return the state of printscreen */
BOOL termPrintScreenEnabled(void);
/* Toggle the state of printscreen */
void termTogglePrintScreen(void);
/* Return the current cursor style */
CursorStyle termCursorStyle(void);
/* Set the cursor style */
void termSetCursorStyle(CursorStyle style);
/* Return handle of the terminal window */
HWND termGetWnd(void);
/* Set the font used to draw the terminal */
void termSetFont(void);
/* Checks if windows size is according to defined limits - Khader Alatrash */
void termCheckSizeLimits(void);
/* Set the geometry of the terminal window (in characters) */
void termSetGeometry(char* str);
/* Set the attribute to be used for blank characters */
void termSetBlankAttr(int attr);
/* Set the application window title */
void termSetTitle(char* title);
/* Return the application window title */
char* termGetTitle(void);
/* Return whether or not there is a application window title set */
BOOL termHasTitle(void);
/* Scroll the terminal to the bottom of the history */
void termScrollToBottom(void);
/* Toggle whether or not terminal output forces a scroll to bottom */
void termToggleBottomOnOutput(void);
/* Return whether or not terminal output forces a scroll to bottom */
BOOL termBottomOnOutput(void);
/* User released a key - auto-repeat detection */
void termKeyDown(UINT key, DWORD flags);
/* User pressed a normal character key */
void termKeyPress(UINT key, DWORD flags);
/* User pressed a system key (Alt+Key) */
void termSysKeyDown(UINT key, DWORD flags);
/* Hide the caret in the terminal window */
void termHideCaret(void);
/* Show the caret in the terminal window */
void termShowCaret(void);
/* Set the caret visibility in the terminal window */
void termSetCursorMode(BOOL visible);
/* Application has just gained focus */
void termSetFocus(void);
/* Application has just lost focus */
void termKillFocus(void);
/* The application window has been resized - set the terminal window size */
void termSetWindowSize(int cx, int cy);
/* Windows is going to change application window size. */
void termWindowPosChanging(SIZE* winSize);
/* Format the terminal window geometry */
void termFormatSize(char* str);
/* Create the terminal window */
BOOL termCreateWnd(HINSTANCE instance, HWND parent);
/* Register the terminal window class */
BOOL termInitClass(HINSTANCE instance);
/* termGetChar: fetch characters from a DtChar array
* Before the very first call set
* *nChar=0, *cf= DTC_ASCII/DTC_ANSI/DTC_OEM
* After the very last call
* *nChar=number of characters, *cf=DTC_ASCII/DTC_ANSI/DTC_OEM
*/
extern void termGetChars (char *text, const DtChar *ch, int len, int *nChar, int *cs);
/* termGetConstChars: similar to the previous, but for constant characters
* which are charset-independents (code 0..127)
*/
void termGetConstChars (char *text, const char *ch, int len, int *nChar);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -