* drv/vterm_termbuf.c
* - Virtual Terminal - Terminal buffer manipulation
*/
+#define DEBUG 0
#include "vterm.h"
+extern int Term_HandleVT100(tVTerm *Term, int Len, const char *Buf);
+
// === CODE ===
/**
*/
void VT_int_PutString(tVTerm *Term, const Uint8 *Buffer, Uint Count)
{
- int i;
-
// Iterate
- for( i = 0; i < Count; i++ )
+ for( int ofs = 0; ofs < Count; )
{
- // Handle escape sequences
- if( Buffer[i] == 0x1B && Count - i > 1 )
- {
- int ret = VT_int_ParseEscape(Term, (const char*)&Buffer[i+1], Count-(i+1));
- if( ret > 0 )
- {
- i += ret;
- continue;
- }
+ int esc_len = Term_HandleVT100(Term, Count - ofs, (const void*)(Buffer + ofs));
+ if( esc_len < 0 ) {
+ esc_len = -esc_len;
+ //LOG("%i '%*C'", esc_len, esc_len, Buffer+ofs);
+ LOG("%i '%.*s'", esc_len, esc_len, Buffer+ofs);
+ VT_int_PutRawString(Term, Buffer + ofs, esc_len);
+ //Debug("Raw string '%.*s'", esc_len, Buffer+ofs);
}
-
- // Fast check for non UTF-8
- if( Buffer[i] < 128 ) // Plain ASCII
- VT_int_PutChar(Term, Buffer[i]);
- else { // UTF-8
- Uint32 val;
- i += ReadUTF8(&Buffer[i], &val) - 1;
- VT_int_PutChar(Term, val);
+ else {
+ //Debug("Escape code '%.*s'", esc_len, Buffer+ofs);
}
+ ASSERTCR(esc_len, >, 0, );
+ ofs += esc_len;
}
// Update Screen
- VT_int_UpdateScreen( Term, 0 );
+ VT_int_UpdateScreen( Term, 1 );
+}
+
+void VT_int_PutRawString(tVTerm *Term, const Uint8 *String, size_t Bytes)
+{
+ for( int i = 0; i < Bytes; ) {
+ Uint32 val;
+ i += ReadUTF8(String+i, &val);
+ VT_int_PutChar(Term, val);
+ }
}
/**
int i;
tVT_Char *buffer;
int write_pos;
+ int limit;
if(Term->Flags & VT_FLAG_ALTBUF) {
buffer = Term->AltBuf;
write_pos = Term->AltWritePos;
+ limit = Term->TextHeight * Term->TextWidth;
}
else {
buffer = Term->Text;
write_pos = Term->WritePos;
+ limit = Term->TextHeight*(giVT_Scrollback+1) * Term->TextWidth;
}
switch(Ch)
break;
default:
+ ASSERTC(write_pos,<,limit);
buffer[ write_pos ].Ch = Ch;
buffer[ write_pos ].Colour = Term->CurColour;
// Update the line before wrapping
{
Term->AltWritePos = write_pos;
- if(Term->AltWritePos >= Term->TextWidth*Term->TextHeight)
+ if(Term->AltWritePos >= limit)
{
Term->AltWritePos -= Term->TextWidth;
VT_int_ScrollText(Term, 1);
}
-
}
else
{
Term->WritePos = write_pos;
// Move Screen
// - Check if we need to scroll the entire scrollback buffer
- if(Term->WritePos >= Term->TextWidth*Term->TextHeight*(giVT_Scrollback+1))
+ if(Term->WritePos >= limit)
{
int base;
*/
void VT_int_ClearLine(tVTerm *Term, int Num)
{
- int i;
- tVT_Char *cell;
-
- if( Num < 0 || Num >= Term->TextHeight * (giVT_Scrollback + 1) ) return ;
+ int limit = Term->TextHeight * (Term->Flags & VT_FLAG_ALTBUF ? 1 : giVT_Scrollback + 1);
+ tVT_Char *buffer = (Term->Flags & VT_FLAG_ALTBUF ? Term->AltBuf : Term->Text);
+ if( Num < 0 || Num >= limit ) return ;
- cell = (Term->Flags & VT_FLAG_ALTBUF) ? Term->AltBuf : Term->Text;
- cell = &cell[ Num*Term->TextWidth ];
+ tVT_Char *cell = &buffer[ Num*Term->TextWidth ];
- for( i = Term->TextWidth; i--; )
+ for( int i = 0; i < Term->TextWidth; i ++ )
{
cell[ i ].Ch = 0;
cell[ i ].Colour = Term->CurColour;
* \param NewWidth New framebuffer width
* \param NewHeight New framebuffer height
*/
-void VT_int_ChangeMode(tVTerm *Term, int NewMode, int NewWidth, int NewHeight)
+void VT_int_Resize(tVTerm *Term, int NewWidth, int NewHeight)
{
int oldW = Term->Width;
int oldTW = Term->TextWidth;
if(NewWidth > giVT_RealWidth) NewWidth = giVT_RealWidth;
if(NewHeight > giVT_RealHeight) NewHeight = giVT_RealHeight;
- Term->Mode = NewMode;
-
// Fast exit if no resolution change
if(NewWidth == Term->Width && NewHeight == Term->Height)
return ;
// Debug
#if 0
- switch(NewMode)
+ switch(Term->Mode)
{
case TERM_MODE_TEXT:
Log_Log("VTerm", "Set VT %p to text mode (%ix%i)",