syntect/highlighting/
theme.rs

1// Code based on https://github.com/defuz/sublimate/blob/master/src/core/syntax/theme.rs
2// released under the MIT license by @defuz
3use super::style::*;
4use super::selector::*;
5use serde_derive::{Deserialize, Serialize};
6
7/// A theme parsed from a `.tmTheme` file.
8///
9/// This contains additional fields useful for a theme list as well as `settings` for styling your editor.
10#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
11pub struct Theme {
12    pub name: Option<String>,
13    pub author: Option<String>,
14    /// External settings for the editor using this theme
15    pub settings: ThemeSettings,
16    /// The styling rules for the viewed text
17    pub scopes: Vec<ThemeItem>,
18}
19
20/// Properties for styling the UI of a text editor
21///
22/// This essentially consists of the styles that aren't directly applied to the text being viewed.
23/// `ThemeSettings` are intended to be used to make the UI of the editor match the styling of the
24/// text itself.
25#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
26pub struct ThemeSettings {
27    /// The default color for text.
28    pub foreground: Option<Color>,
29    /// The default backgound color of the view.
30    pub background: Option<Color>,
31    /// Color of the caret.
32    pub caret: Option<Color>,
33    /// Color of the line the caret is in.
34    /// Only used when the `highlight_line` setting is set to `true`.
35    pub line_highlight: Option<Color>,
36
37    /// The color to use for the squiggly underline drawn under misspelled words.
38    pub misspelling: Option<Color>,
39    /// The color of the border drawn around the viewport area of the minimap.
40    /// Only used when the `draw_minimap_border` setting is enabled.
41    pub minimap_border: Option<Color>,
42    /// A color made available for use by the theme.
43    pub accent: Option<Color>,
44    /// CSS passed to popups.
45    pub popup_css: Option<String>,
46    /// CSS passed to phantoms.
47    pub phantom_css: Option<String>,
48
49    /// Color of bracketed sections of text when the caret is in a bracketed section.
50    /// Only applied when the `match_brackets` setting is set to `true`.
51    pub bracket_contents_foreground: Option<Color>,
52    /// Controls certain options when the caret is in a bracket section.
53    /// Only applied when the `match_brackets` setting is set to `true`.
54    pub bracket_contents_options: Option<UnderlineOption>,
55    /// Foreground color of the brackets when the caret is next to a bracket.
56    /// Only applied when the `match_brackets` setting is set to `true`.
57    pub brackets_foreground: Option<Color>,
58    /// Background color of the brackets when the caret is next to a bracket.
59    /// Only applied when the `match_brackets` setting is set to `true`.
60    pub brackets_background: Option<Color>,
61    /// Controls certain options when the caret is next to a bracket.
62    /// Only applied when the `match_brackets` setting is set to `true`.
63    pub brackets_options: Option<UnderlineOption>,
64
65    /// Color of tags when the caret is next to a tag.
66    /// Only used when the `match_tags` setting is set to `true`.
67    pub tags_foreground: Option<Color>,
68    /// Controls certain options when the caret is next to a tag.
69    /// Only applied when the `match_tags` setting is set to `true`.
70    pub tags_options: Option<UnderlineOption>,
71
72    /// The border color for "other" matches.
73    pub highlight: Option<Color>,
74    /// Background color of regions matching the current search.
75    pub find_highlight: Option<Color>,
76    /// Text color of regions matching the current search.
77    pub find_highlight_foreground: Option<Color>,
78
79    /// Background color of the gutter.
80    pub gutter: Option<Color>,
81    /// Foreground color of the gutter.
82    pub gutter_foreground: Option<Color>,
83
84    /// The background color of selected text.
85    pub selection: Option<Color>,
86    /// A color that will override the scope-based text color of the selection.
87    pub selection_foreground: Option<Color>,
88
89    /// Color of the selection regions border.
90    pub selection_border: Option<Color>,
91    /// The background color of a selection in a view that is not currently focused.
92    pub inactive_selection: Option<Color>,
93    /// A color that will override the scope-based text color of the selection
94    /// in a view that is not currently focused.
95    pub inactive_selection_foreground: Option<Color>,
96
97    /// Color of the guides displayed to indicate nesting levels.
98    pub guide: Option<Color>,
99    /// Color of the guide lined up with the caret.
100    /// Only applied if the `indent_guide_options` setting is set to `draw_active`.
101    pub active_guide: Option<Color>,
102    /// Color of the current guide’s parent guide level.
103    /// Only used if the `indent_guide_options` setting is set to `draw_active`.
104    pub stack_guide: Option<Color>,
105
106    /// The color of the shadow used when a text area can be horizontally scrolled.
107    pub shadow: Option<Color>,
108}
109
110/// A component of a theme meant to highlight a specific thing (e.g string literals)
111/// in a certain way.
112#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
113pub struct ThemeItem {
114    /// Target scope name.
115    pub scope: ScopeSelectors,
116    /// The style to use for this component
117    pub style: StyleModifier,
118}
119
120#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
121pub enum UnderlineOption {
122    #[default]
123    None,
124    Underline,
125    StippledUnderline,
126    SquigglyUnderline,
127}