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
use super::framebuffer::Framebuffer;

/// Type for terminal `Write` function
/// In order for the terminal to remain functioning, the GDT must at least have the default values
///
/// Special length values do the following things
/// * `TerminalSize` - `-1`
///     * This will **write** a single u64 to the pointer
/// * `TerminalSave` - `-2`
///     * This will save the terminal context to the pointer, of allocation size `TerminalSize`
/// * `TerminalRestore` - `-3`
///     * This will restore the terminal context from the pointer, of allocation size `TerminalSize`
/// * `TerminalFullRefresh` - `-4`
///     * This will fully repaint the framebuffer, the pointer is unused
pub type TerminalWriteFn = extern "C" fn(*mut Terminal, *const u8, u64);

/// Type for terminal callback
/// The first argument is `Type`, which corresponds to `CallbackType`[`CallbackType`]
/// * `DecSequence`
///     * `ValueCount` - Number of values in the array `Values`
///     * `Values` - Array of values in the DEC Sequence
///     * `Final` - The final character in the DEC Sequence
/// * `Bell`
///     * `unused1`
///     * `unused2`
///     * `unused3`
/// * `DECPrivateID`
///     * `unused1`
///     * `unused2`
///     * `unused3`
/// * `StatusReport`
///     * `unused1`
///     * `unused2`
///     * `unused3`
/// * `CursorPositionReport`
///     * `X` - The X position at the time the report was requested
///     * `Y` - The Y position at the time the report was requested
///     * `unused3`
/// * `KeyboardLEDUpdate`
///     * `LedState` - What to set (possible values below)
///         * `0` - Clear all LEDs
///         * `1` - Set Scroll Lock
///         * `2` - Set Num Lock
///         * `3` - Set Caps Lock LED
///     * `unused2`
///     * `unused3`
/// * `SwitchSequence`
///     * `ValueCount` - Number of values in the array `Values`
///     * `Values` - Array of values in the Switch Sequence
///     * `Final` - The final character in the Switch Sequence
/// * `LinuxEscapeSequence`
///     * `ValueCount` - Number of values in the array `Values`
///     * `Values` - Array of values in the Sequence
pub type TerminalCallback = extern "C" fn(*mut Terminal, u64, u64, u64, u64);

#[repr(u64)]
#[derive(Debug, PartialEq, Eq)]
/// Types of terminal callbacks
pub enum CallbackType {
    /// A DEC Private Mode Sequence has been encountered
    DECSequence = 10,
    /// A bell event has occurred
    Bell = 20,
    /// The kernel must respond to a DEC Private ID request
    DECPrivateID = 30,
    /// The kernel must respond to an ECMA-48 status report request
    StatusReport = 40,
    /// The kernel must respond to an ECMA-48 cursor position report request
    CursorPositionReport = 50,
    /// The kernel must respond to a keyboard LED change request
    KeyboardLEDUpdate = 60,
    /// An ECMA-48 Switch sequence has been encountered that the terminal cannot handle alone
    SwitchSequence = 70,
    /// A private Linux escape sequence has been encountered that the terminal cannot handle alone
    LinuxEscapeSequence = 80,
}

#[repr(C)]
#[derive(Debug, PartialEq, Eq)]
/// Terminal structure
pub struct Terminal {
    /// How many columns are in the terminal
    pub columns: u32,
    /// How many rows are in the terminal
    pub rows: u32,
    /// The terminal's framebuffer
    pub framebuffer: *mut Framebuffer,
}