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->ViewPos/Term->TextWidth + CountDown < 0)
52 if(Term->ViewPos/Term->TextWidth + CountDown > Term->TextHeight * (giVT_Scrollback + 1))
55 Term->ViewPos += Term->TextWidth * 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*Term->TextWidth + Col;
69 void Display_MoveCursor(tTerminal *Term, int RelRow, int RelCol)
71 LOG("(R+%i,C+%i)", RelRow, RelCol);
72 size_t *wrpos = VT_int_GetWritePosPtr(Term);
74 // TODO: Support scrolling if cursor goes offscreen
75 // if( bScrollIfNeeded )
76 // Display_ScrollDown(extra);
85 int max = *wrpos % Term->TextWidth;
91 size_t max = Term->TextWidth - (*wrpos % Term->TextWidth) - 1;
99 int currow = *wrpos / Term->TextWidth;
100 int maxrows = VT_int_GetBufferRows(Term);
103 if( RelRow < -currow )
108 if( currow + RelRow > maxrows-1 )
109 RelRow = maxrows-1 - currow;
111 *wrpos += RelRow*Term->TextWidth;
113 LOG("=(R%i,C%i)", *wrpos / Term->TextWidth, *wrpos % Term->TextWidth);
115 void Display_SaveCursor(tTerminal *Term)
117 Term->SavedWritePos = *VT_int_GetWritePosPtr(Term);
118 LOG("Saved = %i", Term->SavedWritePos);
120 void Display_RestoreCursor(tTerminal *Term)
122 size_t max = VT_int_GetBufferRows(Term) * Term->TextWidth;
123 size_t *wrpos = VT_int_GetWritePosPtr(Term);
124 *wrpos = MIN(Term->SavedWritePos, max-1);
125 LOG("Restored %i", *wrpos);
127 // 0: All, 1: Forward, -1: Reverse
128 void Display_ClearLine(tTerminal *Term, int Dir)
130 const size_t wrpos = *VT_int_GetWritePosPtr(Term);
131 const int row = wrpos / Term->TextWidth;
132 const int col = wrpos % Term->TextWidth;
134 LOG("(Dir=%i)", Dir);
138 VT_int_ClearLine(Term, row);
139 VT_int_UpdateScreen(Term, 0);
142 else if( Dir == 1 ) {
143 VT_int_ClearInLine(Term, row, col, Term->TextWidth);
144 VT_int_UpdateScreen(Term, 0);
147 else if( Dir == -1 ) {
148 VT_int_ClearInLine(Term, row, 0, col);
149 VT_int_UpdateScreen(Term, 0);
153 ASSERTC(Dir, >=, -1);
157 void Display_ClearLines(tTerminal *Term, int Dir)
159 LOG("(Dir=%i)", Dir);
160 size_t *wrpos = VT_int_GetWritePosPtr(Term);
161 size_t height = VT_int_GetBufferRows(Term);
166 if( !(Term->Flags & VT_FLAG_ALTBUF) ) {
171 VT_int_ClearLine(Term, count);
173 VT_int_UpdateScreen(Term, 1);
176 else if( Dir == 1 ) {
177 for( int row = *wrpos / Term->TextWidth; row < height; row ++ )
178 VT_int_ClearLine(Term, row);
179 VT_int_UpdateScreen(Term, 1);
182 else if( Dir == -1 ) {
183 for( int row = 0; row < *wrpos / Term->TextWidth; row ++ )
184 VT_int_ClearLine(Term, row);
185 VT_int_UpdateScreen(Term, 1);
189 ASSERTC(Dir, >=, -1);
193 void Display_ResetAttributes(tTerminal *Term)
196 Term->CurColour = DEFAULT_COLOUR;
198 void Display_SetForeground(tTerminal *Term, uint32_t RGB)
201 Term->CurColour &= 0x8000FFFF;
202 Term->CurColour |= (Uint32)VT_Colour24to12(RGB) << 16;
205 void Display_SetBackground(tTerminal *Term, uint32_t RGB)
208 Term->CurColour &= 0xFFFF8000;
209 Term->CurColour |= (Uint32)VT_Colour24to12(RGB) << 0;
211 void Display_Flush(tTerminal *Term)
214 VT_int_UpdateScreen(Term, 0);
216 void Display_ShowAltBuffer(tTerminal *Term, bool AltBufEnabled)
218 LOG("(%B)", AltBufEnabled);
219 VT_int_ToggleAltBuffer(Term, AltBufEnabled);
221 void Display_SetTitle(tTerminal *Term, const char *Title)