From 42b945fb7a9d0b39bd04dfac1e1ccf340616ba8b Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sun, 20 Aug 2023 20:00:29 -0700 Subject: [PATCH 1/4] Theme switching for main window --- src/handlers/app.rs | 9 +++++++-- src/ui/components/chat.rs | 18 ++++++++++++++---- src/utils/styles.rs | 6 ++---- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/handlers/app.rs b/src/handlers/app.rs index c72d6dc8..291d529f 100644 --- a/src/handlers/app.rs +++ b/src/handlers/app.rs @@ -151,6 +151,9 @@ impl App { Key::Ctrl('d') => { self.components.debug.toggle_focus(); } + Key::Ctrl('T') => { + self.rotate_theme(); + } _ => { return match self.state { State::Dashboard => self.components.dashboard.event(event), @@ -214,8 +217,10 @@ impl App { self.state = other; } - #[allow(dead_code)] pub fn rotate_theme(&mut self) { - todo!("Rotate through different themes") + self.theme = match self.theme { + Theme::Dark => Theme::Light, + _ => Theme::Dark, + } } } diff --git a/src/ui/components/chat.rs b/src/ui/components/chat.rs index cd99520a..8ad7db8f 100644 --- a/src/ui/components/chat.rs +++ b/src/ui/components/chat.rs @@ -16,7 +16,7 @@ use crate::{ 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, @@ -31,7 +31,10 @@ use crate::{ following::FollowingWidget, utils::centered_rect, ChannelSwitcherWidget, ChatInputWidget, Component, MessageSearchWidget, }, - utils::text::{title_line, TitleStyle}, + utils::{ + styles::{BORDER_DARK, BORDER_LIGHT}, + text::{title_line, TitleStyle}, + }, }; pub struct ChatWidget { @@ -302,7 +305,10 @@ impl Component for ChatWidget { .border_type(self.config.borrow().frontend.border_type.clone().into()) .title(chat_title), ) - .style(Style::default().fg(Color::White)); + .style(match self.config.borrow().frontend.theme { + Theme::Dark => BORDER_DARK, + _ => BORDER_LIGHT, + }); f.render_widget(list, *first_v_chunk); @@ -323,7 +329,11 @@ impl Component for ChatWidget { .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, + }); let rect = Rect::new( first_v_chunk.x, diff --git a/src/utils/styles.rs b/src/utils/styles.rs index c32ae011..e414c638 100644 --- a/src/utils/styles.rs +++ b/src/utils/styles.rs @@ -1,7 +1,6 @@ use tui::style::{Color, Modifier, Style}; -#[allow(dead_code)] -pub const BORDER_NAME_DARK: Style = Style { +pub const BORDER_DARK: Style = Style { fg: Some(Color::White), bg: None, add_modifier: Modifier::empty(), @@ -9,8 +8,7 @@ pub const BORDER_NAME_DARK: Style = Style { underline_color: None, }; -#[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(), From 2f02049c18b4c73d33116cff9222e6bb35a31a2d Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sun, 20 Aug 2023 20:07:00 -0700 Subject: [PATCH 2/4] Moved `rotate_theme` to config impl --- src/handlers/app.rs | 11 ++--------- src/handlers/config.rs | 7 +++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/handlers/app.rs b/src/handlers/app.rs index 291d529f..1f068911 100644 --- a/src/handlers/app.rs +++ b/src/handlers/app.rs @@ -151,8 +151,8 @@ impl App { Key::Ctrl('d') => { self.components.debug.toggle_focus(); } - Key::Ctrl('T') => { - self.rotate_theme(); + Key::Ctrl('.') => { + self.config.borrow_mut().rotate_theme(); } _ => { return match self.state { @@ -216,11 +216,4 @@ impl App { self.previous_state = Some(self.state.clone()); self.state = other; } - - pub fn rotate_theme(&mut self) { - self.theme = match self.theme { - Theme::Dark => Theme::Light, - _ => Theme::Dark, - } - } } diff --git a/src/handlers/config.rs b/src/handlers/config.rs index f652d2ab..158d0984 100644 --- a/src/handlers/config.rs +++ b/src/handlers/config.rs @@ -525,4 +525,11 @@ impl CompleteConfig { ) } } + + pub fn rotate_theme(&mut self) { + self.frontend.theme = match self.frontend.theme { + Theme::Dark => Theme::Light, + _ => Theme::Dark, + } + } } From ba3783d8677fe026823be0cb29b05b97c626ad1a Mon Sep 17 00:00:00 2001 From: Xithrius Date: Thu, 26 Oct 2023 21:39:18 -0700 Subject: [PATCH 3/4] `Ctrl + g` to switch themes [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Appeased the linter --- src/handlers/app.rs | 2 +- src/handlers/config.rs | 2 +- src/ui/components/chat.rs | 8 ++++++-- src/utils/styles.rs | 21 +++++++++++++++++---- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/handlers/app.rs b/src/handlers/app.rs index bce73641..9b0c3911 100644 --- a/src/handlers/app.rs +++ b/src/handlers/app.rs @@ -152,7 +152,7 @@ impl App { Key::Ctrl('d') => { self.components.debug.toggle_focus(); } - Key::Ctrl('.') => { + Key::Ctrl('g') => { self.config.borrow_mut().rotate_theme(); } _ => { diff --git a/src/handlers/config.rs b/src/handlers/config.rs index 5308b288..e94f87bd 100644 --- a/src/handlers/config.rs +++ b/src/handlers/config.rs @@ -533,6 +533,6 @@ impl CompleteConfig { self.frontend.theme = match self.frontend.theme { Theme::Dark => Theme::Light, _ => Theme::Dark, - } + }; } } diff --git a/src/ui/components/chat.rs b/src/ui/components/chat.rs index aaa97cd5..f2b96fc5 100644 --- a/src/ui/components/chat.rs +++ b/src/ui/components/chat.rs @@ -31,7 +31,7 @@ use crate::{ Component, MessageSearchWidget, }, utils::{ - styles::{BORDER_DARK, BORDER_LIGHT}, + styles::{BORDER_DARK, BORDER_LIGHT, WINDOW_DARK, WINDOW_LIGHT}, text::{title_line, TitleStyle}, }, }; @@ -297,7 +297,11 @@ impl Component for ChatWidget { 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, + }), ) .style(match self.config.borrow().frontend.theme { Theme::Dark => BORDER_DARK, diff --git a/src/utils/styles.rs b/src/utils/styles.rs index 644d3d8d..381b0ae2 100644 --- a/src/utils/styles.rs +++ b/src/utils/styles.rs @@ -1,5 +1,18 @@ use tui::style::{Color, Modifier, 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, @@ -29,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(), }; From 5ecf3b9eb72ee98613c815bcff145d952db7d9b6 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sat, 28 Oct 2023 23:23:47 -0700 Subject: [PATCH 4/4] Clearer CI job names --- .github/workflows/ci.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3166e1f..79cab971 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ env: CARGO_TERM_COLOR: always jobs: - build-test: + build: strategy: fail-fast: false @@ -25,6 +25,7 @@ jobs: target: x86_64-apple-darwin name: Build & Test (${{ matrix.target }}) + runs-on: ${{ matrix.os }} env: @@ -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 @@ -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