Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/ui/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ use crate::config::Settings;
/// - "dracula" - Dracula theme
pub fn get_theme() -> Theme {
let settings = Settings::get();
if !console::colors_enabled_stderr() {
return no_color_theme();
}
match settings.color_theme.to_lowercase().as_str() {
"base16" => Theme::base16(),
"catppuccin" => Theme::catppuccin(),
Expand All @@ -22,3 +25,46 @@ pub fn get_theme() -> Theme {
}
}
}

fn no_color_theme() -> Theme {
let mut theme = Theme::new();
theme.input_placeholder = Default::default();
theme.focused_button = Default::default();
theme.blurred_button = Default::default();
theme.cursor_style = Default::default();
theme.force_style = false;
theme.breadcrumb_active = Default::default();
theme.breadcrumb_clickable = Default::default();
theme.breadcrumb_future = Default::default();
theme
}
Comment thread
risu729 marked this conversation as resolved.

#[cfg(test)]
mod tests {
use confique::Layer;

use crate::config::Settings;
use crate::config::settings::SettingsPartial;

use super::*;

#[test]
fn get_theme_returns_no_color_theme_when_color_is_disabled() {
let mut partial = SettingsPartial::empty();
partial.color = Some(false);
partial.color_theme = Some("base16".to_string());
Settings::reset(Some(partial));
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Outdated

let theme = get_theme();
let cursor_color = theme.real_cursor_color(None);

assert!(theme.title.fg().is_none());
assert!(theme.description.fg().is_none());
assert!(theme.selected_option.fg().is_none());
assert!(theme.unselected_option.fg().is_none());
assert!(cursor_color.fg().is_none());
assert!(cursor_color.bg().is_none());
Comment thread
risu729 marked this conversation as resolved.
Outdated

Settings::reset(None);
}
Comment thread
greptile-apps[bot] marked this conversation as resolved.
}
Loading