use gpui::{App, Global, Hsla};
use theme::Theme;
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct SourceStyle {
pub line_numbers: bool,
pub gutter_min_digits: usize,
pub gutter_gap: f32,
pub gutter_color: Option<Hsla>,
}
impl Default for SourceStyle {
fn default() -> Self {
Self {
line_numbers: true,
gutter_min_digits: 1,
gutter_gap: 1.0,
gutter_color: None,
}
}
}
impl SourceStyle {
pub fn of(cx: &App) -> Self {
cx.try_global::<Installed>()
.map_or_else(Self::default, |installed| (installed.0)(Theme::of(cx)))
}
}
struct Installed(Box<dyn Fn(&Theme) -> SourceStyle>);
impl Global for Installed {}
pub fn set_source_style(cx: &mut App, style: impl Fn(&Theme) -> SourceStyle + 'static) {
cx.set_global(Installed(Box::new(style)));
cx.refresh_windows();
}