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