Skip to content

Commit 4ec1a4e

Browse files
author
Mehran Kordi
authored
Implement color themes #65 (closes #28)
1 parent e73cdb6 commit 4ec1a4e

File tree

18 files changed

+470
-231
lines changed

18 files changed

+470
-231
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- support for color themes and light mode([#28](https://github.com/extrawurst/gitui/issues/28))
810

911
## [0.2.6] - 2020-05-18
1012
### Fixed

Cargo.lock

Lines changed: 49 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ scopeguard = "1.1"
3131
bitflags = "1.2"
3232
chrono = "0.4"
3333
backtrace = { version = "0.3" }
34+
ron = "0.5.1"
3435
scopetime = { path = "./scopetime", version = "0.1" }
3536
asyncgit = { path = "./asyncgit", version = "0.2" }
37+
serde = "1.0.110"
3638

3739
[features]
3840
default=[]
@@ -45,6 +47,6 @@ members=[
4547
]
4648

4749
[profile.release]
48-
lto = true
50+
lto = true
4951
opt-level = 'z' # Optimize for size.
5052
codegen-units = 1

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ this will log to:
8080
* `$XDG_CACHE_HOME/gitui/gitui.log` (linux using `XDG`)
8181
* `$HOME/.cache/gitui/gitui.log` (linux)
8282

83+
# color theme
84+
85+
to change the colors of the program you have to modify `theme.ron` file
86+
[Ron format](https://github.com/ron-rs/ron) located at config path (same as log paths). the list of valid
87+
colors can be found in [ColorDef](./src/ui/style.rs#ColorDef) struct. note that rgb colors might not be available
88+
on some platforms.
89+
8390
# inspiration
8491

8592
* https://github.com/jesseduffield/lazygit

src/app.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::ui::style::Theme;
12
use crate::{
23
accessors,
34
components::{
@@ -17,10 +18,11 @@ use itertools::Itertools;
1718
use log::trace;
1819
use std::borrow::Cow;
1920
use strings::commands;
21+
use tui::style::Style;
2022
use tui::{
2123
backend::Backend,
2224
layout::{Alignment, Constraint, Direction, Layout, Rect},
23-
style::{Color, Modifier, Style},
25+
style::Modifier,
2426
widgets::{Block, Borders, Paragraph, Tabs, Text},
2527
Frame,
2628
};
@@ -37,24 +39,29 @@ pub struct App {
3739
revlog: Revlog,
3840
status_tab: Status,
3941
queue: Queue,
42+
theme: Theme,
4043
}
4144

4245
// public interface
4346
impl App {
4447
///
4548
pub fn new(sender: &Sender<AsyncNotification>) -> Self {
4649
let queue = Queue::default();
50+
51+
let theme = Theme::init();
52+
4753
Self {
48-
reset: ResetComponent::new(queue.clone()),
49-
commit: CommitComponent::new(queue.clone()),
54+
reset: ResetComponent::new(queue.clone(), theme),
55+
commit: CommitComponent::new(queue.clone(), theme),
5056
do_quit: false,
5157
current_commands: Vec::new(),
52-
help: HelpComponent::default(),
58+
help: HelpComponent::new(theme),
5359
msg: MsgComponent::default(),
5460
tab: 0,
55-
revlog: Revlog::new(&sender),
56-
status_tab: Status::new(&sender, &queue),
61+
revlog: Revlog::new(&sender, theme),
62+
status_tab: Status::new(&sender, &queue, theme),
5763
queue,
64+
theme,
5865
}
5966
}
6067

@@ -84,6 +91,7 @@ impl App {
8491
f,
8592
chunks_main[2],
8693
self.current_commands.as_slice(),
94+
self.theme,
8795
);
8896

8997
self.draw_popups(f);
@@ -320,10 +328,9 @@ impl App {
320328
Tabs::default()
321329
.block(Block::default().borders(Borders::BOTTOM))
322330
.titles(&[strings::TAB_STATUS, strings::TAB_LOG])
323-
.style(Style::default().fg(Color::White))
324331
.highlight_style(
325-
Style::default()
326-
.fg(Color::Yellow)
332+
self.theme
333+
.tab(true)
327334
.modifier(Modifier::UNDERLINED),
328335
)
329336
.divider(strings::TAB_DIVIDER)
@@ -336,28 +343,20 @@ impl App {
336343
f: &mut Frame<B>,
337344
r: Rect,
338345
cmds: &[CommandInfo],
346+
theme: Theme,
339347
) {
340348
let splitter = Text::Styled(
341349
Cow::from(strings::CMD_SPLITTER),
342350
Style::default(),
343351
);
344352

345-
let style_enabled =
346-
Style::default().fg(Color::White).bg(Color::Blue);
347-
348-
let style_disabled =
349-
Style::default().fg(Color::DarkGray).bg(Color::Blue);
350353
let texts = cmds
351354
.iter()
352355
.filter_map(|c| {
353356
if c.show_in_quickbar() {
354357
Some(Text::Styled(
355358
Cow::from(c.text.name),
356-
if c.enabled {
357-
style_enabled
358-
} else {
359-
style_disabled
360-
},
359+
theme.toolbar(c.enabled),
361360
))
362361
} else {
363362
None

src/components/changes.rs

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use super::{
33
statustree::{MoveSelection, StatusTree},
44
CommandBlocking, DrawableComponent,
55
};
6+
use crate::ui::style::Theme;
67
use crate::{
78
components::{CommandInfo, Component},
89
keys,
@@ -13,13 +14,7 @@ use asyncgit::{hash, sync, StatusItem, StatusItemType, CWD};
1314
use crossterm::event::Event;
1415
use std::{borrow::Cow, convert::From, path::Path};
1516
use strings::commands;
16-
use tui::{
17-
backend::Backend,
18-
layout::Rect,
19-
style::{Color, Style},
20-
widgets::Text,
21-
Frame,
22-
};
17+
use tui::{backend::Backend, layout::Rect, widgets::Text, Frame};
2318

2419
///
2520
pub struct ChangesComponent {
@@ -30,6 +25,7 @@ pub struct ChangesComponent {
3025
show_selection: bool,
3126
is_working_dir: bool,
3227
queue: Queue,
28+
theme: Theme,
3329
}
3430

3531
impl ChangesComponent {
@@ -39,6 +35,7 @@ impl ChangesComponent {
3935
focus: bool,
4036
is_working_dir: bool,
4137
queue: Queue,
38+
theme: Theme,
4239
) -> Self {
4340
Self {
4441
title: title.to_string(),
@@ -48,6 +45,7 @@ impl ChangesComponent {
4845
show_selection: focus,
4946
is_working_dir,
5047
queue,
48+
theme,
5149
}
5250
}
5351

@@ -154,9 +152,8 @@ impl ChangesComponent {
154152
item: &FileTreeItem,
155153
width: u16,
156154
selected: bool,
155+
theme: Theme,
157156
) -> Option<Text> {
158-
let select_color = Color::Rgb(0, 0, 100);
159-
160157
let indent_str = if item.info.indent == 0 {
161158
String::from("")
162159
} else {
@@ -189,18 +186,14 @@ impl ChangesComponent {
189186
format!("{} {}{}", status_char, indent_str, file)
190187
};
191188

192-
let mut style =
193-
Style::default().fg(Self::item_color(
194-
status_item
195-
.status
196-
.unwrap_or(StatusItemType::Modified),
197-
));
189+
let status = status_item
190+
.status
191+
.unwrap_or(StatusItemType::Modified);
198192

199-
if selected {
200-
style = style.bg(select_color);
201-
}
202-
203-
Some(Text::Styled(Cow::from(txt), style))
193+
Some(Text::Styled(
194+
Cow::from(txt),
195+
theme.item(status, selected),
196+
))
204197
}
205198

206199
FileTreeItemKind::Path(path_collapsed) => {
@@ -222,27 +215,14 @@ impl ChangesComponent {
222215
)
223216
};
224217

225-
let mut style = Style::default();
226-
227-
if selected {
228-
style = style.bg(select_color);
229-
}
230-
231-
Some(Text::Styled(Cow::from(txt), style))
218+
Some(Text::Styled(
219+
Cow::from(txt),
220+
theme.text(true, selected),
221+
))
232222
}
233223
}
234224
}
235225

236-
fn item_color(item_type: StatusItemType) -> Color {
237-
match item_type {
238-
StatusItemType::Modified => Color::LightYellow,
239-
StatusItemType::New => Color::LightGreen,
240-
StatusItemType::Deleted => Color::LightRed,
241-
StatusItemType::Renamed => Color::LightMagenta,
242-
_ => Color::White,
243-
}
244-
}
245-
246226
fn item_status_char(item_type: Option<StatusItemType>) -> char {
247227
if let Some(item_type) = item_type {
248228
match item_type {
@@ -287,6 +267,7 @@ impl DrawableComponent for ChangesComponent {
287267
.tree
288268
.selection
289269
.map_or(false, |e| e == idx),
270+
self.theme,
290271
)
291272
},
292273
);
@@ -298,6 +279,7 @@ impl DrawableComponent for ChangesComponent {
298279
items,
299280
self.tree.selection.map(|idx| idx - selection_offset),
300281
self.focused,
282+
self.theme,
301283
);
302284
}
303285
}

0 commit comments

Comments
 (0)