1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Noncopyable.h>
#include <AK/NonnullOwnPtrVector.h>
#include <AK/Vector.h>
#include <Kernel/API/KeyCode.h>
#include <Kernel/Devices/ConsoleDevice.h>
#include <Kernel/Devices/HID/HIDManagement.h>
#include <Kernel/Graphics/Console/Console.h>
#include <Kernel/TTY/TTY.h>
#include <LibVT/Attribute.h>
#include <LibVT/Color.h>
#include <LibVT/Position.h>
#include <LibVT/Terminal.h>
namespace Kernel {
class ConsoleManagement;
class VirtualConsole;
// FIXME: This implementation has no knowledge about keeping terminal history...
class ConsoleImpl final : public VT::Terminal {
public:
explicit ConsoleImpl(VirtualConsole&);
virtual void set_size(u16 columns, u16 rows) override;
private:
virtual void invalidate_cursor() override;
virtual void clear() override;
virtual void clear_history() override;
virtual void scroll_up(u16 region_top, u16 region_bottom, size_t count) override;
virtual void scroll_down(u16 region_top, u16 region_bottom, size_t count) override;
virtual void scroll_left(u16 row, u16 column, size_t count) override;
virtual void scroll_right(u16 row, u16 column, size_t count) override;
virtual void put_character_at(unsigned row, unsigned column, u32 ch) override;
virtual void clear_in_line(u16 row, u16 first_column, u16 last_column) override;
};
class VirtualConsole final : public TTY
, public KeyboardClient
, public VT::TerminalClient {
friend class ConsoleManagement;
friend class DeviceManagement;
friend class ConsoleImpl;
friend class VT::Terminal;
public:
struct Line {
bool dirty;
size_t length;
};
struct Cell {
void clear()
{
ch = ' ';
attribute.reset();
}
char ch;
VT::Attribute attribute;
};
public:
static NonnullLockRefPtr<VirtualConsole> create(size_t index);
static NonnullLockRefPtr<VirtualConsole> create_with_preset_log(size_t index, CircularQueue<char, 16384> const&);
virtual ~VirtualConsole() override;
size_t index() const { return m_index; }
void refresh_after_resolution_change();
// ^TTY
virtual bool is_graphical() const override { return m_graphical; }
virtual void set_graphical(bool graphical) override;
void emit_char(char);
private:
explicit VirtualConsole(unsigned const index);
// ^KeyboardClient
virtual void on_key_pressed(KeyEvent) override;
// ^TTY
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_name() const override;
virtual ErrorOr<size_t> on_tty_write(UserOrKernelBuffer const&, size_t) override;
virtual void echo(u8) override;
// ^TerminalClient
virtual void beep() override;
virtual void set_window_title(StringView) override;
virtual void set_window_progress(int, int) override;
virtual void terminal_did_resize(u16 columns, u16 rows) override;
virtual void terminal_history_changed(int) override;
virtual void emit(u8 const*, size_t) override;
virtual void set_cursor_shape(VT::CursorShape) override;
virtual void set_cursor_blinking(bool) override;
// ^CharacterDevice
virtual StringView class_name() const override { return "VirtualConsole"sv; }
void set_active(bool);
void flush_dirty_lines();
unsigned m_index;
bool m_active { false };
bool m_graphical { false };
private:
void initialize();
void invalidate_cursor(size_t row);
void clear();
Cell& cell_at(size_t column, size_t row);
using ParamVector = Vector<unsigned, 4>;
void scroll_down(u16 region_top, u16 region_bottom, size_t count);
void scroll_up(u16 region_top, u16 region_bottom, size_t count);
void scroll_left(u16 row, u16 column, size_t count);
void scroll_right(u16 row, u16 column, size_t count);
void clear_line(size_t index)
{
clear_in_line(index, 0, m_console_impl.columns() - 1);
}
void clear_in_line(u16 row, u16 first_column, u16 last_column);
void put_character_at(unsigned row, unsigned column, u32 ch, const VT::Attribute&);
OwnPtr<Memory::Region> m_cells;
Vector<VirtualConsole::Line> m_lines;
ConsoleImpl m_console_impl;
};
}
|