Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme switching, custom themes #449

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 9 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:
CARGO_TERM_COLOR: always

jobs:
build-test:
build:
strategy:
fail-fast: false

Expand All @@ -25,6 +25,7 @@ jobs:
target: x86_64-apple-darwin

name: Build & Test (${{ matrix.target }})

runs-on: ${{ matrix.os }}

env:
Expand Down Expand Up @@ -55,13 +56,10 @@ jobs:
- name: Build
run: cargo build --verbose --target ${{ matrix.target }}

- name: Run tests
run: cargo test --verbose --target ${{ matrix.target }}

lint:
name: Formatter
name: Lint

needs: build-test
needs: build

runs-on: ubuntu-latest

Expand All @@ -83,7 +81,12 @@ jobs:
run: cargo clippy -- -D warnings

coverage:
name: Coverage

needs: build

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
8 changes: 3 additions & 5 deletions src/handlers/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@
Key::Ctrl('d') => {
self.components.debug.toggle_focus();
}
Key::Ctrl('g') => {
self.config.borrow_mut().rotate_theme();
}

Check warning on line 157 in src/handlers/app.rs

View check run for this annotation

Codecov / codecov/patch

src/handlers/app.rs#L155-L157

Added lines #L155 - L157 were not covered by tests
_ => {
return match self.state {
State::Dashboard => self.components.dashboard.event(event),
Expand Down Expand Up @@ -214,9 +217,4 @@
self.previous_state = Some(self.state.clone());
self.state = other;
}

#[allow(dead_code)]
pub fn rotate_theme(&mut self) {
todo!("Rotate through different themes")
}
}
7 changes: 7 additions & 0 deletions src/handlers/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,4 +528,11 @@
)
}
}

pub fn rotate_theme(&mut self) {
self.frontend.theme = match self.frontend.theme {
Theme::Dark => Theme::Light,
_ => Theme::Dark,

Check warning on line 535 in src/handlers/config.rs

View check run for this annotation

Codecov / codecov/patch

src/handlers/config.rs#L532-L535

Added lines #L532 - L535 were not covered by tests
};
}

Check warning on line 537 in src/handlers/config.rs

View check run for this annotation

Codecov / codecov/patch

src/handlers/config.rs#L537

Added line #L537 was not covered by tests
}
24 changes: 19 additions & 5 deletions src/ui/components/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
emotes::{emotes_enabled, hide_message_emotes, is_in_rect, show_span_emotes, Emotes},
handlers::{
app::SharedMessages,
config::SharedCompleteConfig,
config::{SharedCompleteConfig, Theme},
data::MessageData,
filters::SharedFilters,
state::State,
Expand All @@ -30,7 +30,10 @@
following::FollowingWidget, utils::centered_rect, ChannelSwitcherWidget, ChatInputWidget,
Component, MessageSearchWidget,
},
utils::text::{title_line, TitleStyle},
utils::{
styles::{BORDER_DARK, BORDER_LIGHT, WINDOW_DARK, WINDOW_LIGHT},
text::{title_line, TitleStyle},
},
};

pub struct ChatWidget {
Expand Down Expand Up @@ -294,9 +297,16 @@
Block::default()
.borders(Borders::ALL)
.border_type(self.config.borrow().frontend.border_type.clone().into())
.title(chat_title),
.title(chat_title)
.style(match self.config.borrow().frontend.theme {
Theme::Dark => WINDOW_DARK,
_ => WINDOW_LIGHT,

Check warning on line 303 in src/ui/components/chat.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/chat.rs#L300-L303

Added lines #L300 - L303 were not covered by tests
}),
)
.style(Style::default().fg(Color::White));
.style(match self.config.borrow().frontend.theme {
Theme::Dark => BORDER_DARK,
_ => BORDER_LIGHT,

Check warning on line 308 in src/ui/components/chat.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/chat.rs#L306-L308

Added lines #L306 - L308 were not covered by tests
});

f.render_widget(list, *first_v_chunk);

Expand All @@ -317,7 +327,11 @@
.border_type(self.config.borrow().frontend.border_type.clone().into())
.title(title_line(&title, Style::default()))
.title_position(Position::Bottom)
.title_alignment(Alignment::Right);
.title_alignment(Alignment::Right)
.style(match self.config.borrow().frontend.theme {
Theme::Dark => BORDER_DARK,
_ => BORDER_LIGHT,

Check warning on line 333 in src/ui/components/chat.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/chat.rs#L330-L333

Added lines #L330 - L333 were not covered by tests
});

let rect = Rect::new(
first_v_chunk.x,
Expand Down
27 changes: 19 additions & 8 deletions src/utils/styles.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
use tui::style::{Color, Modifier, Style};

#[allow(dead_code)]
pub const BORDER_NAME_DARK: Style = Style {
pub const WINDOW_DARK: Style = Style {
fg: None,
bg: None,
add_modifier: Modifier::empty(),
sub_modifier: Modifier::empty(),
};
pub const WINDOW_LIGHT: Style = Style {
fg: None,
bg: Some(Color::White),
add_modifier: Modifier::empty(),
sub_modifier: Modifier::empty(),
};

pub const BORDER_DARK: Style = Style {
fg: Some(Color::White),
bg: None,
add_modifier: Modifier::empty(),
sub_modifier: Modifier::empty(),
};

#[allow(dead_code)]
pub const BORDER_NAME_LIGHT: Style = Style {
pub const BORDER_LIGHT: Style = Style {
fg: Some(Color::Black),
bg: None,
add_modifier: Modifier::empty(),
Expand All @@ -31,14 +42,14 @@ pub const DATETIME_LIGHT: Style = Style {
};

pub const HIGHLIGHT_NAME_DARK: Style = Style {
fg: Some(Color::Black),
bg: Some(Color::White),
fg: Some(Color::Rgb(83, 83, 95)),
bg: Some(Color::Rgb(173, 173, 184)),
add_modifier: Modifier::BOLD,
sub_modifier: Modifier::empty(),
};
pub const HIGHLIGHT_NAME_LIGHT: Style = Style {
fg: Some(Color::White),
bg: Some(Color::Black),
fg: Some(Color::Rgb(173, 173, 184)),
bg: Some(Color::Rgb(83, 83, 95)),
add_modifier: Modifier::BOLD,
sub_modifier: Modifier::empty(),
};
Expand Down
Loading