1use anyhow::Result;
2use gpui::font_cache::{FamilyId, FontCache};
3use postage::watch;
4use std::sync::Arc;
5use theme::{Theme, ThemeRegistry, DEFAULT_THEME_NAME};
6
7#[derive(Clone)]
8pub struct Settings {
9 pub buffer_font_family: FamilyId,
10 pub buffer_font_size: f32,
11 pub tab_size: usize,
12 pub theme: Arc<Theme>,
13}
14
15impl Settings {
16 pub fn new(
17 buffer_font_family: &str,
18 font_cache: &FontCache,
19 theme: Arc<Theme>,
20 ) -> Result<Self> {
21 Ok(Self {
22 buffer_font_family: font_cache.load_family(&[buffer_font_family])?,
23 buffer_font_size: 16.,
24 tab_size: 4,
25 theme,
26 })
27 }
28
29 pub fn with_tab_size(mut self, tab_size: usize) -> Self {
30 self.tab_size = tab_size;
31 self
32 }
33}
34
35pub fn channel(
36 buffer_font_family: &str,
37 font_cache: &FontCache,
38 themes: &ThemeRegistry,
39) -> Result<(watch::Sender<Settings>, watch::Receiver<Settings>)> {
40 let theme = match themes.get(DEFAULT_THEME_NAME) {
41 Ok(theme) => theme,
42 Err(err) => {
43 panic!("failed to deserialize default theme: {:?}", err)
44 }
45 };
46 Ok(watch::channel_with(Settings::new(
47 buffer_font_family,
48 font_cache,
49 theme,
50 )?))
51}