2018-10-30 13:59:29 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "TTY.h"
|
|
|
|
#include "Keyboard.h"
|
|
|
|
#include "Console.h"
|
|
|
|
|
|
|
|
class VirtualConsole final : public TTY, public KeyboardClient, public ConsoleImplementation {
|
2018-10-31 23:19:15 +01:00
|
|
|
AK_MAKE_ETERNAL
|
2018-10-30 13:59:29 +01:00
|
|
|
public:
|
|
|
|
enum InitialContents { Cleared, AdoptCurrentVGABuffer };
|
|
|
|
|
|
|
|
VirtualConsole(unsigned index, InitialContents = Cleared);
|
|
|
|
virtual ~VirtualConsole() override;
|
|
|
|
|
2018-11-01 14:09:21 +01:00
|
|
|
static void switch_to(unsigned);
|
2018-10-30 13:59:29 +01:00
|
|
|
static void initialize();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// ^KeyboardClient
|
2019-01-21 07:05:31 +01:00
|
|
|
virtual void on_key_pressed(Keyboard::Event) override;
|
2018-10-30 13:59:29 +01:00
|
|
|
|
|
|
|
// ^ConsoleImplementation
|
2018-12-03 00:39:25 +01:00
|
|
|
virtual void on_sysconsole_receive(byte) override;
|
2018-10-30 13:59:29 +01:00
|
|
|
|
2018-10-30 15:33:37 +01:00
|
|
|
// ^TTY
|
2019-02-05 13:09:01 +01:00
|
|
|
virtual ssize_t on_tty_write(const byte*, size_t) override;
|
2018-12-03 00:39:25 +01:00
|
|
|
virtual String tty_name() const override;
|
2018-10-30 15:33:37 +01:00
|
|
|
|
2019-01-21 02:33:01 +01:00
|
|
|
// ^CharacterDevice
|
|
|
|
virtual const char* class_name() const override { return "VirtualConsole"; }
|
|
|
|
|
2018-11-01 14:09:21 +01:00
|
|
|
void set_active(bool);
|
2018-11-16 20:18:58 +01:00
|
|
|
void on_char(byte);
|
2018-10-30 13:59:29 +01:00
|
|
|
|
2018-11-10 16:25:59 +01:00
|
|
|
void get_vga_cursor(byte& row, byte& column);
|
|
|
|
void flush_vga_cursor();
|
|
|
|
|
2018-10-30 13:59:29 +01:00
|
|
|
byte* m_buffer;
|
|
|
|
unsigned m_index;
|
|
|
|
bool m_active { false };
|
|
|
|
|
2018-11-01 14:09:21 +01:00
|
|
|
void scroll_up();
|
|
|
|
void set_cursor(unsigned row, unsigned column);
|
|
|
|
void put_character_at(unsigned row, unsigned column, byte ch);
|
2018-10-30 15:33:37 +01:00
|
|
|
|
2018-11-11 15:36:40 +01:00
|
|
|
void escape$A(const Vector<unsigned>&);
|
2018-12-07 01:19:02 +01:00
|
|
|
void escape$D(const Vector<unsigned>&);
|
2018-10-30 13:59:29 +01:00
|
|
|
void escape$H(const Vector<unsigned>&);
|
|
|
|
void escape$J(const Vector<unsigned>&);
|
|
|
|
void escape$m(const Vector<unsigned>&);
|
|
|
|
void escape$s(const Vector<unsigned>&);
|
|
|
|
void escape$u(const Vector<unsigned>&);
|
|
|
|
|
2018-11-10 00:56:10 +01:00
|
|
|
void clear();
|
|
|
|
|
2018-11-01 14:09:21 +01:00
|
|
|
byte m_cursor_row { 0 };
|
|
|
|
byte m_cursor_column { 0 };
|
|
|
|
byte m_saved_cursor_row { 0 };
|
|
|
|
byte m_saved_cursor_column { 0 };
|
|
|
|
byte m_current_attribute { 0x07 };
|
2018-10-30 13:59:29 +01:00
|
|
|
|
2018-11-09 21:18:03 +01:00
|
|
|
void clear_vga_row(word row);
|
|
|
|
void set_vga_start_row(word row);
|
|
|
|
word m_vga_start_row { 0 };
|
|
|
|
word m_current_vga_start_address { 0 };
|
|
|
|
byte* m_current_vga_window { nullptr };
|
|
|
|
|
2018-11-01 14:09:21 +01:00
|
|
|
void execute_escape_sequence(byte final);
|
2018-10-30 13:59:29 +01:00
|
|
|
|
|
|
|
enum EscapeState {
|
|
|
|
Normal,
|
|
|
|
ExpectBracket,
|
|
|
|
ExpectParameter,
|
|
|
|
ExpectIntermediate,
|
|
|
|
ExpectFinal,
|
|
|
|
};
|
2018-11-01 14:09:21 +01:00
|
|
|
EscapeState m_escape_state { Normal };
|
2018-10-30 13:59:29 +01:00
|
|
|
Vector<byte> m_parameters;
|
|
|
|
Vector<byte> m_intermediates;
|
2018-12-07 00:17:23 +01:00
|
|
|
byte* m_horizontal_tabs { nullptr };
|
2018-10-30 13:59:29 +01:00
|
|
|
};
|