xref: /DragonOS/kernel/src/driver/video/console/dummycon.rs (revision 2709e017d0d216d61b2caed3c7286459de7794c7)
1 use alloc::sync::Arc;
2 use system_error::SystemError;
3 
4 use crate::driver::tty::{
5     console::ConsoleSwitch,
6     termios::WindowSize,
7     tty_driver::TtyOperation,
8     virtual_terminal::virtual_console::{CursorOperation, ScrollDir, VirtualConsoleData},
9 };
10 
11 lazy_static! {
12     pub static ref DUMMY_CONSOLE: Arc<DummyConsole> = Arc::new(DummyConsole::new());
13 }
14 
15 #[inline]
16 #[allow(dead_code)]
17 pub fn dummy_console() -> Arc<DummyConsole> {
18     DUMMY_CONSOLE.clone()
19 }
20 
21 pub struct DummyConsole;
22 
23 impl DummyConsole {
24     pub const COLUNMS: usize = 80;
25     pub const ROWS: usize = 25;
26     pub const fn new() -> Self {
27         DummyConsole
28     }
29 }
30 
31 impl ConsoleSwitch for DummyConsole {
32     fn con_getxy(
33         &self,
34         _vc_data: &VirtualConsoleData,
35         _pos: usize,
36     ) -> Result<(usize, usize, usize), SystemError> {
37         Ok((0, 0, 0))
38     }
39 
40     fn con_build_attr(
41         &self,
42         _vc_data: &VirtualConsoleData,
43         _color: u8,
44         _intensity: crate::driver::tty::virtual_terminal::virtual_console::VirtualConsoleIntensity,
45         _blink: bool,
46         _underline: bool,
47         _reverse: bool,
48         _italic: bool,
49     ) -> Result<u8, SystemError> {
50         Ok(0)
51     }
52     fn con_init(&self, vc_data: &mut VirtualConsoleData, init: bool) -> Result<(), SystemError> {
53         vc_data.color_mode = true;
54 
55         if init {
56             vc_data.cols = Self::COLUNMS;
57             vc_data.rows = Self::ROWS;
58         } else {
59             let tty = vc_data.port().port_data().tty().unwrap();
60             tty.resize(
61                 tty.clone(),
62                 WindowSize::new(Self::ROWS as u16, Self::COLUNMS as u16, 0, 0),
63             )?;
64         }
65 
66         Ok(())
67     }
68 
69     fn con_deinit(&self) -> Result<(), SystemError> {
70         Ok(())
71     }
72 
73     fn con_clear(
74         &self,
75         _vc_data: &mut VirtualConsoleData,
76         _sy: usize,
77         _sx: usize,
78         _height: usize,
79         _width: usize,
80     ) -> Result<(), SystemError> {
81         Ok(())
82     }
83 
84     fn con_putc(
85         &self,
86         _vc_data: &VirtualConsoleData,
87         _ch: u16,
88         _ypos: u32,
89         _xpos: u32,
90     ) -> Result<(), SystemError> {
91         Ok(())
92     }
93 
94     fn con_putcs(
95         &self,
96         _vc_data: &VirtualConsoleData,
97         _buf: &[u16],
98         _count: usize,
99         _ypos: u32,
100         _xpos: u32,
101     ) -> Result<(), SystemError> {
102         Ok(())
103     }
104 
105     fn con_cursor(&self, _vc_data: &VirtualConsoleData, _op: CursorOperation) {
106         // Do nothing
107     }
108 
109     fn con_set_palette(
110         &self,
111         _vc_data: &VirtualConsoleData,
112         _color_table: &[u8],
113     ) -> Result<(), SystemError> {
114         Ok(())
115     }
116 
117     fn con_scroll(
118         &self,
119         _vc_data: &mut VirtualConsoleData,
120         _top: usize,
121         _bottom: usize,
122         _dir: ScrollDir,
123         _nr: usize,
124     ) -> bool {
125         false
126     }
127 }
128