summaryrefslogtreecommitdiff
path: root/Kernel/Console.h
blob: b10882d2f1214a2642fd29ae6881e86e855a9c6f (plain)
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
#pragma once

#include <AK/Compiler.h>
#include <AK/Vector.h>
#include <VirtualFileSystem/CharacterDevice.h>

class Console final : public CharacterDevice {
public:
    static Console& the() PURE;

    Console();
    virtual ~Console() override;

    virtual bool hasDataAvailableForRead() const override;
    virtual ssize_t read(byte* buffer, size_t size) override;
    virtual ssize_t write(const byte* data, size_t size) override;

    void putChar(char);

private:
    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>&);

    const byte m_rows { 25 };
    const byte m_columns { 80 };

    byte m_cursorRow { 0 };
    byte m_cursorColumn { 0 };

    byte m_savedCursorRow { 0 };
    byte m_savedCursorColumn { 0 };

    byte m_currentAttribute { 0x07 };

    void executeEscapeSequence(byte final);

    enum EscapeState {
        Normal,
        ExpectBracket,
        ExpectParameter,
        ExpectIntermediate,
        ExpectFinal,
    };
    EscapeState m_escState { Normal };
    Vector<byte> m_parameters;
    Vector<byte> m_intermediates;
};