Skip to content

Commit

Permalink
Implemented NO_COLOR environment variable standard
Browse files Browse the repository at this point in the history
All styles are now statics

[pre-commit.ci] auto fixes from pre-commit.com hooks

Appeased the linter, removed the vscode crate extension
  • Loading branch information
Xithrius committed Jul 27, 2024
1 parent 03d07e2 commit 2cd6e36
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 129 deletions.
5 changes: 1 addition & 4 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"recommendations": [
"serayuzgur.crates",
"rust-lang.rust-analyzer"
],
"recommendations": ["rust-lang.rust-analyzer"]
}
2 changes: 1 addition & 1 deletion src/emotes/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ pub async fn get_twitch_emote(name: &str) -> Result<()> {

let res = if res.is_err() {
client
.get(&url.replace("animated", "static"))
.get(url.replace("animated", "static"))

Check warning on line 478 in src/emotes/downloader.rs

View check run for this annotation

Codecov / codecov/patch

src/emotes/downloader.rs#L478

Added line #L478 was not covered by tests
.send()
.await?
.error_for_status()
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl App {
self.components.chat.scroll_offset.jump_to(0);
}

pub fn purge_user_messages(&mut self, user_id: &str) {
pub fn purge_user_messages(&self, user_id: &str) {

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

View check run for this annotation

Codecov / codecov/patch

src/handlers/app.rs#L181

Added line #L181 was not covered by tests
let messages = self
.messages
.borrow_mut()
Expand All @@ -190,7 +190,7 @@ impl App {
self.messages.replace(messages);
}

pub fn remove_message_with(&mut self, message_id: &str) {
pub fn remove_message_with(&self, message_id: &str) {

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

View check run for this annotation

Codecov / codecov/patch

src/handlers/app.rs#L193

Added line #L193 was not covered by tests
let index = self
.messages
.borrow_mut()
Expand All @@ -217,7 +217,7 @@ impl App {
}

#[allow(dead_code)]
pub fn rotate_theme(&mut self) {
pub fn rotate_theme(&self) {

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

View check run for this annotation

Codecov / codecov/patch

src/handlers/app.rs#L220

Added line #L220 was not covered by tests
todo!("Rotate through different themes")
}
}
16 changes: 8 additions & 8 deletions src/handlers/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ use crate::{
ZERO_WIDTH_SPACE_STR,
},
styles::{
DATETIME_DARK, DATETIME_LIGHT, HIGHLIGHT_NAME_DARK, HIGHLIGHT_NAME_LIGHT, SYSTEM_CHAT,
DATETIME_DARK_STYLE, DATETIME_LIGHT_STYLE, HIGHLIGHT_NAME_DARK_STYLE,
HIGHLIGHT_NAME_LIGHT_STYLE, SEARCH_STYLE, SYSTEM_CHAT_STYLE,
},
text::split_cow_in_place,
},
Expand Down Expand Up @@ -454,19 +455,18 @@ impl MessageData {
Style::default()
};
let username_theme = match frontend_config.theme {
Theme::Dark => HIGHLIGHT_NAME_DARK,
_ => HIGHLIGHT_NAME_LIGHT,
Theme::Dark => *HIGHLIGHT_NAME_DARK_STYLE,
_ => *HIGHLIGHT_NAME_LIGHT_STYLE,

Check warning on line 459 in src/handlers/data.rs

View check run for this annotation

Codecov / codecov/patch

src/handlers/data.rs#L458-L459

Added lines #L458 - L459 were not covered by tests
};
let author_theme = if self.system {
SYSTEM_CHAT
*SYSTEM_CHAT_STYLE

Check warning on line 462 in src/handlers/data.rs

View check run for this annotation

Codecov / codecov/patch

src/handlers/data.rs#L462

Added line #L462 was not covered by tests
} else {
Style::default().fg(fg)
};
let datetime_theme = match frontend_config.theme {
Theme::Dark => DATETIME_DARK,
_ => DATETIME_LIGHT,
Theme::Dark => *DATETIME_DARK_STYLE,
_ => *DATETIME_LIGHT_STYLE,

Check warning on line 468 in src/handlers/data.rs

View check run for this annotation

Codecov / codecov/patch

src/handlers/data.rs#L467-L468

Added lines #L467 - L468 were not covered by tests
};
let search_theme = Style::default().fg(Color::Red).add_modifier(Modifier::BOLD);

// All indices to highlight like a user
let username_highlight = username_highlight
Expand All @@ -491,7 +491,7 @@ impl MessageData {
})
.unwrap_or_default();

let search = (&search_highlight as &[usize], search_theme);
let search = (&search_highlight as &[usize], *SEARCH_STYLE);

Check warning on line 494 in src/handlers/data.rs

View check run for this annotation

Codecov / codecov/patch

src/handlers/data.rs#L494

Added line #L494 was not covered by tests
let username = (&username_highlight as &[usize], username_theme);

// Message prefix
Expand Down
14 changes: 6 additions & 8 deletions src/ui/components/channel_switcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ use crate::{
components::{utils::InputWidget, Component},
statics::{NAME_MAX_CHARACTERS, NAME_RESTRICTION_REGEX},
},
utils::text::{first_similarity, title_line, TitleStyle},
utils::{
styles::TITLE_STYLE,
text::{first_similarity, title_line, TitleStyle},
},
};

use super::utils::centered_rect;
Expand Down Expand Up @@ -175,14 +178,12 @@ impl Component for ChannelSwitcherWidget {
continue;
}

let search_theme = Style::default().fg(Color::Red).add_modifier(Modifier::BOLD);

let line = channel
.chars()
.enumerate()
.map(|(i, c)| {
if matched_indices.contains(&i) {
Span::styled(c.to_string(), search_theme)
Span::styled(c.to_string(), *TITLE_STYLE)

Check warning on line 186 in src/ui/components/channel_switcher.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/channel_switcher.rs#L186

Added line #L186 was not covered by tests
} else {
Span::raw(c.to_string())
}
Expand All @@ -201,10 +202,7 @@ impl Component for ChannelSwitcherWidget {
let list = List::new(items.clone())
.block(
Block::default()
.title(title_line(
&title_binding,
Style::default().fg(Color::Red).add_modifier(Modifier::BOLD),
))
.title(title_line(&title_binding, *TITLE_STYLE))

Check warning on line 205 in src/ui/components/channel_switcher.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/channel_switcher.rs#L205

Added line #L205 was not covered by tests
.borders(Borders::ALL)
.border_type(self.config.borrow().frontend.border_type.clone().into()),
)
Expand Down
30 changes: 17 additions & 13 deletions src/ui/components/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ use crate::{
following::FollowingWidget, ChannelSwitcherWidget, ChatInputWidget, Component,
MessageSearchWidget,
},
utils::text::{title_line, TitleStyle},
utils::{
styles::{NO_COLOR, TEXT_DARK_STYLE, TITLE_STYLE},
text::{title_line, TitleStyle},
},
};

pub struct ChatWidget {
Expand Down Expand Up @@ -206,21 +209,22 @@ impl Component for ChatWidget {
} else {
"Filter"
},
Style::default().add_modifier(Modifier::BOLD).fg(
if self.filters.borrow().enabled() {
Color::Green
} else {
Color::Red
},
),
if *NO_COLOR {
Style::default()

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

View check run for this annotation

Codecov / codecov/patch

src/ui/components/chat.rs#L212-L213

Added lines #L212 - L213 were not covered by tests
} else {
Style::default().add_modifier(Modifier::BOLD).fg(
if self.filters.borrow().enabled() {
Color::Green

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

View check run for this annotation

Codecov / codecov/patch

src/ui/components/chat.rs#L215-L217

Added lines #L215 - L217 were not covered by tests
} else {
Color::Red

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

View check run for this annotation

Codecov / codecov/patch

src/ui/components/chat.rs#L219

Added line #L219 was not covered by tests
},
)
},
)),
];

let chat_title = if self.config.borrow().frontend.title_shown {
Line::from(title_line(
&spans,
Style::default().fg(Color::Red).add_modifier(Modifier::BOLD),
))
Line::from(title_line(&spans, *TITLE_STYLE))

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

View check run for this annotation

Codecov / codecov/patch

src/ui/components/chat.rs#L227

Added line #L227 was not covered by tests
} else {
Line::default()
};
Expand All @@ -241,7 +245,7 @@ impl Component for ChatWidget {
.title(chat_title),
)
}
.style(Style::default().fg(Color::White));
.style(*TEXT_DARK_STYLE);

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

View check run for this annotation

Codecov / codecov/patch

src/ui/components/chat.rs#L248

Added line #L248 was not covered by tests

f.render_widget(list, *first_v_chunk);

Expand Down
13 changes: 6 additions & 7 deletions src/ui/components/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
terminal::TerminalAction,
twitch::TwitchAction,
ui::components::{ChannelSwitcherWidget, Component},
utils::styles::DASHBOARD_TITLE_COLOR,
utils::styles::{DASHBOARD_SECTION_STYLE, DASHBOARD_TITLE_COLOR_STYLE, TEXT_DARK_STYLE},
};

use super::following::FollowingWidget;
Expand Down Expand Up @@ -67,7 +67,7 @@ impl DashboardWidget {
Span::raw(s),
]))
}))
.style(Style::default().fg(Color::White))
.style(*TEXT_DARK_STYLE)

Check warning on line 70 in src/ui/components/dashboard.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/dashboard.rs#L70

Added line #L70 was not covered by tests
.highlight_style(Style::default().add_modifier(Modifier::ITALIC))
}

Expand All @@ -78,7 +78,7 @@ impl DashboardWidget {
.map(|&s| Line::from(vec![Span::raw(s)]))
.collect::<Vec<Line>>(),
)
.style(DASHBOARD_TITLE_COLOR);
.style(*DASHBOARD_TITLE_COLOR_STYLE);

Check warning on line 81 in src/ui/components/dashboard.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/dashboard.rs#L81

Added line #L81 was not covered by tests

frame.render_widget(w, *v_chunks.next().unwrap());
}
Expand All @@ -91,8 +91,7 @@ impl DashboardWidget {
default_channels: &[String],
) {
frame.render_widget(
Paragraph::new("Currently selected channel")
.style(Style::default().fg(Color::LightRed)),
Paragraph::new("Currently selected channel").style(*DASHBOARD_SECTION_STYLE),

Check warning on line 94 in src/ui/components/dashboard.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/dashboard.rs#L94

Added line #L94 was not covered by tests
*v_chunks.next().unwrap(),
);

Expand All @@ -109,7 +108,7 @@ impl DashboardWidget {
frame.render_widget(current_channel_selection, *v_chunks.next().unwrap());

frame.render_widget(
Paragraph::new("Favorite channels").style(Style::default().fg(Color::LightRed)),
Paragraph::new("Favorite channels").style(*DASHBOARD_SECTION_STYLE),

Check warning on line 111 in src/ui/components/dashboard.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/dashboard.rs#L111

Added line #L111 was not covered by tests
*v_chunks.next().unwrap(),
);

Expand All @@ -122,7 +121,7 @@ impl DashboardWidget {
}

frame.render_widget(
Paragraph::new("Most recent channels").style(Style::default().fg(Color::LightRed)),
Paragraph::new("Most recent channels").style(*DASHBOARD_SECTION_STYLE),

Check warning on line 124 in src/ui/components/dashboard.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/dashboard.rs#L124

Added line #L124 was not covered by tests
*v_chunks.next().unwrap(),
);

Expand Down
22 changes: 8 additions & 14 deletions src/ui/components/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use chrono::{DateTime, Local};
use tui::{
layout::{Constraint, Rect},
prelude::Alignment,
style::{Color, Modifier, Style},
widgets::{block::Position, Block, Borders, Clear, Row, Table},
Frame,
};
Expand All @@ -14,7 +13,10 @@ use crate::{
},
terminal::TerminalAction,
ui::components::Component,
utils::text::{title_line, TitleStyle},
utils::{
styles::{BOLD_STYLE, TITLE_STYLE},
text::{title_line, TitleStyle},
},
};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -67,12 +69,10 @@ impl Component for DebugWidget {
let mut inner_rows = if i > 0 {
vec![
Row::new::<Vec<String>>(vec![]),
Row::new(vec![t.to_string()])
.style(Style::default().add_modifier(Modifier::BOLD)),
Row::new(vec![t.to_string()]).style(*BOLD_STYLE),

Check warning on line 72 in src/ui/components/debug.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/debug.rs#L72

Added line #L72 was not covered by tests
]
} else {
vec![Row::new(vec![t.to_string()])
.style(Style::default().add_modifier(Modifier::BOLD))]
vec![Row::new(vec![t.to_string()]).style(*BOLD_STYLE)]

Check warning on line 75 in src/ui/components/debug.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/debug.rs#L75

Added line #L75 was not covered by tests
};

for (k, v) in values {
Expand All @@ -87,10 +87,7 @@ impl Component for DebugWidget {

let table = Table::new(rows, &[Constraint::Length(25), Constraint::Length(25)]).block(
Block::default()
.title(title_line(
&title_binding,
Style::default().fg(Color::Red).add_modifier(Modifier::BOLD),
))
.title(title_line(&title_binding, *TITLE_STYLE))

Check warning on line 90 in src/ui/components/debug.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/debug.rs#L90

Added line #L90 was not covered by tests
.borders(Borders::ALL)
.border_type(self.config.borrow().frontend.border_type.clone().into()),
);
Expand All @@ -108,10 +105,7 @@ impl Component for DebugWidget {
let bottom_block = Block::default()
.borders(Borders::BOTTOM | Borders::LEFT | Borders::RIGHT)
.border_type(self.config.borrow().frontend.border_type.clone().into())
.title(title_line(
&title,
Style::default().add_modifier(Modifier::BOLD).fg(Color::Red),
))
.title(title_line(&title, *TITLE_STYLE))

Check warning on line 108 in src/ui/components/debug.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/debug.rs#L108

Added line #L108 was not covered by tests
.title_position(Position::Bottom)
.title_alignment(Alignment::Left);

Expand Down
18 changes: 8 additions & 10 deletions src/ui/components/emote_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::{
utils::{
colors::u32_to_color,
emotes::UnicodePlaceholder,
styles::{NO_COLOR, SEARCH_STYLE, TITLE_STYLE},
text::{first_similarity_iter, title_line, TitleStyle},
},
};
Expand Down Expand Up @@ -68,13 +69,11 @@ impl EmotePickerWidget {
Some((emotes.clone(), input_suggester)),
);

let search_theme = Style::default().fg(Color::Red).add_modifier(Modifier::BOLD);

Self {
config,
emotes,
input,
search_theme,
search_theme: *SEARCH_STYLE,

Check warning on line 76 in src/ui/components/emote_picker.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/emote_picker.rs#L76

Added line #L76 was not covered by tests
list_state: ListState::default(),
filtered_emotes: vec![],
}
Expand Down Expand Up @@ -212,18 +211,17 @@ impl Component for EmotePickerWidget {
let list = List::new::<Vec<ListItem>>(list_items)
.block(
Block::default()
.title(title_line(
&title_binding,
Style::default().fg(Color::Red).add_modifier(Modifier::BOLD),
))
.title(title_line(&title_binding, *TITLE_STYLE))

Check warning on line 214 in src/ui/components/emote_picker.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/emote_picker.rs#L214

Added line #L214 was not covered by tests
.borders(Borders::ALL)
.border_type(self.config.borrow().frontend.border_type.clone().into()),
)
.highlight_style(
.highlight_style(if *NO_COLOR {
Style::default()

Check warning on line 219 in src/ui/components/emote_picker.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/emote_picker.rs#L218-L219

Added lines #L218 - L219 were not covered by tests
} else {
Style::default()
.bg(Color::LightGreen)
.add_modifier(Modifier::BOLD),
);
.add_modifier(Modifier::BOLD)

Check warning on line 223 in src/ui/components/emote_picker.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/emote_picker.rs#L223

Added line #L223 was not covered by tests
});

f.render_widget(Clear, r);
f.render_stateful_widget(list, r, &mut self.list_state);
Expand Down
13 changes: 10 additions & 3 deletions src/ui/components/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use tui::{
widgets::{block::Title, Block, Borders, Clear, Paragraph},
};

use crate::ui::components::Component;
use crate::{
ui::components::Component,
utils::styles::{NO_COLOR, TEXT_DARK_STYLE},
};

#[derive(Debug, Clone)]
pub struct ErrorWidget {
Expand Down Expand Up @@ -44,10 +47,14 @@ impl Component for ErrorWidget {
.block(
Block::default()
.borders(Borders::ALL)
.border_style(Style::default().fg(Color::Red))
.border_style(if *NO_COLOR {
Style::default()

Check warning on line 51 in src/ui/components/error.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/error.rs#L50-L51

Added lines #L50 - L51 were not covered by tests
} else {
Style::default().fg(Color::Red)

Check warning on line 53 in src/ui/components/error.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/error.rs#L53

Added line #L53 was not covered by tests
})
.title(Title::from("[ ERROR ]").alignment(Alignment::Center)),
)
.style(Style::default().fg(Color::White))
.style(*TEXT_DARK_STYLE)

Check warning on line 57 in src/ui/components/error.rs

View check run for this annotation

Codecov / codecov/patch

src/ui/components/error.rs#L57

Added line #L57 was not covered by tests
.alignment(Alignment::Center);

f.render_widget(Clear, r);
Expand Down
Loading

0 comments on commit 2cd6e36

Please sign in to comment.