Skip to content

Commit ffddee2

Browse files
authored
chore: refactor app layout computations to take them out of the hot loop (#996)
* chore: refactor app layout computations to take them out of the hot loop * chore: use Default for default theme * fix: recursion loop on default theme
1 parent 07b40a3 commit ffddee2

File tree

7 files changed

+910
-175
lines changed

7 files changed

+910
-175
lines changed

src/theme.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
//! Handle the color theme
2-
use std::sync::LazyLock;
3-
42
use ratatui::style::{Color, Modifier, Style};
53

64
use crate::options::SkimOptions;
75

8-
/// Theme defaults to Dark256
9-
pub static DEFAULT_THEME: LazyLock<ColorTheme> = LazyLock::new(ColorTheme::dark256);
10-
116
/// The color scheme of skim's UI
127
///
138
/// <pre>
@@ -19,7 +14,7 @@ pub static DEFAULT_THEME: LazyLock<ColorTheme> = LazyLock::new(ColorTheme::dark2
1914
/// |> query | --> prompt & query
2015
/// +----------------+
2116
/// </pre>
22-
#[derive(Copy, Clone, Debug, Default)]
17+
#[derive(Copy, Clone, Debug)]
2318
pub struct ColorTheme {
2419
/// Non-selected lines and general text
2520
pub normal: Style,
@@ -47,6 +42,13 @@ pub struct ColorTheme {
4742
pub border: Style,
4843
}
4944

45+
impl Default for ColorTheme {
46+
/// Theme defaults to Dark256
47+
fn default() -> Self {
48+
ColorTheme::dark256()
49+
}
50+
}
51+
5052
#[allow(dead_code)]
5153
impl ColorTheme {
5254
/// Setup the theme from the skim options
@@ -64,9 +66,20 @@ impl ColorTheme {
6466
}
6567

6668
fn none() -> Self {
69+
let def = Style::default();
6770
Self {
6871
spinner: Style::default().bold(),
69-
..ColorTheme::default()
72+
normal: def,
73+
matched: def,
74+
current: def,
75+
current_match: def,
76+
query: def,
77+
info: def,
78+
prompt: def,
79+
cursor: def,
80+
selected: def,
81+
header: def,
82+
border: def,
7083
}
7184
}
7285

0 commit comments

Comments
 (0)