limine_protocol/responses/
terminal.rs

1use crate::structures::terminal::{Terminal, TerminalWriteFn};
2
3#[repr(C)]
4#[derive(Debug)]
5/// Response to [`TerminalRequest`]
6pub struct TerminalResponse {
7    /// The response revision number
8    pub revision: u64,
9    /// The number of [Terminal]s in `terminals`
10    pub terminal_count: u64,
11    /// A pointer to an array of [Terminal] pointers
12    pub terminals: *const *const Terminal,
13    /// The terminal write function
14    ///
15    /// # Important
16    /// It must be noted that this is the physical address of the write function
17    pub write: TerminalWriteFn,
18}
19
20impl TerminalResponse {
21    /// Get the terminal slice
22    ///
23    /// # Safety
24    /// The pointer must point to a valid array of [Terminal]s
25    #[must_use]
26    pub unsafe fn get_terminals(&self) -> Option<&[&Terminal]> {
27        if self.terminals.is_null() {
28            return None;
29        }
30        Some(core::slice::from_raw_parts(
31            self.terminals.cast::<&Terminal>(),
32            self.terminal_count.try_into().ok()?,
33        ))
34    }
35
36    /// Get the terminal slice
37    ///
38    /// # Safety
39    /// The pointer must point to a valid array of [Terminal]s.
40    /// Additionally, you must ensure that this is called *nowhere* else, otherwise
41    /// very, very bad things may occur due to read and write tearing
42    #[must_use]
43    pub unsafe fn get_terminals_mut(&self) -> Option<&mut [&mut Terminal]> {
44        if self.terminals.is_null() {
45            return None;
46        }
47        Some(core::slice::from_raw_parts_mut(
48            self.terminals as *mut &mut Terminal,
49            self.terminal_count.try_into().ok()?,
50        ))
51    }
52}