diff --git a/Cargo.lock b/Cargo.lock index ff0f0f7..18a33af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,17 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" version = "1.0.4" @@ -26,6 +37,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + [[package]] name = "android-tzdata" version = "0.1.1" @@ -899,6 +916,10 @@ name = "hashbrown" version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +dependencies = [ + "ahash", + "allocator-api2", +] [[package]] name = "heck" @@ -1237,6 +1258,15 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "lru" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a83fb7698b3643a0e34f9ae6f2e8f0178c0fd42f8b59d493aa271ff3a5bf21" +dependencies = [ + "hashbrown 0.14.0", +] + [[package]] name = "malloc_buf" version = "0.0.6" @@ -1607,15 +1637,16 @@ dependencies = [ [[package]] name = "ratatui" -version = "0.23.0" +version = "0.23.1-alpha.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e2e4cd95294a85c3b4446e63ef054eea43e0205b1fd60120c16b74ff7ff96ad" +checksum = "a16e8ea6cc383d0a413353336a40794844f0d63fad911004adfe2b64ab993952" dependencies = [ "bitflags 2.4.0", "cassowary", "crossterm", "indoc", "itertools", + "lru", "paste", "serde", "strum", @@ -2468,6 +2499,12 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "walkdir" version = "2.3.3" diff --git a/Cargo.toml b/Cargo.toml index f533b05..0d28c44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ categories = ["command-line-utilities"] [dependencies] crossterm = "0.27.0" -tui = { package = "ratatui", version = "0.23.0", default-features = false, features = [ "crossterm", "serde" ] } +tui = { package = "ratatui", version = "0.23.1-alpha.6", default-features = false, features = [ "crossterm", "serde" ] } tokio = { version = "1.32.0", features = [ "rt", "macros", "rt-multi-thread", "fs" ] } clap = { version = "4.4.6", features = [ "derive", "cargo" ] } serde = { version = "1.0.188", features = [ "derive" ] } diff --git a/src/handlers/app.rs b/src/handlers/app.rs index ac7cf06..5de4a5e 100644 --- a/src/handlers/app.rs +++ b/src/handlers/app.rs @@ -3,7 +3,6 @@ use std::{cell::RefCell, collections::VecDeque, rc::Rc}; use chrono::{DateTime, Local}; use rustyline::line_buffer::LineBuffer; use tui::{ - backend::Backend, layout::{Constraint, Direction, Layout, Rect}, Frame, }; @@ -102,7 +101,7 @@ impl App { } } - pub fn draw(&mut self, f: &mut Frame) { + pub fn draw(&mut self, f: &mut Frame) { let mut size = f.size(); if self.config.borrow().frontend.state_tabs { diff --git a/src/ui/components/channel_switcher.rs b/src/ui/components/channel_switcher.rs index a08ab59..a4debf4 100644 --- a/src/ui/components/channel_switcher.rs +++ b/src/ui/components/channel_switcher.rs @@ -2,7 +2,6 @@ use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher}; use once_cell::sync::Lazy; use regex::Regex; use tui::{ - backend::Backend, layout::Rect, prelude::{Alignment, Margin}, style::{Color, Modifier, Style}, @@ -107,9 +106,7 @@ impl ChannelSwitcherWidget { self.list_state.select(Some(i)); self.vertical_scroll = self.vertical_scroll.saturating_add(1); - self.vertical_scroll_state = self - .vertical_scroll_state - .position(self.vertical_scroll as u16); + self.vertical_scroll_state = self.vertical_scroll_state.position(self.vertical_scroll); } fn previous(&mut self) { @@ -121,9 +118,7 @@ impl ChannelSwitcherWidget { self.list_state.select(Some(i)); self.vertical_scroll = self.vertical_scroll.saturating_sub(1); - self.vertical_scroll_state = self - .vertical_scroll_state - .position(self.vertical_scroll as u16); + self.vertical_scroll_state = self.vertical_scroll_state.position(self.vertical_scroll); } fn unselect(&mut self) { @@ -146,12 +141,7 @@ impl ToString for ChannelSwitcherWidget { } impl Component for ChannelSwitcherWidget { - fn draw( - &mut self, - f: &mut Frame, - area: Option, - emotes: Option<&mut Emotes>, - ) { + fn draw(&mut self, f: &mut Frame, area: Option, emotes: Option<&mut Emotes>) { let r = area.map_or_else(|| centered_rect(60, 60, 20, f.size()), |a| a); let channels = self.storage.borrow().get("channels"); @@ -224,9 +214,7 @@ impl Component for ChannelSwitcherWidget { f.render_widget(Clear, r); f.render_stateful_widget(list, r, &mut self.list_state); - self.vertical_scroll_state = self - .vertical_scroll_state - .content_length(items.len() as u16); + self.vertical_scroll_state = self.vertical_scroll_state.content_length(items.len()); f.render_stateful_widget( Scrollbar::default() diff --git a/src/ui/components/chat.rs b/src/ui/components/chat.rs index d0f3db5..1b36669 100644 --- a/src/ui/components/chat.rs +++ b/src/ui/components/chat.rs @@ -3,7 +3,6 @@ use std::{collections::VecDeque, slice::Iter}; use chrono::Local; use log::warn; use tui::{ - backend::Backend, layout::{Alignment, Constraint, Direction, Layout, Rect}, style::{Color, Modifier, Style}, text::{Line, Span, Text}, @@ -78,9 +77,9 @@ impl ChatWidget { self.config.borrow().twitch.channel).as_str()).unwrap(); } - pub fn get_messages<'a, B: Backend>( + pub fn get_messages<'a>( &self, - frame: &Frame, + frame: &Frame, area: Rect, messages_data: &'a VecDeque, emotes: &mut Emotes, @@ -211,12 +210,7 @@ impl ChatWidget { } impl Component for ChatWidget { - fn draw( - &mut self, - f: &mut Frame, - area: Option, - emotes: Option<&mut Emotes>, - ) { + fn draw(&mut self, f: &mut Frame, area: Option, emotes: Option<&mut Emotes>) { let mut default_emotes = Emotes::default(); let emotes = emotes.map_or(&mut default_emotes, |e| e); diff --git a/src/ui/components/chat_input.rs b/src/ui/components/chat_input.rs index ca35f0c..362010c 100644 --- a/src/ui/components/chat_input.rs +++ b/src/ui/components/chat_input.rs @@ -1,4 +1,4 @@ -use tui::{backend::Backend, layout::Rect, Frame}; +use tui::{layout::Rect, Frame}; use crate::{ emotes::Emotes, @@ -95,12 +95,7 @@ impl ToString for ChatInputWidget { } impl Component for ChatInputWidget { - fn draw( - &mut self, - f: &mut Frame, - area: Option, - emotes: Option<&mut Emotes>, - ) { + fn draw(&mut self, f: &mut Frame, area: Option, emotes: Option<&mut Emotes>) { self.input.draw(f, area, emotes); } diff --git a/src/ui/components/dashboard.rs b/src/ui/components/dashboard.rs index 00dc8cf..d53f765 100644 --- a/src/ui/components/dashboard.rs +++ b/src/ui/components/dashboard.rs @@ -1,7 +1,6 @@ use std::slice::Iter; use tui::{ - backend::Backend, layout::{Constraint, Direction, Layout, Rect}, style::{Color, Modifier, Style}, terminal::Frame, @@ -79,11 +78,7 @@ impl DashboardWidget { .highlight_style(Style::default().add_modifier(Modifier::ITALIC)) } - fn render_dashboard_title_widget( - &self, - frame: &mut Frame, - v_chunks: &mut Iter, - ) { + fn render_dashboard_title_widget(&self, frame: &mut Frame, v_chunks: &mut Iter) { let w = Paragraph::new( DASHBOARD_TITLE .iter() @@ -95,9 +90,9 @@ impl DashboardWidget { frame.render_widget(w, *v_chunks.next().unwrap()); } - fn render_channel_selection_widget( + fn render_channel_selection_widget( &self, - frame: &mut Frame, + frame: &mut Frame, v_chunks: &mut Iter, current_channel: String, default_channels: &[String], @@ -150,11 +145,7 @@ impl DashboardWidget { } } - fn render_quit_selection_widget( - &self, - frame: &mut Frame, - v_chunks: &mut Iter, - ) { + fn render_quit_selection_widget(&self, frame: &mut Frame, v_chunks: &mut Iter) { let quit_option = Paragraph::new(Line::from(vec![ Span::raw("["), Span::styled("q", Style::default().fg(Color::LightMagenta)), @@ -167,12 +158,7 @@ impl DashboardWidget { } impl Component for DashboardWidget { - fn draw( - &mut self, - f: &mut Frame, - area: Option, - emotes: Option<&mut Emotes>, - ) { + fn draw(&mut self, f: &mut Frame, area: Option, emotes: Option<&mut Emotes>) { let r = area.map_or_else(|| f.size(), |a| a); let favorite_channels_len = { diff --git a/src/ui/components/debug.rs b/src/ui/components/debug.rs index 632a197..5bb8266 100644 --- a/src/ui/components/debug.rs +++ b/src/ui/components/debug.rs @@ -1,6 +1,5 @@ use chrono::{DateTime, Local}; use tui::{ - backend::Backend, layout::{Constraint, Rect}, prelude::Alignment, style::{Color, Modifier, Style}, @@ -57,12 +56,7 @@ impl DebugWidget { } impl Component for DebugWidget { - fn draw( - &mut self, - f: &mut Frame, - area: Option, - _emotes: Option<&mut Emotes>, - ) { + fn draw(&mut self, f: &mut Frame, area: Option, _emotes: Option<&mut Emotes>) { let r = area.map_or_else(|| f.size(), |a| a); let configs = self.get_config_values(); diff --git a/src/ui/components/error.rs b/src/ui/components/error.rs index df5fbab..eb8ae76 100644 --- a/src/ui/components/error.rs +++ b/src/ui/components/error.rs @@ -1,5 +1,4 @@ use tui::{ - backend::Backend, layout::{Alignment, Rect}, style::{Color, Style}, terminal::Frame, @@ -33,12 +32,7 @@ impl ErrorWidget { } impl Component for ErrorWidget { - fn draw( - &mut self, - f: &mut Frame, - area: Option, - _emotes: Option<&mut Emotes>, - ) { + fn draw(&mut self, f: &mut Frame, area: Option, _emotes: Option<&mut Emotes>) { let r = area.map_or_else(|| f.size(), |a| a); let paragraph = Paragraph::new( diff --git a/src/ui/components/following.rs b/src/ui/components/following.rs index a2aff7a..c0d3793 100644 --- a/src/ui/components/following.rs +++ b/src/ui/components/following.rs @@ -1,6 +1,6 @@ use once_cell::sync::Lazy; -use tui::{backend::Backend, layout::Rect, Frame}; +use tui::{layout::Rect, Frame}; use crate::{ emotes::Emotes, @@ -55,12 +55,7 @@ impl FollowingWidget { } impl Component for FollowingWidget { - fn draw( - &mut self, - f: &mut Frame, - area: Option, - emotes: Option<&mut Emotes>, - ) { + fn draw(&mut self, f: &mut Frame, area: Option, emotes: Option<&mut Emotes>) { self.search_widget.draw(f, area, emotes); } diff --git a/src/ui/components/help.rs b/src/ui/components/help.rs index f6cd045..319b7e3 100644 --- a/src/ui/components/help.rs +++ b/src/ui/components/help.rs @@ -1,5 +1,4 @@ use tui::{ - backend::Backend, layout::{Constraint, Rect}, style::{Modifier, Style}, widgets::{Block, Borders, Cell, Row, Table}, @@ -32,12 +31,7 @@ impl HelpWidget { } impl Component for HelpWidget { - fn draw( - &mut self, - f: &mut Frame, - area: Option, - _emotes: Option<&mut Emotes>, - ) { + fn draw(&mut self, f: &mut Frame, area: Option, _emotes: Option<&mut Emotes>) { let r = area.map_or_else(|| f.size(), |a| a); let mut rows = vec![]; diff --git a/src/ui/components/message_search.rs b/src/ui/components/message_search.rs index 34bf9fe..9fa88e5 100644 --- a/src/ui/components/message_search.rs +++ b/src/ui/components/message_search.rs @@ -1,4 +1,4 @@ -use tui::{backend::Backend, layout::Rect, Frame}; +use tui::{layout::Rect, Frame}; use crate::{ emotes::Emotes, @@ -58,12 +58,7 @@ impl ToString for MessageSearchWidget { } impl Component for MessageSearchWidget { - fn draw( - &mut self, - f: &mut Frame, - area: Option, - emotes: Option<&mut Emotes>, - ) { + fn draw(&mut self, f: &mut Frame, area: Option, emotes: Option<&mut Emotes>) { self.input.draw(f, area, emotes); } diff --git a/src/ui/components/mod.rs b/src/ui/components/mod.rs index eb3f936..5340d0b 100644 --- a/src/ui/components/mod.rs +++ b/src/ui/components/mod.rs @@ -23,7 +23,7 @@ use once_cell::sync::Lazy; pub use state_tabs::StateTabsWidget; use chrono::{DateTime, Local}; -use tui::{backend::Backend, layout::Rect, Frame}; +use tui::{layout::Rect, Frame}; use crate::{ emotes::Emotes, @@ -47,12 +47,7 @@ static WINDOW_SIZE_TOO_SMALL_ERROR: Lazy> = Lazy::new(|| { pub trait Component { #[allow(unused_variables)] - fn draw( - &mut self, - f: &mut Frame, - area: Option, - emotes: Option<&mut Emotes>, - ) { + fn draw(&mut self, f: &mut Frame, area: Option, emotes: Option<&mut Emotes>) { todo!() } diff --git a/src/ui/components/state_tabs.rs b/src/ui/components/state_tabs.rs index 408a703..2bb50c0 100644 --- a/src/ui/components/state_tabs.rs +++ b/src/ui/components/state_tabs.rs @@ -1,5 +1,4 @@ use tui::{ - backend::Backend, layout::Rect, style::{Color, Modifier, Style}, symbols::DOT, @@ -25,7 +24,7 @@ impl StateTabsWidget { Self { _config: config } } - pub fn draw(&self, f: &mut Frame, area: Option, state: &State) { + pub fn draw(&self, f: &mut Frame, area: Option, state: &State) { let tab_titles = TABS_TO_RENDER .iter() .map(|t| Line::from(capitalize_first_char(&t.to_string()))) diff --git a/src/ui/components/utils/input_widget.rs b/src/ui/components/utils/input_widget.rs index ffc3d57..7cc0ad5 100644 --- a/src/ui/components/utils/input_widget.rs +++ b/src/ui/components/utils/input_widget.rs @@ -1,6 +1,5 @@ use rustyline::{line_buffer::LineBuffer, At, Word}; use tui::{ - backend::Backend, layout::Rect, style::{Color, Modifier, Style}, text::{Line, Span}, @@ -88,12 +87,7 @@ impl ToString for InputWidget { } impl Component for InputWidget { - fn draw( - &mut self, - f: &mut Frame, - area: Option, - _emotes: Option<&mut Emotes>, - ) { + fn draw(&mut self, f: &mut Frame, area: Option, _emotes: Option<&mut Emotes>) { let r = area.map_or_else(|| centered_rect(60, 60, 20, f.size()), |a| a); let cursor_pos = get_cursor_position(&self.input); diff --git a/src/ui/components/utils/search_widget.rs b/src/ui/components/utils/search_widget.rs index 2e1a869..df89b97 100644 --- a/src/ui/components/utils/search_widget.rs +++ b/src/ui/components/utils/search_widget.rs @@ -4,7 +4,6 @@ use color_eyre::Result; use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher}; use once_cell::sync::Lazy; use tui::{ - backend::Backend, layout::Rect, prelude::{Alignment, Margin}, style::{Color, Modifier, Style}, @@ -108,9 +107,7 @@ where self.list_state.select(Some(i)); self.vertical_scroll = self.vertical_scroll.saturating_add(1); - self.vertical_scroll_state = self - .vertical_scroll_state - .position(self.vertical_scroll as u16); + self.vertical_scroll_state = self.vertical_scroll_state.position(self.vertical_scroll); } fn previous(&mut self) { @@ -121,9 +118,7 @@ where self.list_state.select(Some(i)); self.vertical_scroll = self.vertical_scroll.saturating_sub(1); - self.vertical_scroll_state = self - .vertical_scroll_state - .position(self.vertical_scroll as u16); + self.vertical_scroll_state = self.vertical_scroll_state.position(self.vertical_scroll); } fn unselect(&mut self) { @@ -152,12 +147,7 @@ where T: ToString + Clone, U: SearchItemGetter, { - fn draw( - &mut self, - f: &mut Frame, - area: Option, - emotes: Option<&mut Emotes>, - ) { + fn draw(&mut self, f: &mut Frame, area: Option, emotes: Option<&mut Emotes>) { let r = area.map_or_else(|| centered_rect(60, 60, 20, f.size()), |a| a); if self.error_widget.is_focused() { @@ -236,9 +226,7 @@ where f.render_widget(Clear, r); f.render_stateful_widget(list, r, &mut self.list_state); - self.vertical_scroll_state = self - .vertical_scroll_state - .content_length(items.len() as u16); + self.vertical_scroll_state = self.vertical_scroll_state.content_length(items.len()); f.render_stateful_widget( Scrollbar::default()