Creates an SDL console host and factory based on the given `spec`.
(
spec: &mut ConsoleSpec<'_>,
signals_tx: Sender<Signal>,
fonts: &Fonts,
)
| 99 | |
| 100 | /// Creates an SDL console host and factory based on the given `spec`. |
| 101 | pub fn setup( |
| 102 | spec: &mut ConsoleSpec<'_>, |
| 103 | signals_tx: Sender<Signal>, |
| 104 | fonts: &Fonts, |
| 105 | ) -> io::Result<(Box<dyn ConsoleHost>, Box<dyn ConsoleFactory>)> { |
| 106 | let resolution: Resolution = spec.take_keyed_flag("resolution")?.unwrap_or_else(|| { |
| 107 | let width = NonZeroU32::new(DEFAULT_RESOLUTION_PIXELS.0).unwrap(); |
| 108 | let height = NonZeroU32::new(DEFAULT_RESOLUTION_PIXELS.1).unwrap(); |
| 109 | Resolution::Windowed((width, height)) |
| 110 | }); |
| 111 | |
| 112 | let default_fg_color = spec.take_keyed_flag::<u8>("fg_color")?; |
| 113 | let default_bg_color = spec.take_keyed_flag::<u8>("bg_color")?; |
| 114 | |
| 115 | let font_name = spec.take_keyed_flag_str("font").unwrap_or(FONT_VGA8X16.name); |
| 116 | let font = fonts.get(font_name)?; |
| 117 | |
| 118 | let (host, factory) = |
| 119 | new_console_pair(resolution, default_fg_color, default_bg_color, font, signals_tx); |
| 120 | Ok((Box::from(host), Box::from(factory))) |
| 121 | } |
no test coverage detected