mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:07:34 +00:00
Terminal: Track which character cells have had something printed in them.
This helps us figure out where lines end, which we need when computing the selected text for copy-to-clipboard. :^)
This commit is contained in:
parent
33ac0de988
commit
438a14c597
2 changed files with 15 additions and 2 deletions
|
@ -751,6 +751,7 @@ void Terminal::put_character_at(unsigned row, unsigned column, byte ch)
|
||||||
auto& line = this->line(row);
|
auto& line = this->line(row);
|
||||||
line.characters[column] = ch;
|
line.characters[column] = ch;
|
||||||
line.attributes[column] = m_current_attribute;
|
line.attributes[column] = m_current_attribute;
|
||||||
|
line.attributes[column].flags |= Attribute::Touched;
|
||||||
line.dirty = true;
|
line.dirty = true;
|
||||||
|
|
||||||
m_last_char = ch;
|
m_last_char = ch;
|
||||||
|
@ -1266,8 +1267,17 @@ String Terminal::selected_text() const
|
||||||
for (int row = start.row(); row <= end.row(); ++row) {
|
for (int row = start.row(); row <= end.row(); ++row) {
|
||||||
int first_column = row == start.row() ? start.column() : 0;
|
int first_column = row == start.row() ? start.column() : 0;
|
||||||
int last_column = row == end.row() ? end.column() : m_columns - 1;
|
int last_column = row == end.row() ? end.column() : m_columns - 1;
|
||||||
for (int column = first_column; column <= last_column; ++column)
|
for (int column = first_column; column <= last_column; ++column) {
|
||||||
builder.append(line(row).characters[column]);
|
auto& line = this->line(row);
|
||||||
|
if (line.attributes[column].is_untouched()) {
|
||||||
|
builder.append('\n');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
builder.append(line.characters[column]);
|
||||||
|
if (column == line.m_length - 1) {
|
||||||
|
builder.append('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.to_string();
|
return builder.to_string();
|
||||||
|
|
|
@ -160,8 +160,11 @@ private:
|
||||||
Underline = 0x04,
|
Underline = 0x04,
|
||||||
Negative = 0x08,
|
Negative = 0x08,
|
||||||
Blink = 0x10,
|
Blink = 0x10,
|
||||||
|
Touched = 0x20,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool is_untouched() const { return !(flags & Touched); }
|
||||||
|
|
||||||
// TODO: it would be really nice if we had a helper for enums that
|
// TODO: it would be really nice if we had a helper for enums that
|
||||||
// exposed bit ops for class enums...
|
// exposed bit ops for class enums...
|
||||||
int flags = Flags::NoAttributes;
|
int flags = Flags::NoAttributes;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue