1use gpui::{App, Global, Hsla};
4use theme::Theme;
5
6#[derive(Clone, Copy, Debug, PartialEq)]
7pub struct SourceStyle {
8 pub line_numbers: bool,
9 pub gutter_min_digits: usize,
11 pub gutter_gap: f32,
13 pub gutter_color: Option<Hsla>,
15}
16
17impl Default for SourceStyle {
18 fn default() -> Self {
19 Self {
20 line_numbers: true,
21 gutter_min_digits: 1,
22 gutter_gap: 1.0,
23 gutter_color: None,
24 }
25 }
26}
27
28impl SourceStyle {
29 pub fn of(cx: &App) -> Self {
30 cx.try_global::<Installed>()
31 .map_or_else(Self::default, |installed| (installed.0)(Theme::of(cx)))
32 }
33}
34
35struct Installed(Box<dyn Fn(&Theme) -> SourceStyle>);
36
37impl Global for Installed {}
38
39pub fn set_source_style(cx: &mut App, style: impl Fn(&Theme) -> SourceStyle + 'static) {
41 cx.set_global(Installed(Box::new(style)));
42 cx.refresh_windows();
43}