par_term_config/config/
theme_methods.rs1use super::config_struct::Config;
9use crate::themes::Theme;
10use crate::types::TabStyle;
11
12impl Config {
13 pub fn apply_tab_style(&mut self) {
18 match self.tabs.tab_style {
19 TabStyle::Dark => {
20 self.tab_colors.tab_bar_background = crate::defaults::tab_bar_background();
22 self.tab_colors.tab_active_background = crate::defaults::tab_active_background();
23 self.tab_colors.tab_inactive_background =
24 crate::defaults::tab_inactive_background();
25 self.tab_colors.tab_hover_background = crate::defaults::tab_hover_background();
26 self.tab_colors.tab_active_text = crate::defaults::tab_active_text();
27 self.tab_colors.tab_inactive_text = crate::defaults::tab_inactive_text();
28 self.tab_colors.tab_active_indicator = crate::defaults::tab_active_indicator();
29 self.tab_colors.tab_border_color = crate::defaults::tab_border_color();
30 self.tab_colors.tab_border_width = crate::defaults::tab_border_width();
31 self.tabs.tab_bar_height = crate::defaults::tab_bar_height();
32 }
33 TabStyle::Light => {
34 self.tab_colors.tab_bar_background = [235, 235, 235];
35 self.tab_colors.tab_active_background = [255, 255, 255];
36 self.tab_colors.tab_inactive_background = [225, 225, 225];
37 self.tab_colors.tab_hover_background = [240, 240, 240];
38 self.tab_colors.tab_active_text = [30, 30, 30];
39 self.tab_colors.tab_inactive_text = [100, 100, 100];
40 self.tab_colors.tab_active_indicator = [50, 120, 220];
41 self.tab_colors.tab_border_color = [200, 200, 200];
42 self.tab_colors.tab_border_width = 1.0;
43 self.tabs.tab_bar_height = crate::defaults::tab_bar_height();
44 }
45 TabStyle::Compact => {
46 self.tab_colors.tab_bar_background = [35, 35, 35];
48 self.tab_colors.tab_active_background = [55, 55, 55];
49 self.tab_colors.tab_inactive_background = [35, 35, 35];
50 self.tab_colors.tab_hover_background = [45, 45, 45];
51 self.tab_colors.tab_active_text = [240, 240, 240];
52 self.tab_colors.tab_inactive_text = [160, 160, 160];
53 self.tab_colors.tab_active_indicator = [80, 140, 240];
54 self.tab_colors.tab_border_color = [60, 60, 60];
55 self.tab_colors.tab_border_width = 0.5;
56 self.tabs.tab_bar_height = 22.0;
57 }
58 TabStyle::Minimal => {
59 self.tab_colors.tab_bar_background = [30, 30, 30];
61 self.tab_colors.tab_active_background = [30, 30, 30];
62 self.tab_colors.tab_inactive_background = [30, 30, 30];
63 self.tab_colors.tab_hover_background = [40, 40, 40];
64 self.tab_colors.tab_active_text = [255, 255, 255];
65 self.tab_colors.tab_inactive_text = [120, 120, 120];
66 self.tab_colors.tab_active_indicator = [100, 150, 255];
67 self.tab_colors.tab_border_color = [30, 30, 30]; self.tab_colors.tab_border_width = 0.0;
69 self.tabs.tab_bar_height = 26.0;
70 }
71 TabStyle::HighContrast => {
72 self.tab_colors.tab_bar_background = [0, 0, 0];
74 self.tab_colors.tab_active_background = [255, 255, 255];
75 self.tab_colors.tab_inactive_background = [30, 30, 30];
76 self.tab_colors.tab_hover_background = [60, 60, 60];
77 self.tab_colors.tab_active_text = [0, 0, 0];
78 self.tab_colors.tab_inactive_text = [255, 255, 255];
79 self.tab_colors.tab_active_indicator = [255, 255, 0];
80 self.tab_colors.tab_border_color = [255, 255, 255];
81 self.tab_colors.tab_border_width = 2.0;
82 self.tabs.tab_bar_height = 30.0;
83 }
84 TabStyle::Automatic => {
85 }
87 }
88 }
89
90 pub fn load_theme(&self) -> Theme {
95 match Theme::by_name(&self.theme_colors.theme) {
96 Some(theme) => theme,
97 None => {
98 log::warn!(
99 "Unknown theme '{}', falling back to the default theme. Available themes: {}",
100 self.theme_colors.theme,
101 Theme::available_themes().join(", ")
102 );
103 Theme::default()
104 }
105 }
106 }
107
108 pub fn apply_system_theme(&mut self, is_dark: bool) -> bool {
111 if !self.theme_colors.auto_dark_mode {
112 return false;
113 }
114 let new_theme = if is_dark {
115 &self.theme_colors.dark_theme
116 } else {
117 &self.theme_colors.light_theme
118 };
119 if self.theme_colors.theme != *new_theme {
120 self.theme_colors.theme = new_theme.clone();
121 true
122 } else {
123 false
124 }
125 }
126
127 pub fn apply_system_tab_style(&mut self, is_dark: bool) -> bool {
130 if self.tabs.tab_style != TabStyle::Automatic {
131 return false;
132 }
133 let target = if is_dark {
134 self.tabs.dark_tab_style
135 } else {
136 self.tabs.light_tab_style
137 };
138 self.tabs.tab_style = target;
140 self.apply_tab_style();
141 self.tabs.tab_style = TabStyle::Automatic;
142 true
143 }
144}