2021-08-04 01:42:39 +00:00
|
|
|
use anyhow::Result;
|
|
|
|
use gpui::font_cache::{FamilyId, FontCache};
|
|
|
|
use postage::watch;
|
|
|
|
use std::sync::Arc;
|
2021-10-05 09:14:30 +00:00
|
|
|
use theme::{Theme, ThemeRegistry, DEFAULT_THEME_NAME};
|
2021-03-18 19:13:31 +00:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct Settings {
|
|
|
|
pub buffer_font_family: FamilyId,
|
|
|
|
pub buffer_font_size: f32,
|
|
|
|
pub tab_size: usize,
|
2021-05-24 22:38:43 +00:00
|
|
|
pub theme: Arc<Theme>,
|
|
|
|
}
|
|
|
|
|
2021-03-18 19:13:31 +00:00
|
|
|
impl Settings {
|
2021-10-05 09:00:33 +00:00
|
|
|
pub fn new(
|
|
|
|
buffer_font_family: &str,
|
|
|
|
font_cache: &FontCache,
|
|
|
|
theme: Arc<Theme>,
|
|
|
|
) -> Result<Self> {
|
2021-03-18 19:13:31 +00:00
|
|
|
Ok(Self {
|
2021-10-05 09:00:33 +00:00
|
|
|
buffer_font_family: font_cache.load_family(&[buffer_font_family])?,
|
2021-09-04 15:02:20 +00:00
|
|
|
buffer_font_size: 16.,
|
2021-03-18 19:13:31 +00:00
|
|
|
tab_size: 4,
|
2021-07-31 00:22:59 +00:00
|
|
|
theme,
|
2021-03-18 19:13:31 +00:00
|
|
|
})
|
|
|
|
}
|
2021-07-20 20:03:59 +00:00
|
|
|
|
|
|
|
pub fn with_tab_size(mut self, tab_size: usize) -> Self {
|
|
|
|
self.tab_size = tab_size;
|
|
|
|
self
|
|
|
|
}
|
2021-03-18 19:13:31 +00:00
|
|
|
}
|
|
|
|
|
2021-08-26 22:06:00 +00:00
|
|
|
pub fn channel(
|
2021-10-05 09:00:33 +00:00
|
|
|
buffer_font_family: &str,
|
2021-07-31 00:22:59 +00:00
|
|
|
font_cache: &FontCache,
|
|
|
|
themes: &ThemeRegistry,
|
|
|
|
) -> Result<(watch::Sender<Settings>, watch::Receiver<Settings>)> {
|
2021-08-04 21:16:28 +00:00
|
|
|
let theme = match themes.get(DEFAULT_THEME_NAME) {
|
2021-08-04 23:09:15 +00:00
|
|
|
Ok(theme) => theme,
|
2021-08-04 21:07:19 +00:00
|
|
|
Err(err) => {
|
|
|
|
panic!("failed to deserialize default theme: {:?}", err)
|
|
|
|
}
|
|
|
|
};
|
2021-10-05 09:00:33 +00:00
|
|
|
Ok(watch::channel_with(Settings::new(
|
|
|
|
buffer_font_family,
|
|
|
|
font_cache,
|
|
|
|
theme,
|
|
|
|
)?))
|
2021-07-31 00:22:59 +00:00
|
|
|
}
|