Skip to content

Commit 0d1e709

Browse files
author
Stephan Dilly
committed
diff hunk marker returns
revert to old style renames some more style adjustments to the old
1 parent 1c03458 commit 0d1e709

File tree

3 files changed

+32
-31
lines changed

3 files changed

+32
-31
lines changed

src/components/diff.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use strings::commands;
1313
use tui::{
1414
backend::Backend,
1515
layout::{Alignment, Rect},
16-
style::Modifier,
1716
symbols,
1817
widgets::{Block, Borders, Paragraph, Text},
1918
Frame,
@@ -198,7 +197,7 @@ impl DiffComponent {
198197
theme: Theme,
199198
) {
200199
{
201-
let style = theme.text(false, selected || selected_hunk);
200+
let style = theme.diff_hunk_marker(selected_hunk);
202201

203202
if end_of_hunk {
204203
text.push(Text::Styled(
@@ -283,11 +282,7 @@ impl DrawableComponent for DiffComponent {
283282
.title(title.as_str())
284283
.borders(Borders::ALL)
285284
.border_style(self.theme.block(self.focused))
286-
.title_style(
287-
self.theme
288-
.text(self.focused, false)
289-
.modifier(Modifier::BOLD),
290-
),
285+
.title_style(self.theme.title(self.focused)),
291286
)
292287
.alignment(Alignment::Left),
293288
r,

src/ui/mod.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use scrolllist::ScrollableList;
55
use tui::{
66
backend::Backend,
77
layout::{Constraint, Direction, Layout, Rect},
8-
style::Modifier,
98
widgets::{Block, Borders, Text},
109
Frame,
1110
};
@@ -81,18 +80,12 @@ pub fn draw_list<'b, B: Backend, L>(
8180
) where
8281
L: Iterator<Item = Text<'b>>,
8382
{
84-
let style = if selected {
85-
theme.block(selected).modifier(Modifier::BOLD)
86-
} else {
87-
theme.block(selected)
88-
};
89-
9083
let list = ScrollableList::new(items)
9184
.block(
9285
Block::default()
9386
.title(title)
9487
.borders(Borders::ALL)
95-
.title_style(style)
88+
.title_style(theme.title(selected))
9689
.border_style(theme.block(selected)),
9790
)
9891
.scroll(select.unwrap_or_default());

src/ui/style.rs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ pub struct Theme {
1717
#[serde(with = "ColorDef")]
1818
selected_tab: Color,
1919
#[serde(with = "ColorDef")]
20-
command_foreground: Color,
20+
command_fg: Color,
2121
#[serde(with = "ColorDef")]
22-
command_background: Color,
22+
selection_bg: Color,
2323
#[serde(with = "ColorDef")]
24-
command_disabled: Color,
24+
disabled_fg: Color,
2525
#[serde(with = "ColorDef")]
2626
diff_line_add: Color,
2727
#[serde(with = "ColorDef")]
@@ -47,7 +47,15 @@ impl Theme {
4747
if focus {
4848
Style::default()
4949
} else {
50-
Style::default().fg(self.command_disabled)
50+
Style::default().fg(self.disabled_fg)
51+
}
52+
}
53+
54+
pub fn title(&self, focused: bool) -> Style {
55+
if focused {
56+
Style::default().modifier(Modifier::BOLD)
57+
} else {
58+
Style::default().fg(self.disabled_fg)
5159
}
5260
}
5361

@@ -61,11 +69,9 @@ impl Theme {
6169

6270
pub fn text(&self, enabled: bool, selected: bool) -> Style {
6371
match (enabled, selected) {
64-
(false, _) => Style::default().fg(self.command_disabled),
72+
(false, _) => Style::default().fg(self.disabled_fg),
6573
(true, false) => Style::default(),
66-
(true, true) => {
67-
Style::default().bg(self.command_background)
68-
}
74+
(true, true) => Style::default().bg(self.selection_bg),
6975
}
7076
}
7177

@@ -91,12 +97,19 @@ impl Theme {
9197

9298
fn apply_select(&self, style: Style, selected: bool) -> Style {
9399
if selected {
94-
style.bg(self.command_background)
100+
style.bg(self.selection_bg)
95101
} else {
96102
style
97103
}
98104
}
99105

106+
pub fn diff_hunk_marker(&self, selected: bool) -> Style {
107+
match selected {
108+
false => Style::default().fg(self.disabled_fg),
109+
true => Style::default().bg(self.selection_bg),
110+
}
111+
}
112+
100113
pub fn diff_line(
101114
&self,
102115
typ: DiffLineType,
@@ -124,11 +137,11 @@ impl Theme {
124137

125138
pub fn toolbar(&self, enabled: bool) -> Style {
126139
if enabled {
127-
Style::default().fg(self.command_foreground)
140+
Style::default().fg(self.command_fg)
128141
} else {
129-
Style::default().fg(self.command_disabled)
142+
Style::default().fg(self.disabled_fg)
130143
}
131-
.bg(self.command_background)
144+
.bg(self.selection_bg)
132145
}
133146

134147
pub fn commit_hash(&self, selected: bool) -> Style {
@@ -195,15 +208,15 @@ impl Default for Theme {
195208
fn default() -> Self {
196209
Self {
197210
selected_tab: Color::Yellow,
198-
command_foreground: Color::White,
199-
command_background: Color::Rgb(0, 0, 100),
200-
command_disabled: Color::DarkGray,
211+
command_fg: Color::White,
212+
selection_bg: Color::Rgb(0, 0, 100),
213+
disabled_fg: Color::DarkGray,
201214
diff_line_add: Color::Green,
202215
diff_line_delete: Color::Red,
203216
diff_file_added: Color::LightGreen,
204217
diff_file_removed: Color::LightRed,
205218
diff_file_moved: Color::LightMagenta,
206-
diff_file_modified: Color::Yellow,
219+
diff_file_modified: Color::LightYellow,
207220
commit_hash: Color::Magenta,
208221
commit_time: Color::Blue,
209222
commit_author: Color::Green,

0 commit comments

Comments
 (0)