3 * - By John Hodge (thePowersGang)
6 * - Virtual Terminal - VT100 (Kinda) Emulation
11 #define sTerminal sVTerm
12 #include "../../../Usermode/Applications/gui_terminal_src/vt100.c"
14 void *Display_GetTermState(tTerminal *Term) {
15 return Term->VT100Info;
17 void Display_SetTermState(tTerminal *Term, void *State) {
18 Term->VT100Info = State;
21 void Display_SendInput(tTerminal *Term, const char *String)
23 PTY_SendInput(Term->PTY, String, strlen(String));
26 void Display_AddText(tTerminal *Term, size_t Length, const char *UTF8Text)
28 LOG("'%*C'", Length, UTF8Text);
29 VT_int_PutRawString(Term, (const void*)UTF8Text, Length);
31 void Display_Newline(tTerminal *Term, bool bCarriageReturn)
34 VT_int_PutChar(Term, '\n');
36 void Display_SetScrollArea(tTerminal *Term, int Start, int Count)
38 LOG("(%i,+%i)", Start, Count);
39 Term->ScrollTop = Start;
40 Term->ScrollHeight = Count;
42 void Display_ScrollDown(tTerminal *Term, int CountDown)
44 LOG("(%i)", CountDown);
45 VT_int_UpdateScreen(Term, 0);
46 if( Term->Flags & VT_FLAG_ALTBUF )
47 VT_int_ScrollText(Term, CountDown);
50 if(Term->ViewTopRow + CountDown < 0)
52 if(Term->ViewTopRow + CountDown > Term->TextHeight * (giVT_Scrollback + 1))
55 Term->ViewTopRow += CountDown;
58 void Display_SetCursor(tTerminal *Term, int Row, int Col)
60 LOG("(R%i,C%i)", Row, Col);
61 VT_int_UpdateScreen(Term, 0);
62 int maxrows = VT_int_GetBufferRows(Term);
63 ASSERTCR( Row, >=, 0, );
64 ASSERTCR( Row, <, maxrows, );
65 ASSERTCR( Col, >=, 0, );
66 ASSERTCR( Col, <, Term->TextWidth, );
67 VT_int_GetWritePosPtr(Term)->Row = Row;
68 VT_int_GetWritePosPtr(Term)->Col = Col;
70 void Display_MoveCursor(tTerminal *Term, int RelRow, int RelCol)
72 LOG("(R+%i,C+%i)", RelRow, RelCol);
73 tVT_Pos *wrpos = VT_int_GetWritePosPtr(Term);
75 // TODO: Support scrolling if cursor goes offscreen
76 // if( bScrollIfNeeded )
77 // Display_ScrollDown(extra);
92 size_t max = Term->TextWidth - wrpos->Col - 1;
100 int currow = wrpos->Row;
101 int maxrows = VT_int_GetBufferRows(Term);
104 if( RelRow < -currow )
109 if( currow + RelRow > maxrows-1 )
110 RelRow = maxrows-1 - currow;
112 wrpos->Row += RelRow;
114 LOG("=(R%i,C%i)", wrpos->Row, wrpos->Col);
116 void Display_SaveCursor(tTerminal *Term)
118 Term->SavedWritePos = *VT_int_GetWritePosPtr(Term);
119 LOG("Saved = %i", Term->SavedWritePos);
121 void Display_RestoreCursor(tTerminal *Term)
123 size_t maxrow = VT_int_GetBufferRows(Term);
124 tVT_Pos *wrpos = VT_int_GetWritePosPtr(Term);
125 *wrpos = Term->SavedWritePos;
126 if(wrpos->Row >= maxrow)
127 wrpos->Row = maxrow-1;
128 if(wrpos->Col >= Term->TextWidth )
129 wrpos->Col = Term->TextWidth-1;
130 LOG("Restored (R%i,C%i)", wrpos->Row, wrpos->Col);
132 // 0: All, 1: Forward, -1: Reverse
133 void Display_ClearLine(tTerminal *Term, int Dir)
135 const tVT_Pos *wrpos = VT_int_GetWritePosPtr(Term);
137 LOG("(Dir=%i)", Dir);
141 VT_int_ClearLine(Term, wrpos->Row);
142 VT_int_UpdateScreen(Term, 0);
145 else if( Dir == 1 ) {
146 VT_int_ClearInLine(Term, wrpos->Row, wrpos->Col, Term->TextWidth);
147 VT_int_UpdateScreen(Term, 0);
150 else if( Dir == -1 ) {
151 VT_int_ClearInLine(Term, wrpos->Row, 0, wrpos->Col);
152 VT_int_UpdateScreen(Term, 0);
156 ASSERTC(Dir, >=, -1);
160 void Display_ClearLines(tTerminal *Term, int Dir)
162 LOG("(Dir=%i)", Dir);
163 tVT_Pos *wrpos = VT_int_GetWritePosPtr(Term);
164 size_t height = VT_int_GetBufferRows(Term);
169 if( !(Term->Flags & VT_FLAG_ALTBUF) ) {
170 Term->ViewTopRow = 0;
174 VT_int_ClearLine(Term, count);
177 VT_int_UpdateScreen(Term, 1);
180 else if( Dir == 1 ) {
181 for( int row = wrpos->Row; row < height; row ++ )
182 VT_int_ClearLine(Term, row);
183 VT_int_UpdateScreen(Term, 1);
186 else if( Dir == -1 ) {
187 for( int row = 0; row < wrpos->Row; row ++ )
188 VT_int_ClearLine(Term, row);
189 VT_int_UpdateScreen(Term, 1);
193 ASSERTC(Dir, >=, -1);
197 void Display_ResetAttributes(tTerminal *Term)
200 Term->CurColour = DEFAULT_COLOUR;
202 void Display_SetForeground(tTerminal *Term, uint32_t RGB)
205 Term->CurColour &= 0x8000FFFF;
206 Term->CurColour |= (Uint32)VT_Colour24to12(RGB) << 16;
209 void Display_SetBackground(tTerminal *Term, uint32_t RGB)
212 Term->CurColour &= 0xFFFF8000;
213 Term->CurColour |= (Uint32)VT_Colour24to12(RGB) << 0;
215 void Display_Flush(tTerminal *Term)
218 VT_int_UpdateScreen(Term, 0);
220 void Display_ShowAltBuffer(tTerminal *Term, bool AltBufEnabled)
222 LOG("(%B)", AltBufEnabled);
223 VT_int_ToggleAltBuffer(Term, AltBufEnabled);
225 void Display_SetTitle(tTerminal *Term, const char *Title)