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