mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:17:35 +00:00
Terminal: Add limited support for 'M' escape sequence (delete line.)
This commit is contained in:
parent
31f44481f3
commit
3944c00f23
2 changed files with 48 additions and 15 deletions
|
@ -337,6 +337,25 @@ void Terminal::escape$J(const Vector<unsigned>& params)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Terminal::escape$M(const Vector<unsigned>& params)
|
||||||
|
{
|
||||||
|
int count = 1;
|
||||||
|
if (params.size() >= 1)
|
||||||
|
count = params[0];
|
||||||
|
|
||||||
|
if (count == 1 && m_cursor_row == 0) {
|
||||||
|
scroll_up();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int max_count = m_rows - m_cursor_row;
|
||||||
|
count = min(count, max_count);
|
||||||
|
|
||||||
|
dbgprintf("Delete %d line(s) starting from %d\n", count, m_cursor_row);
|
||||||
|
// FIXME: Implement.
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
void Terminal::execute_xterm_command()
|
void Terminal::execute_xterm_command()
|
||||||
{
|
{
|
||||||
m_final = '@';
|
m_final = '@';
|
||||||
|
@ -378,6 +397,7 @@ void Terminal::execute_escape_sequence(byte final)
|
||||||
case 'H': escape$H(params); break;
|
case 'H': escape$H(params); break;
|
||||||
case 'J': escape$J(params); break;
|
case 'J': escape$J(params); break;
|
||||||
case 'K': escape$K(params); break;
|
case 'K': escape$K(params); break;
|
||||||
|
case 'M': escape$M(params); break;
|
||||||
case 'm': escape$m(params); break;
|
case 'm': escape$m(params); break;
|
||||||
case 's': escape$s(params); break;
|
case 's': escape$s(params); break;
|
||||||
case 'u': escape$u(params); break;
|
case 'u': escape$u(params); break;
|
||||||
|
@ -390,23 +410,28 @@ void Terminal::execute_escape_sequence(byte final)
|
||||||
m_intermediates.clear();
|
m_intermediates.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Terminal::scroll_up()
|
void Terminal::newline()
|
||||||
{
|
{
|
||||||
word new_row = m_cursor_row;
|
word new_row = m_cursor_row;
|
||||||
if (m_cursor_row == (rows() - 1)) {
|
if (m_cursor_row == (rows() - 1)) {
|
||||||
// NOTE: We have to invalidate the cursor first.
|
scroll_up();
|
||||||
invalidate_cursor();
|
|
||||||
delete m_lines[0];
|
|
||||||
for (word row = 1; row < rows(); ++row)
|
|
||||||
m_lines[row - 1] = m_lines[row];
|
|
||||||
m_lines[m_rows - 1] = new Line(m_columns);
|
|
||||||
++m_rows_to_scroll_backing_store;
|
|
||||||
} else {
|
} else {
|
||||||
++new_row;
|
++new_row;
|
||||||
}
|
}
|
||||||
set_cursor(new_row, 0);
|
set_cursor(new_row, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Terminal::scroll_up()
|
||||||
|
{
|
||||||
|
// NOTE: We have to invalidate the cursor first.
|
||||||
|
invalidate_cursor();
|
||||||
|
delete m_lines[0];
|
||||||
|
for (word row = 1; row < rows(); ++row)
|
||||||
|
m_lines[row - 1] = m_lines[row];
|
||||||
|
m_lines[m_rows - 1] = new Line(m_columns);
|
||||||
|
++m_rows_to_scroll_backing_store;
|
||||||
|
}
|
||||||
|
|
||||||
void Terminal::set_cursor(unsigned a_row, unsigned a_column)
|
void Terminal::set_cursor(unsigned a_row, unsigned a_column)
|
||||||
{
|
{
|
||||||
unsigned row = min(a_row, m_rows - 1u);
|
unsigned row = min(a_row, m_rows - 1u);
|
||||||
|
@ -427,9 +452,12 @@ void Terminal::put_character_at(unsigned row, unsigned column, byte ch)
|
||||||
{
|
{
|
||||||
ASSERT(row < rows());
|
ASSERT(row < rows());
|
||||||
ASSERT(column < columns());
|
ASSERT(column < columns());
|
||||||
line(row).characters[column] = ch;
|
auto& line = this->line(row);
|
||||||
line(row).attributes[column] = m_current_attribute;
|
if ((line.characters[column] == ch) && (line.attributes[column] == m_current_attribute))
|
||||||
line(row).dirty = true;
|
return;
|
||||||
|
line.characters[column] = ch;
|
||||||
|
line.attributes[column] = m_current_attribute;
|
||||||
|
line.dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Terminal::on_char(byte ch)
|
void Terminal::on_char(byte ch)
|
||||||
|
@ -521,7 +549,7 @@ void Terminal::on_char(byte ch)
|
||||||
set_cursor(m_cursor_row, 0);
|
set_cursor(m_cursor_row, 0);
|
||||||
return;
|
return;
|
||||||
case '\n':
|
case '\n':
|
||||||
scroll_up();
|
newline();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,7 +560,7 @@ void Terminal::on_char(byte ch)
|
||||||
} else {
|
} else {
|
||||||
if (m_stomp) {
|
if (m_stomp) {
|
||||||
m_stomp = false;
|
m_stomp = false;
|
||||||
scroll_up();
|
newline();
|
||||||
put_character_at(m_cursor_row, m_cursor_column, ch);
|
put_character_at(m_cursor_row, m_cursor_column, ch);
|
||||||
set_cursor(m_cursor_row, 1);
|
set_cursor(m_cursor_row, 1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -635,8 +663,7 @@ void Terminal::paint()
|
||||||
}
|
}
|
||||||
m_rows_to_scroll_backing_store = 0;
|
m_rows_to_scroll_backing_store = 0;
|
||||||
|
|
||||||
// Always redraw the line with the cursor on it.
|
invalidate_cursor();
|
||||||
line(m_cursor_row).dirty = true;
|
|
||||||
|
|
||||||
for (word row = 0; row < m_rows; ++row) {
|
for (word row = 0; row < m_rows; ++row) {
|
||||||
auto& line = this->line(row);
|
auto& line = this->line(row);
|
||||||
|
|
|
@ -23,6 +23,7 @@ public:
|
||||||
private:
|
private:
|
||||||
Font& font() { return *m_font; }
|
Font& font() { return *m_font; }
|
||||||
void scroll_up();
|
void scroll_up();
|
||||||
|
void newline();
|
||||||
void set_cursor(unsigned row, unsigned column);
|
void set_cursor(unsigned row, unsigned column);
|
||||||
void put_character_at(unsigned row, unsigned column, byte ch);
|
void put_character_at(unsigned row, unsigned column, byte ch);
|
||||||
void invalidate_cursor();
|
void invalidate_cursor();
|
||||||
|
@ -41,6 +42,7 @@ private:
|
||||||
void escape$H(const Vector<unsigned>&);
|
void escape$H(const Vector<unsigned>&);
|
||||||
void escape$J(const Vector<unsigned>&);
|
void escape$J(const Vector<unsigned>&);
|
||||||
void escape$K(const Vector<unsigned>&);
|
void escape$K(const Vector<unsigned>&);
|
||||||
|
void escape$M(const Vector<unsigned>&);
|
||||||
void escape$m(const Vector<unsigned>&);
|
void escape$m(const Vector<unsigned>&);
|
||||||
void escape$s(const Vector<unsigned>&);
|
void escape$s(const Vector<unsigned>&);
|
||||||
void escape$u(const Vector<unsigned>&);
|
void escape$u(const Vector<unsigned>&);
|
||||||
|
@ -64,6 +66,10 @@ private:
|
||||||
unsigned foreground_color : 4;
|
unsigned foreground_color : 4;
|
||||||
unsigned background_color : 4;
|
unsigned background_color : 4;
|
||||||
//bool bold : 1;
|
//bool bold : 1;
|
||||||
|
bool operator==(const Attribute& other) const
|
||||||
|
{
|
||||||
|
return foreground_color == other.foreground_color && background_color == other.background_color;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Line {
|
struct Line {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue