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