1*160bd2ffSMichael Lotz #ifndef _CONSOLE_H_ 2*160bd2ffSMichael Lotz #define _CONSOLE_H_ 3*160bd2ffSMichael Lotz 4*160bd2ffSMichael Lotz #include <SupportDefs.h> 5*160bd2ffSMichael Lotz 6*160bd2ffSMichael Lotz #define TAB_SIZE 8 7*160bd2ffSMichael Lotz #define TAB_MASK 7 8*160bd2ffSMichael Lotz 9*160bd2ffSMichael Lotz #define FMASK 0x0f 10*160bd2ffSMichael Lotz #define BMASK 0x70 11*160bd2ffSMichael Lotz 12*160bd2ffSMichael Lotz typedef enum { 13*160bd2ffSMichael Lotz CONSOLE_STATE_NORMAL = 0, 14*160bd2ffSMichael Lotz CONSOLE_STATE_GOT_ESCAPE, 15*160bd2ffSMichael Lotz CONSOLE_STATE_SEEN_BRACKET, 16*160bd2ffSMichael Lotz CONSOLE_STATE_NEW_ARG, 17*160bd2ffSMichael Lotz CONSOLE_STATE_PARSING_ARG, 18*160bd2ffSMichael Lotz } console_state; 19*160bd2ffSMichael Lotz 20*160bd2ffSMichael Lotz typedef enum { 21*160bd2ffSMichael Lotz SCREEN_ERASE_WHOLE, 22*160bd2ffSMichael Lotz SCREEN_ERASE_UP, 23*160bd2ffSMichael Lotz SCREEN_ERASE_DOWN 24*160bd2ffSMichael Lotz } erase_screen_mode; 25*160bd2ffSMichael Lotz 26*160bd2ffSMichael Lotz typedef enum { 27*160bd2ffSMichael Lotz LINE_ERASE_WHOLE, 28*160bd2ffSMichael Lotz LINE_ERASE_LEFT, 29*160bd2ffSMichael Lotz LINE_ERASE_RIGHT 30*160bd2ffSMichael Lotz } erase_line_mode; 31*160bd2ffSMichael Lotz 32*160bd2ffSMichael Lotz #define MAX_ARGS 8 33*160bd2ffSMichael Lotz 34*160bd2ffSMichael Lotz class ViewBuffer; 35*160bd2ffSMichael Lotz 36*160bd2ffSMichael Lotz class Console { 37*160bd2ffSMichael Lotz public: 38*160bd2ffSMichael Lotz Console(ViewBuffer *output); 39*160bd2ffSMichael Lotz ~Console(); 40*160bd2ffSMichael Lotz 41*160bd2ffSMichael Lotz void ResetConsole(); 42*160bd2ffSMichael Lotz 43*160bd2ffSMichael Lotz void SetScrollRegion(int top, int bottom); 44*160bd2ffSMichael Lotz void ScrollUp(); 45*160bd2ffSMichael Lotz void ScrollDown(); 46*160bd2ffSMichael Lotz 47*160bd2ffSMichael Lotz void LineFeed(); 48*160bd2ffSMichael Lotz void RLineFeed(); 49*160bd2ffSMichael Lotz void CariageReturn(); 50*160bd2ffSMichael Lotz 51*160bd2ffSMichael Lotz void Delete(); 52*160bd2ffSMichael Lotz void Tab(); 53*160bd2ffSMichael Lotz 54*160bd2ffSMichael Lotz void EraseLine(erase_line_mode mode); 55*160bd2ffSMichael Lotz void EraseScreen(erase_screen_mode mode); 56*160bd2ffSMichael Lotz 57*160bd2ffSMichael Lotz void SaveCursor(bool save_attrs); 58*160bd2ffSMichael Lotz void RestoreCursor(bool restore_attrs); 59*160bd2ffSMichael Lotz void UpdateCursor(int x, int y); 60*160bd2ffSMichael Lotz void GotoXY(int new_x, int new_y); 61*160bd2ffSMichael Lotz 62*160bd2ffSMichael Lotz void PutChar(const char c); 63*160bd2ffSMichael Lotz 64*160bd2ffSMichael Lotz void SetVT100Attributes(int32 *args, int32 argCount); 65*160bd2ffSMichael Lotz bool ProcessVT100Command(const char c, bool seen_bracket, int32 *args, int32 argCount); 66*160bd2ffSMichael Lotz 67*160bd2ffSMichael Lotz void Write(const void *buf, size_t len); 68*160bd2ffSMichael Lotz 69*160bd2ffSMichael Lotz private: 70*160bd2ffSMichael Lotz static void ResizeCallback(int32 width, int32 height, void *data); 71*160bd2ffSMichael Lotz 72*160bd2ffSMichael Lotz int32 fLines; 73*160bd2ffSMichael Lotz int32 fColumns; 74*160bd2ffSMichael Lotz 75*160bd2ffSMichael Lotz uint8 fAttr; 76*160bd2ffSMichael Lotz uint8 fSavedAttr; 77*160bd2ffSMichael Lotz bool fBrightAttr; 78*160bd2ffSMichael Lotz bool fReverseAttr; 79*160bd2ffSMichael Lotz 80*160bd2ffSMichael Lotz int32 fX; // current x coordinate 81*160bd2ffSMichael Lotz int32 fY; // current y coordinate 82*160bd2ffSMichael Lotz int32 fSavedX; // used to save x and y 83*160bd2ffSMichael Lotz int32 fSavedY; 84*160bd2ffSMichael Lotz 85*160bd2ffSMichael Lotz int32 fScrollTop; // top of the scroll region 86*160bd2ffSMichael Lotz int32 fScrollBottom; // bottom of the scroll region 87*160bd2ffSMichael Lotz 88*160bd2ffSMichael Lotz /* state machine */ 89*160bd2ffSMichael Lotz console_state fState; 90*160bd2ffSMichael Lotz int32 fArgCount; 91*160bd2ffSMichael Lotz int32 fArgs[MAX_ARGS]; 92*160bd2ffSMichael Lotz 93*160bd2ffSMichael Lotz ViewBuffer *fOutput; 94*160bd2ffSMichael Lotz }; 95*160bd2ffSMichael Lotz 96*160bd2ffSMichael Lotz #endif 97