on master help sign in
fix: Merge default palette with user palette
commite4e93e176ceca39a834abf7e67bf9bfaa34d886d authorGokul Soumya <gokulps15@gmail.com> dateFri 3 Sep 2021, 16:42 (5 years ago) parente40e6db
2 files changed+29−20
book/src/themes.md+3−1 helix-view/src/theme.rs+26−19
book/src/themes.md+3−1
@@ -124,7 +124,9 @@ black = "#000000"
124124Remember that the `[palette]` table includes all keys after its header,
125125so you should define the palette after normal theme options.
126126
127−If there is no `[palette]` section, a default palette which uses the terminal's default 16 colors are used:
127+The default palette uses the terminal's default 16 colors, and the colors names
128+are listed below. The `[palette]` section in the config file takes precedence
129+over it and is merged into the default palette.
128130
129131| Color Name |
130132| --- |
helix-view/src/theme.rs+26−19
@@ -143,30 +143,37 @@ struct ThemePalette {
143143
144144impl Default for ThemePalette {
145145 fn default() -> Self {
146− Self::new(hashmap! {
147− "black".to_string() => Color::Black,
148− "red".to_string() => Color::Red,
149− "green".to_string() => Color::Green,
150− "yellow".to_string() => Color::Yellow,
151− "blue".to_string() => Color::Blue,
152− "magenta".to_string() => Color::Magenta,
153− "cyan".to_string() => Color::Cyan,
154− "gray".to_string() => Color::Gray,
155− "light-red".to_string() => Color::LightRed,
156− "light-green".to_string() => Color::LightGreen,
157− "light-yellow".to_string() => Color::LightYellow,
158− "light-blue".to_string() => Color::LightBlue,
159− "light-magenta".to_string() => Color::LightMagenta,
160− "light-cyan".to_string() => Color::LightCyan,
161− "light-gray".to_string() => Color::LightGray,
162− "white".to_string() => Color::White,
163− })
146+ Self {
147+ palette: hashmap! {
148+ "black".to_string() => Color::Black,
149+ "red".to_string() => Color::Red,
150+ "green".to_string() => Color::Green,
151+ "yellow".to_string() => Color::Yellow,
152+ "blue".to_string() => Color::Blue,
153+ "magenta".to_string() => Color::Magenta,
154+ "cyan".to_string() => Color::Cyan,
155+ "gray".to_string() => Color::Gray,
156+ "light-red".to_string() => Color::LightRed,
157+ "light-green".to_string() => Color::LightGreen,
158+ "light-yellow".to_string() => Color::LightYellow,
159+ "light-blue".to_string() => Color::LightBlue,
160+ "light-magenta".to_string() => Color::LightMagenta,
161+ "light-cyan".to_string() => Color::LightCyan,
162+ "light-gray".to_string() => Color::LightGray,
163+ "white".to_string() => Color::White,
164+ },
165+ }
164166 }
165167}
166168
167169impl ThemePalette {
168170 pub fn new(palette: HashMap<String, Color>) -> Self {
169− Self { palette }
171+ let ThemePalette {
172+ palette: mut default,
173+ } = ThemePalette::default();
174+
175+ default.extend(palette);
176+ Self { palette: default }
170177 }
171178
172179 pub fn hex_string_to_rgb(s: &str) -> Result<Color, String> {