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

NO_COLOR environment variable standard #632

Merged
merged 2 commits into from
Jul 29, 2024
Merged
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
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"]
}
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,
};
let author_theme = if self.system {
SYSTEM_CHAT
*SYSTEM_CHAT_STYLE
} 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,
};
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);
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)
} 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))
.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()
} else {
Style::default().add_modifier(Modifier::BOLD).fg(
if self.filters.borrow().enabled() {
Color::Green
} else {
Color::Red
},
)
},
)),
];

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))
} 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);

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)
.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);

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),
*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),
*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),
*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),
]
} 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)]
};

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))
.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))
.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,
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))
.borders(Borders::ALL)
.border_type(self.config.borrow().frontend.border_type.clone().into()),
)
.highlight_style(
.highlight_style(if *NO_COLOR {
Style::default()
} else {
Style::default()
.bg(Color::LightGreen)
.add_modifier(Modifier::BOLD),
);
.add_modifier(Modifier::BOLD)
});

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()
} else {
Style::default().fg(Color::Red)
})
.title(Title::from("[ ERROR ]").alignment(Alignment::Center)),
)
.style(Style::default().fg(Color::White))
.style(*TEXT_DARK_STYLE)
.alignment(Alignment::Center);

f.render_widget(Clear, r);
Expand Down
9 changes: 4 additions & 5 deletions src/ui/components/help.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use tui::{
layout::{Constraint, Rect},
style::{Modifier, Style},
widgets::{Block, Borders, Cell, Row, Table},
Frame,
};
Expand All @@ -11,7 +10,7 @@ use crate::{
components::Component,
statics::{HELP_COLUMN_TITLES, HELP_KEYBINDS},
},
utils::styles::COLUMN_TITLE,
utils::styles::{BOLD_STYLE, COLUMN_TITLE_STYLE},
};

// Once a solution is found to calculate constraints, this will be removed.
Expand Down Expand Up @@ -40,10 +39,10 @@ impl Component for HelpWidget {
rows.push(Row::new(vec![
if i == 0 {
Cell::from((*s).to_string())
.style(Style::default().add_modifier(Modifier::BOLD))
} else {
Cell::from("")
},
}
.style(*BOLD_STYLE),
Cell::from((*key).to_string()),
Cell::from((*desc).to_string()),
]));
Expand All @@ -53,7 +52,7 @@ impl Component for HelpWidget {
}

let help_table = Table::new(rows, TABLE_CONSTRAINTS)
.header(Row::new(HELP_COLUMN_TITLES.iter().copied()).style(COLUMN_TITLE))
.header(Row::new(HELP_COLUMN_TITLES.iter().copied()).style(*COLUMN_TITLE_STYLE))
.block(
Block::default()
.borders(Borders::ALL)
Expand Down
4 changes: 2 additions & 2 deletions src/ui/components/state_tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use tui::{

use crate::{
handlers::{config::SharedCompleteConfig, state::State},
utils::text::capitalize_first_char,
utils::{styles::STATE_TABS_STYLE, text::capitalize_first_char},
};

const TABS_TO_RENDER: [State; 3] = [State::Dashboard, State::Normal, State::Help];
Expand All @@ -32,7 +32,7 @@ impl StateTabsWidget {

let tabs = Tabs::new(tab_titles)
.block(Block::default())
.style(Style::default().fg(Color::Gray).add_modifier(Modifier::DIM))
.style(*STATE_TABS_STYLE)
.highlight_style(
Style::default()
.fg(Color::Yellow)
Expand Down
Loading
Loading