Support \e[6n for reporting cursor position.

This commit is contained in:
Jonas 'Sortie' Termansen 2023-02-26 01:10:25 +01:00
parent 6b0ddb4615
commit 18cb2651be
2 changed files with 29 additions and 1 deletions

View File

@ -116,6 +116,7 @@ LogTerminal::LogTerminal(dev_t dev, mode_t mode, uid_t owner, gid_t group,
this->keyboard = keyboard;
this->kblayout = kblayout;
this->modifiers = 0;
this->report_cursor_offset = 0;
keyboard->SetOwner(this, NULL);
}
@ -127,7 +128,33 @@ LogTerminal::~LogTerminal()
void LogTerminal::tty_output(const unsigned char* buffer, size_t length)
{
Log::PrintData(buffer, length);
const char* report_cursor = "\e[6n";
while ( length )
{
size_t amount = 0;
bool found_report_cursor = false;
while ( !found_report_cursor && amount < length )
{
if ( buffer[amount++] == report_cursor[report_cursor_offset++] )
found_report_cursor = !report_cursor[report_cursor_offset];
else
report_cursor_offset = 0;
}
Log::PrintData(buffer, amount);
buffer += amount;
length -= amount;
if ( found_report_cursor )
{
size_t column, row;
Log::GetCursor(&column, &row);
char buf[64];
snprintf(buf, sizeof(buf), "\e[%zu;%zuR", row + 1, column + 1);
for ( size_t n = 0; buf[n]; n++ )
if ( !linebuffer.Push(buf[n]) )
break;
CommitLineBuffer();
}
}
}
int LogTerminal::sync(ioctx_t* /*ctx*/)

View File

@ -52,6 +52,7 @@ private:
Keyboard* keyboard;
KeyboardLayoutExecutor* kblayout;
int modifiers;
size_t report_cursor_offset;
};