if( PTY->Mode.InputMode & PTYIMODE_CANON )
{
- const char char_bs = '\b';
+
switch(Input[0])
{
case 3: // INTR - ^C
print = 0;
break;
case 8: // Backspace
- if(PTY->LineLength != 0)
+ if(PTY->LineLength != 0) {
PTY->LineLength --;
+ PTY_WriteClient(&PTY->ClientNode, 0, 3, "\b \b", 0);
+ }
+ print = 0;
break;
case 'w'-'a': // Word erase
while(PTY->LineLength != 0 && isalnum(PTY->LineData[--PTY->LineLength]))
- PTY_WriteClient(&PTY->ClientNode, 0, 1, &char_bs, 0);
+ PTY_WriteClient(&PTY->ClientNode, 0, 1, "\b", 0);
+ PTY_WriteClient(&PTY->ClientNode, 0, 3, "\x1b[K", 0);
print = 0;
break;
case 'u'-'a': // Kill
- while(PTY->LineLength > 0)
- PTY_WriteClient(&PTY->ClientNode, 0, 1, &char_bs, 0);
+ PTY_WriteClient(&PTY->ClientNode, 0, 8, "\x1b[2K\x1b[0G", 0);
+ PTY->LineLength = 0;
print = 0;
break;
case 'v'-'a':
Uint32 CurColour; //!< Current Text Colour
- int ViewPos; //!< View Buffer Offset (Text Only)
- int WritePos; //!< Write Buffer Offset (Text Only)
+ size_t ViewPos; //!< View Buffer Offset (Text Only)
+ size_t WritePos; //!< Write Buffer Offset (Text Only)
tVT_Char *Text;
tVT_Char *AltBuf; //!< Alternate Screen Buffer
- int AltWritePos; //!< Alternate write position
+ size_t AltWritePos; //!< Alternate write position
short ScrollTop; //!< Top of scrolling region (smallest)
short ScrollHeight; //!< Length of scrolling region
- int SavedWritePos; //!< Saved cursor position (\e[s and \e[u)
+ size_t SavedWritePos; //!< Saved cursor position (\e[s and \e[u)
char EscapeCodeCache[16];
size_t EscapeCodeLen;
extern void VT_int_Resize(tVTerm *Term, int NewWidth, int NewHeight);
extern void VT_int_ToggleAltBuffer(tVTerm *Term, int Enabled);
+extern size_t *VT_int_GetWritePosPtr(tVTerm *Term);
+extern size_t VT_int_GetBufferRows(tVTerm *Term);
+
#endif
void VT_int_PutChar(tVTerm *Term, Uint32 Ch)
{
int i;
- tVT_Char *buffer;
- int write_pos;
- int limit;
HEAP_VALIDATE();
- 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;
- }
+ size_t limit = VT_int_GetBufferRows(Term) * Term->TextWidth;
+ size_t write_pos = *VT_int_GetWritePosPtr(Term);
+ tVT_Char *buffer = (Term->Flags & VT_FLAG_ALTBUF ? Term->AltBuf : Term->Text);
ASSERTC(write_pos, >=, 0);
}
ASSERTC(write_pos, <=, limit);
- if(Term->Flags & VT_FLAG_ALTBUF)
- {
- Term->AltWritePos = write_pos;
- }
- else
- {
- Term->WritePos = write_pos;
- }
+ *VT_int_GetWritePosPtr(Term) = write_pos;
HEAP_VALIDATE();
void VT_int_ScrollText(tVTerm *Term, int Count)
{
tVT_Char *buf;
- int *write_pos_ptr;
- int height;
int scroll_top, scroll_height;
HEAP_VALIDATE();
// Get buffer pointer and attributes
+ size_t height = VT_int_GetBufferRows(Term);
+ size_t *write_pos_ptr = VT_int_GetWritePosPtr(Term);
+
if( Term->Flags & VT_FLAG_ALTBUF )
{
buf = Term->AltBuf;
- height = Term->TextHeight;
- write_pos_ptr = &Term->AltWritePos;
scroll_top = Term->ScrollTop;
scroll_height = Term->ScrollHeight;
}
else
{
buf = Term->Text;
- height = Term->TextHeight*(giVT_Scrollback+1);
- write_pos_ptr = &Term->WritePos;
scroll_top = 0;
scroll_height = height;
}
{
HEAP_VALIDATE();
- size_t height = Term->TextHeight * (Term->Flags & VT_FLAG_ALTBUF ? 1 : giVT_Scrollback + 1);
+ size_t height = VT_int_GetBufferRows(Term);
tVT_Char *buffer = (Term->Flags & VT_FLAG_ALTBUF ? Term->AltBuf : Term->Text);
ASSERTCR(Row, >=, 0, );
ASSERTCR(Row, <, height, );
{
HEAP_VALIDATE();
- size_t height = Term->TextHeight * (Term->Flags & VT_FLAG_ALTBUF ? 1 : giVT_Scrollback + 1);
+ size_t height = VT_int_GetBufferRows(Term);
tVT_Char *buffer = (Term->Flags & VT_FLAG_ALTBUF ? Term->AltBuf : Term->Text);
ASSERTCR(Row, >=, 0, );
ASSERTCR(Row, <, height, );
VT_int_UpdateScreen(Term, 1);
}
+size_t *VT_int_GetWritePosPtr(tVTerm *Term)
+{
+ return ((Term->Flags & VT_FLAG_ALTBUF) ? &Term->AltWritePos : &Term->WritePos);
+}
+
+size_t VT_int_GetBufferRows(tVTerm *Term)
+{
+ return ((Term->Flags & VT_FLAG_ALTBUF) ? 1 : (giVT_Scrollback+1))*Term->TextHeight;
+}
+
{
LOG("(R%i,C%i)", Row, Col);
VT_int_UpdateScreen(Term, 0);
- int maxrows = ((Term->Flags & VT_FLAG_ALTBUF) ? 1 : (giVT_Scrollback+1))*Term->TextHeight;
+ int maxrows = VT_int_GetBufferRows(Term);
ASSERTCR( Row, >=, 0, );
ASSERTCR( Row, <, maxrows, );
ASSERTCR( Col, >=, 0, );
ASSERTCR( Col, <, Term->TextWidth, );
- *(Term->Flags & VT_FLAG_ALTBUF ? &Term->AltWritePos : &Term->WritePos) = Row*Term->TextWidth + Col;
+ *VT_int_GetWritePosPtr(Term) = Row*Term->TextWidth + Col;
}
void Display_MoveCursor(tTerminal *Term, int RelRow, int RelCol)
{
LOG("(R+%i,C+%i)", RelRow, RelCol);
- int *wrpos = (Term->Flags & VT_FLAG_ALTBUF ? &Term->AltWritePos : &Term->WritePos);
+ size_t *wrpos = VT_int_GetWritePosPtr(Term);
// TODO: Support scrolling if cursor goes offscreen
// if( bScrollIfNeeded )
//
if( RelCol < 0 )
{
- int avail = *wrpos % Term->TextWidth;
- if( RelCol < -avail )
- RelCol = -avail;
+ int max = *wrpos % Term->TextWidth;
+ if( RelCol < -max )
+ RelCol = -max;
}
else
{
- size_t avail = Term->TextWidth - (*wrpos % Term->TextWidth);
- if(RelCol > avail)
- RelCol = avail;
+ size_t max = Term->TextWidth - (*wrpos % Term->TextWidth) - 1;
+ if(RelCol > max)
+ RelCol = max;
}
*wrpos += RelCol;
}
if( RelRow != 0 )
{
int currow = *wrpos / Term->TextWidth;
- int maxrows = ((Term->Flags & VT_FLAG_ALTBUF) ? 1 : (giVT_Scrollback+1))*Term->TextHeight;
+ int maxrows = VT_int_GetBufferRows(Term);
if( RelRow < 0 )
{
if( RelRow < -currow )
}
void Display_SaveCursor(tTerminal *Term)
{
- Term->SavedWritePos = (Term->Flags & VT_FLAG_ALTBUF) ? Term->AltWritePos : Term->WritePos;
+ Term->SavedWritePos = *VT_int_GetWritePosPtr(Term);
LOG("Saved = %i", Term->SavedWritePos);
}
void Display_RestoreCursor(tTerminal *Term)
{
- int max = ((Term->Flags & VT_FLAG_ALTBUF) ? 1 : (giVT_Scrollback+1))*Term->TextHeight * Term->TextWidth;
- int *wrpos = ((Term->Flags & VT_FLAG_ALTBUF) ? &Term->AltWritePos : &Term->WritePos);
- if( Term->SavedWritePos >= max )
- *wrpos = max-1;
- else
- *wrpos = Term->SavedWritePos;
+ size_t max = VT_int_GetBufferRows(Term) * Term->TextWidth;
+ size_t *wrpos = VT_int_GetWritePosPtr(Term);
+ *wrpos = MIN(Term->SavedWritePos, max-1);
LOG("Restored %i", *wrpos);
}
// 0: All, 1: Forward, -1: Reverse
void Display_ClearLine(tTerminal *Term, int Dir)
{
- const int wrpos = (Term->Flags & VT_FLAG_ALTBUF ? Term->AltWritePos : Term->WritePos);
+ const size_t wrpos = *VT_int_GetWritePosPtr(Term);
const int row = wrpos / Term->TextWidth;
const int col = wrpos % Term->TextWidth;
void Display_ClearLines(tTerminal *Term, int Dir)
{
LOG("(Dir=%i)", Dir);
- int *wrpos = (Term->Flags & VT_FLAG_ALTBUF ? &Term->AltWritePos : &Term->WritePos);
- int height = Term->TextHeight * (Term->Flags & VT_FLAG_ALTBUF ? 1 : giVT_Scrollback + 1);
+ size_t *wrpos = VT_int_GetWritePosPtr(Term);
+ size_t height = VT_int_GetBufferRows(Term);
// All
if( Dir == 0 ) {
# include <string.h>
# include <assert.h>
# include <stdlib.h> // malloc/free
+
+static inline int MIN(int a, int b)
+{
+ return a < b ? a : b;
+}
#endif
enum eExcapeMode {
int Term_HandleVT100_Long(tTerminal *Term, int Len, const char *Buf);
int Term_HandleVT100_OSC(tTerminal *Term, int Len, const char *Buf);
-static inline int min(int a, int b)
-{
- return a < b ? a : b;
-}
-
int _locate_eos(size_t Len, const char *Buf)
{
for( size_t ret = 0; ret < Len; ret ++ )
if( st->cache_len > 0 || *Buf == '\x1b' )
{
// Handle VT100 (like) escape sequence
- int new_bytes = min(MAX_VT100_ESCAPE_LEN - st->cache_len, Len);
+ int new_bytes = MIN(MAX_VT100_ESCAPE_LEN - st->cache_len, Len);
int ret = 0;
int old_inc_len = st->cache_len;
switch( *Buf )
{
- // TODO: Need to handle \t and ^A-Z
case '\b':
+ // backspace is aprarently just supposed to cursor left (if possible)
Display_MoveCursor(Term, 0, -1);
- Display_AddText(Term, 1, " ");
- Display_MoveCursor(Term, 0, -1);
+ //Display_AddText(Term, 1, " ");
+ //Display_MoveCursor(Term, 0, -1);
return 1;
case '\t':
// TODO: tab (get current cursor pos, space until multiple of 8)
switch(Buf[2])
{
case 8:
- _SysDebug("TODO \\e#%c - Fill screen with 'E'", Buf[2]);
+ _SysDebug("TODO \\e#%c DECALN - Fill screen with 'E'", Buf[2]);
break;
default:
_SysDebug("Unknown \\e#%c", Buf[2]);
switch( c )
{
case 'A':
- Display_MoveCursor(Term, -(argc >= 1 ? args[0] : 1), 0);
+ Display_MoveCursor(Term, -(args[0] != 0 ? args[0] : 1), 0);
break;
case 'B':
- Display_MoveCursor(Term, (argc >= 1 ? args[0] : 1), 0);
+ Display_MoveCursor(Term, (args[0] != 0 ? args[0] : 1), 0);
break;
case 'C':
- Display_MoveCursor(Term, 0, (argc >= 1 ? args[0] : 1));
+ Display_MoveCursor(Term, 0, (args[0] != 0 ? args[0] : 1));
break;
case 'D':
- Display_MoveCursor(Term, 0, -(argc >= 1 ? args[0] : 1));
+ Display_MoveCursor(Term, 0, -(args[0] != 0 ? args[0] : 1));
break;
case 'H':
if( argc != 2 ) {