mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 16:37:47 +00:00
LibVT+Everywhere: Introduce 'automarks' and 'clear previous command'
Automarks are similar to bookmarks placed by the terminal, allowing the user to selectively remove a single command and its output from the terminal scrollback. This commit implements a single way to add marks: automatically placing them when the shell becomes interactive. To make sure the shell behaves correctly after its expected prompt position changes, the terminal layer forces a resize event to be passed to the shell on such (possibly) partial clears; this also has the nice side effect of fixing the disappearing prompt on the preexisting "clear including history" action: Fixes #4192.
This commit is contained in:
parent
cde528fdd9
commit
54ab6fe5b9
12 changed files with 238 additions and 0 deletions
|
@ -8,6 +8,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/AnyOf.h>
|
||||
#include <AK/DistinctNumeric.h>
|
||||
#include <AK/Noncopyable.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibVT/Attribute.h>
|
||||
|
@ -16,6 +17,10 @@
|
|||
|
||||
namespace VT {
|
||||
|
||||
AK_TYPEDEF_DISTINCT_ORDERED_ID(u32, Mark);
|
||||
|
||||
inline static constexpr Mark Unmarked = 0;
|
||||
|
||||
class Line {
|
||||
AK_MAKE_NONCOPYABLE(Line);
|
||||
AK_MAKE_NONMOVABLE(Line);
|
||||
|
@ -40,6 +45,7 @@ public:
|
|||
void clear(Attribute const& attribute = Attribute())
|
||||
{
|
||||
m_terminated_at.clear();
|
||||
m_mark = Unmarked;
|
||||
clear_range(0, m_cells.size() - 1, attribute);
|
||||
}
|
||||
void clear_range(size_t first_column, size_t last_column, Attribute const& attribute = Attribute());
|
||||
|
@ -76,6 +82,16 @@ public:
|
|||
bool is_dirty() const { return m_dirty; }
|
||||
void set_dirty(bool b) { m_dirty = b; }
|
||||
|
||||
Optional<Mark> mark() const
|
||||
{
|
||||
return m_mark == Unmarked ? OptionalNone {} : Optional<Mark>(m_mark);
|
||||
}
|
||||
void set_marked(Mark mark)
|
||||
{
|
||||
set_dirty(m_mark != mark);
|
||||
m_mark = mark;
|
||||
}
|
||||
|
||||
Optional<u16> termination_column() const { return m_terminated_at; }
|
||||
void set_terminated(u16 column) { m_terminated_at = column; }
|
||||
|
||||
|
@ -84,6 +100,7 @@ private:
|
|||
void push_cells_into_next_line(size_t new_length, Line* next_line, bool cursor_is_on_next_line, CursorPosition* cursor);
|
||||
|
||||
Vector<Cell> m_cells;
|
||||
Mark m_mark { Unmarked };
|
||||
bool m_dirty { false };
|
||||
// Note: The alignment is 8, so this member lives in the padding (that already existed before it was introduced)
|
||||
[[no_unique_address]] Optional<u16> m_terminated_at;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue