Skip to content

Commit

Permalink
Recent channel and favorite channel counts are user-defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Xithrius committed Jul 22, 2023
1 parent afb6422 commit f481d9e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 2 additions & 0 deletions default-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ seventv_emotes = false
# Channel names to always be displayed in the start screen (dashboard).
# Example: ["Xithrius", "RocketLeague", "AntVenom"]
favorite_channels = []
# The amount of recently connected to channels shown on the start screen.
recent_channel_count = 5
# What style the border of the terminal should have.
# Options: plain, rounded, double, and thick.
border_type = "plain"
Expand Down
3 changes: 3 additions & 0 deletions src/handlers/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ pub struct FrontendConfig {
pub seventv_emotes: bool,
/// Channels to always be displayed in the start screen.
pub favorite_channels: Vec<String>,
/// The amount of recent channels that should be shown on the start screen.
pub recent_channel_count: u16,
/// A border wrapper around [`BorderType`].
pub border_type: Border,
/// If the usernames should be aligned to the right.
Expand Down Expand Up @@ -174,6 +176,7 @@ impl Default for FrontendConfig {
betterttv_emotes: false,
seventv_emotes: false,
favorite_channels: vec![],
recent_channel_count: 5,
border_type: Border::default(),
right_align_usernames: false,
}
Expand Down
22 changes: 11 additions & 11 deletions src/ui/components/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ const DASHBOARD_TITLE: [&str; 5] = [
"\\__/ |__/|__/_/\\__/\\___/_/ /_/ \\__/\\__,_/_/ ",
];

const CHANNEL_LIST_AMOUNT: u16 = 5;

pub struct DashboardWidget {
config: SharedCompleteConfig,
storage: SharedStorage,
Expand Down Expand Up @@ -165,17 +163,19 @@ impl DashboardWidget {

impl Component for DashboardWidget {
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, area: Rect, emotes: Option<&mut Emotes>) {
let favorite_channels_len = self.config.borrow().frontend.favorite_channels.len() as u16;
let favorite_channels_len =
self.config.borrow().frontend.favorite_channels.len() as u16 + 1;

let recent_channels_len = self.storage.borrow().get("channels").len() as u16;
let recent_channels_len = {
let current_len = self.storage.borrow().get("channels").len() as u16;
let recent_channel_config_count = self.config.borrow().frontend.recent_channel_count;

let channel_list_constrainer = |l: u16| -> u16 {
if l == 0 {
if current_len == 0 {
2
} else if l <= CHANNEL_LIST_AMOUNT {
l + 1
} else if current_len <= recent_channel_config_count {
current_len + 1
} else {
CHANNEL_LIST_AMOUNT + 1
recent_channel_config_count + 1
}
};

Expand All @@ -189,10 +189,10 @@ impl Component for DashboardWidget {
Constraint::Length(2),
// Favorite channels title, content
Constraint::Length(2),
Constraint::Length(channel_list_constrainer(favorite_channels_len)),
Constraint::Length(favorite_channels_len),
// Recent channel title, content
Constraint::Length(2),
Constraint::Length(channel_list_constrainer(recent_channels_len)),
Constraint::Length(recent_channels_len),
// Quit
Constraint::Length(1),
])
Expand Down

0 comments on commit f481d9e

Please sign in to comment.