diff options
author | extrawurst <mail@rusticorn.com> | 2024-02-20 14:59:33 +0100 |
---|---|---|
committer | extrawurst <776816+extrawurst@users.noreply.github.com> | 2024-02-20 15:41:31 +0100 |
commit | 2b39c6465aa01b06600040053fe3086f92590692 (patch) | |
tree | a02c7fe9ac73c97bf2bc70d97b8aef2a4516db77 /src | |
parent | 45c34e5675e83285f99db77309dd1c6b78fc245f (diff) |
ratatui 0.24 update
Diffstat (limited to 'src')
50 files changed, 107 insertions, 334 deletions
@@ -42,7 +42,6 @@ use asyncgit::{ use crossbeam_channel::Sender; use crossterm::event::{Event, KeyEvent}; use ratatui::{ - backend::Backend, layout::{ Alignment, Constraint, Direction, Layout, Margin, Rect, }, @@ -227,7 +226,7 @@ impl App { } /// - pub fn draw<B: Backend>(&self, f: &mut Frame<B>) -> Result<()> { + pub fn draw(&self, f: &mut Frame) -> Result<()> { let fsize = f.size(); self.cmdbar.borrow_mut().refresh_width(fsize.width); @@ -1070,7 +1069,7 @@ impl App { } //TODO: make this dynamic - fn draw_top_bar<B: Backend>(&self, f: &mut Frame<B>, r: Rect) { + fn draw_top_bar(&self, f: &mut Frame, r: Rect) { const DIVIDER_PAD_SPACES: usize = 2; const SIDE_PADS: usize = 2; const MARGIN_LEFT_AND_RIGHT: usize = 2; diff --git a/src/cmdbar.rs b/src/cmdbar.rs index 2479cc31..790d0f09 100644 --- a/src/cmdbar.rs +++ b/src/cmdbar.rs @@ -3,7 +3,6 @@ use crate::{ ui::style::SharedTheme, }; use ratatui::{ - backend::Backend, layout::{Alignment, Rect}, text::{Line, Span}, widgets::Paragraph, @@ -139,7 +138,7 @@ impl CommandBar { } } - pub fn draw<B: Backend>(&self, f: &mut Frame<B>, r: Rect) { + pub fn draw(&self, f: &mut Frame, r: Rect) { if r.width < MORE_WIDTH { return; } diff --git a/src/components/changes.rs b/src/components/changes.rs index 30c0ab68..e2a32cb0 100644 --- a/src/components/changes.rs +++ b/src/components/changes.rs @@ -17,7 +17,7 @@ use asyncgit::{ StatusItem, StatusItemType, }; use crossterm::event::Event; -use ratatui::{backend::Backend, layout::Rect, Frame}; +use ratatui::{layout::Rect, Frame}; use std::path::Path; /// @@ -187,11 +187,7 @@ impl ChangesComponent { } impl DrawableComponent for ChangesComponent { - fn draw<B: Backend>( - &self, - f: &mut Frame<B>, - r: Rect, - ) -> Result<()> { + fn draw(&self, f: &mut Frame, r: Rect) -> Result<()> { self.files.draw(f, r)?; Ok(()) diff --git a/src/components/commit_details/compare_details.rs b/src/components/commit_details/compare_details.rs index 2e908b2b..e10974f3 100644 --- a/src/components/commit_details/compare_details.rs +++ b/src/components/commit_details/compare_details.rs @@ -18,7 +18,6 @@ use asyncgit::sync::{ }; use crossterm::event::Event; use ratatui::{ - backend::Backend, layout::{Constraint, Direction, Layout, Rect}, text::{Line, Span, Text}, Frame, @@ -102,11 +101,7 @@ impl CompareDetailsComponent { } impl DrawableComponent for CompareDetailsComponent { - fn draw<B: Backend>( - &self, - f: &mut Frame<B>, - rect: Rect, - ) -> Result<()> { + fn draw(&self, f: &mut Frame, rect: Rect) -> Result<()> { let chunks = Layout::default() .direction(Direction::Vertical) .constraints( diff --git a/src/components/commit_details/details.rs b/src/components/commit_details/details.rs index cd24e1df..95e4737e 100644 --- a/src/components/commit_details/details.rs +++ b/src/components/commit_details/details.rs @@ -17,7 +17,6 @@ use asyncgit::sync::{ }; use crossterm::event::Event; use ratatui::{ - backend::Backend, layout::{Constraint, Direction, Layout, Rect}, style::{Modifier, Style}, text::{Line, Span, Text}, @@ -255,11 +254,7 @@ impl DetailsComponent { } impl DrawableComponent for DetailsComponent { - fn draw<B: Backend>( - &self, - f: &mut Frame<B>, - rect: Rect, - ) -> Result<()> { + fn draw(&self, f: &mut Frame, rect: Rect) -> Result<()> { const CANSCROLL_STRING: &str = "[\u{2026}]"; const EMPTY_STRING: &str = ""; diff --git a/src/components/commit_details/mod.rs b/src/components/commit_details/mod.rs index b8a42bcc..229c2a9a 100644 --- a/src/components/commit_details/mod.rs +++ b/src/components/commit_details/mod.rs @@ -21,7 +21,6 @@ use compare_details::CompareDetailsComponent; use crossterm::event::Event; use details::DetailsComponent; use ratatui::{ - backend::Backend, layout::{Constraint, Direction, Layout, Rect}, Frame, }; @@ -140,11 +139,7 @@ impl CommitDetailsComponent { } impl DrawableComponent for CommitDetailsComponent { - fn draw<B: Backend>( - &self, - f: &mut Frame<B>, - rect: Rect, - ) -> Result<()> { + fn draw(&self, f: &mut Frame, rect: Rect) -> Result<()> { if !self.visible { return Ok(()); } diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs index 64e41e89..84f9c3ae 100644 --- a/src/components/commitlist.rs +++ b/src/components/commitlist.rs @@ -22,7 +22,6 @@ use crossterm::event::Event; use indexmap::IndexSet; use itertools::Itertools; use ratatui::{ - backend::Backend, layout::{Alignment, Rect}, style::Style, text::{Line, Span}, @@ -772,11 +771,7 @@ impl CommitList { } impl DrawableComponent for CommitList { - fn draw<B: Backend>( - &self, - f: &mut Frame<B>, - area: Rect, - ) -> Result<()> { + fn draw(&self, f: &mut Frame, area: Rect) -> Result<()> { let current_size = ( area.width.saturating_sub(2), area.height.saturating_sub(2), diff --git a/src/components/cred.rs b/src/components/cred.rs index f801a550..f92d486a 100644 --- a/src/components/cred.rs +++ b/src/components/cred.rs @@ -1,6 +1,6 @@ use anyhow::Result; use crossterm::event::Event; -use ratatui::{backend::Backend, layout::Rect, Frame}; +use ratatui::{layout::Rect, Frame}; use asyncgit::sync::cred::BasicAuthCredential; @@ -60,11 +60,7 @@ impl CredComponent { } impl DrawableComponent for CredComponent { - fn draw<B: Backend>( - &self, - f: &mut Frame<B>, - rect: Rect, - ) -> Result<()> { + fn draw(&self, f: &mut Frame, rect: Rect) -> Result<()> { if self.visible { self.input_username.draw(f, rect)?; self.input_password.draw(f, rect)?; diff --git a/src/components/diff.rs b/src/components/diff.rs index 1c7e0622..c402bc69 100644 --- a/src/components/diff.rs +++ b/src/components/diff.rs @@ -23,7 +23,6 @@ use asyncgit::{ use bytesize::ByteSize; use crossterm::event::Event; use ratatui::{ - backend::Backend, layout::Rect, symbols, text::{Line, Span}, @@ -683,11 +682,7 @@ impl DiffComponent { } impl DrawableComponent for DiffComponent { - fn draw<B: Backend>( - &self, - f: &mut Frame<B>, - r: Rect, - ) -> Result<()> { + fn draw(&self, f: &mut Frame, r: Rect) -> Result<()> { self.current_size.set(( r.width.saturating_sub(2), r.height.saturating_sub(2), diff --git a/src/components/mod.rs b/src/components/mod.rs index 7b2b5a7e..4f1f3f40 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -30,7 +30,6 @@ use crate::ui::style::Theme; use anyhow::Result; use crossterm::event::Event; use ratatui::{ - backend::Backend, layout::{Alignment, Rect}, text::{Span, Text}, widgets::{Block, Borders, Paragraph}, @@ -72,7 +71,7 @@ macro_rules! any_popup_visible { #[macro_export] macro_rules! draw_popups { ($self:ident, [$($element:ident),+]) => { - fn draw_popups<B: Backend>(& $self, mut f: &mut Frame<B>) -> Result<()>{ + fn draw_popups(& $self, mut f: &mut Frame) -> Result<()>{ //TODO: move the layout part out and feed it into `draw_popups` let size = Layout::default() .direction(Direction::Vertical) @@ -176,11 +175,7 @@ pub fn visibility_blocking<T: Component>( /// pub trait DrawableComponent { /// - fn draw<B: Backend>( - &self, - f: &mut Frame<B>, - rect: Rect, - ) -> Result<()>; + fn draw(&self, f: &mut Frame, rect: Rect) -> Result<()>; } /// diff --git a/src/components/revision_files.rs b/src/components/revision_files.rs index d8725619..fdd71866 100644 --- a/src/components/revision_files.rs +++ b/src/components/revision_files.rs @@ -24,7 +24,6 @@ use asyncgit::{ use crossterm::event::Event; use filetreelist::{FileTree, FileTreeItem}; use ratatui::{ - backend::Backend, layout::{Constraint, Direction, Layout, Rect}, text::Span, widgets::{Block, Borders}, @@ -277,11 +276,7 @@ impl RevisionFilesComponent { } } - fn draw_tree<B: Backend>( - &self, - f: &mut Frame<B>, - area: Rect, - ) -> Result<()> { + fn draw_tree(&self, f: &mut Frame, area: Rect) -> Result<()> { let tree_height = usize::from(area.height.saturating_sub(2)); let tree_width = usize::from(area.width); @@ -389,11 +384,7 @@ impl RevisionFilesComponent { } impl DrawableComponent for RevisionFilesComponent { - fn draw<B: Backend>( - &self, - f: &mut Frame<B>, - area: Rect, - ) -> Result<()> { + fn draw(&self, f: &mut Frame, area: Rect) -> Result<()> { if self.is_visible() { let chunks = Layout::default() .direction(Direction::Horizontal) diff --git a/src/components/status_tree.rs b/src/components/status_tree.rs index a3087de3..8aa58ce7 100644 --- a/src/components/status_tree.rs +++ b/src/components/status_tree.rs @@ -17,7 +17,7 @@ use crate::{ use anyhow::Result; use asyncgit::{hash, sync::CommitId, StatusItem, StatusItemType}; use crossterm::event::Event; -use ratatui::{backend::Backend, layout::Rect, text::Span, Frame}; +use ratatui::{layout::Rect, text::Span, Frame}; use std::{borrow::Cow, cell::Cell, path::Path}; //TODO: use new `filetreelist` crate @@ -319,11 +319,7 @@ struct TextDrawInfo<'a> { } impl DrawableComponent for StatusTreeComponent { - fn draw<B: Backend>( - &self, - f: &mut Frame<B>, - r: Rect, - ) -> Result<()> { + fn draw(&self, f: &mut Frame, r: Rect) -> Result<()> { if !self.is_visible() { return Ok(()); } diff --git a/src/components/syntax_text.rs b/src/components/syntax_text.rs index f031fdb6..9da5d2cc 100644 --- a/src/components/syntax_text.rs +++ b/src/components/syntax_text.rs @@ -23,7 +23,6 @@ use crossterm::event::Event; use filetreelist::MoveSelection; use itertools::Either; use ratatui::{ - backend::Backend, layout::Rect, text::Text, widgets::{Block, Borders, Wrap}, @@ -184,11 +183,7 @@ impl SyntaxTextComponent { } impl DrawableComponent for SyntaxTextComponent { - fn draw<B: Backend>( - &self, - f: &mut Frame<B>, - area: Rect, - ) -> Result<()> { + fn draw(&self, f: &mut Frame, area: Rect) -> Result<()> { let text = self.current_file.as_ref().map_or_else( || Text::from(""), |(_, content)| match content { diff --git a/src/components/textinput.rs b/src/components/textinput.rs index 0dfe96a8..a92519b3 100644 --- a/src/components/textinput.rs +++ b/src/components/textinput.rs @@ -14,7 +14,6 @@ use anyhow::Result; use crossterm::event::Event; use ratatui::widgets::{Block, Borders}; use ratatui::{ - backend::Backend, layout::{Alignment, Rect}, widgets::{Clear, Paragraph}, Frame, @@ -197,7 +196,7 @@ impl TextInputComponent { } } - fn draw_char_count<B: Backend>(&self, f: &mut Frame<B>, r: Rect) { + fn draw_char_count(&self, f: &mut Frame, r: Rect) { let count = self.get_text().len(); if count > 0 { let w = Paragraph::new(format!("[{count} chars]")) @@ -611,11 +610,7 @@ impl TextInputComponent { } impl DrawableComponent for TextInputComponent { - fn draw<B: Backend>( - &self, - f: &mut Frame<B>, - rect: Rect, - ) -> Result<()> { + fn draw(&self, f: &mut Frame, rect: Rect) -> Result<()> { // this should always be true since draw should only be being called // is control is visible if let Some(ta) = &self.textarea { diff --git a/src/components/utils/scroll_horizontal.rs b/src/components/utils/scroll_horizontal.rs index 4cfe53b0..67825744 100644 --- a/src/components/utils/scroll_horizontal.rs +++ b/src/components/utils/scroll_horizontal.rs @@ -1,11 +1,9 @@ -use std::cell::Cell; - -use ratatui::{backend::Backend, layout::Rect, Frame}; - use crate::{ components::HorizontalScrollType, ui::{draw_scrollbar, style::SharedTheme, Orientation}, }; +use ratatui::{layout::Rect, Frame}; +use std::cell::Cell; pub struct HorizontalScroll { right: Cell<usize>, @@ -84,12 +82,7 @@ impl HorizontalScroll { self.update(self.get_right(), column_count, visual_width) } - pub fn draw<B: Backend>( - &self, - f: &mut Frame<B>, - r: Rect, - theme: &SharedTheme, - ) { + pub fn draw(&self, f: &mut Frame, r: Rect, theme: &SharedTheme) { draw_scrollbar( f, r, diff --git a/src/components/utils/scroll_vertical.rs b/src/components/utils/scroll_vertical.rs index 70d68eef..d78dcb26 100644 --- a/src/components/utils/scroll_vertical.rs +++ b/src/components/utils/scroll_vertical.rs @@ -1,11 +1,9 @@ -use std::cell::Cell; - -use ratatui::{backend::Backend, layout::Rect, Frame}; - use crate::{ components::ScrollType, ui::{draw_scrollbar, style::SharedTheme, Orientation}, }; +use ratatui::{layout::Rect, Frame}; +use std::cell::Cell; pub struct VerticalScroll { top: Cell<usize>, @@ -109,12 +107,7 @@ impl VerticalScroll { self.update(self.get_top(), line_count, visual_height) } - pub fn draw<B: Backend>( - &self, - f: &mut Frame<B>, - r: Rect, - theme: &SharedTheme, - ) { + pub fn draw(&self, f: &mut Frame, r: Rect, theme: &SharedTheme) { draw_scrollbar( f, r, diff --git a/src/main.rs b/src/main.rs index 96c806d9..f1810a3e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,22 +66,21 @@ use crossterm::{ }; use input::{Input, InputEvent, InputState}; use keys::KeyConfig; -use ratatui::{ - backend::{Backend, CrosstermBackend}, - Terminal, -}; +use ratatui::backend::CrosstermBackend; use scopeguard::defer; use scopetime::scope_time; use spinner::Spinner; use std::{ cell::RefCell, - io::{self, Write}, + io::{self, Stdout}, panic, process, time::{Duration, Instant}, }; use ui::style::Theme; use watcher::RepoWatcher; +type Terminal = ratatui::Terminal<CrosstermBackend<io::Stdout>>; + static TICK_INTERVAL: Duration = Duration::from_secs(5); static SPINNER_INTERVAL: Duration = Duration::from_millis(80); @@ -183,7 +182,7 @@ fn run_app( key_config: KeyConfig, input: &Input, updater: Updater, - terminal: &mut Terminal<CrosstermBackend<io::Stdout>>, + terminal: &mut Terminal, ) -> Result<QuitState, anyhow::Error> { let (tx_git, rx_git) = unbounded(); let (tx_app, rx_app) = unbounded(); @@ -302,10 +301,7 @@ fn shutdown_terminal() { } } -fn draw<B: Backend>( - terminal: &mut Terminal<B>, - app: &App, -) -> io::Result<()> { +fn draw(terminal: &mut Terminal, app: &App) -> io::Result<()> { if app.requires_redraw() { terminal.resize(terminal.size()?)?; } @@ -364,9 +360,7 @@ fn select_event( Ok(ev) } -fn start_terminal<W: Write>( - buf: W, -) -> io::Result<Terminal<CrosstermBackend<W>>> { +fn start_terminal(buf: Stdout) -> io::Result<Terminal> { let backend = CrosstermBackend::new(buf); let mut terminal = Terminal::new(backend)?; terminal.hide_cursor()?; diff --git a/src/popups/blame_file.rs b/src/popups/blame_file.rs index 26366e75..62d1c748 100644 --- a/src/popups/blame_file.rs +++ b/src/popups/blame_file.rs @@ -22,7 +22,6 @@ use asyncgit::{ use crossbeam_channel::Sender; use crossterm::event::Event; use ratatui::{ - backend::Backend, layout::{Constraint, Rect}, symbols::line::VERTICAL, text::{Span, Text}, @@ -101,11 +100,7 @@ pub struct BlameFilePopup { } impl DrawableComponent for BlameFilePopup { - fn draw<B: Backend>( - &self, - f: &mut Frame<B>, - area: Rect, - ) -> Result<()> { + fn draw(&self, f: &mut Frame, area: Rect) -> Result<()> { if self.is_visible() { let title = self.get_title(); diff --git a/src/popups/branchlist.rs b/src/popups/branchlist.rs index 7b36ca60..f7c9b94d 100644 --- a/src/popups/branchlist.rs +++ b/src/popups/branchlist.rs @@ -27,7 +27,6 @@ use asyncgit::{ }; use crossterm::event::{Event, KeyEvent}; use ratatui::{ - backend::Backend, layout::{ Alignment, Constraint, Direction, Layout, Margin, Rect, }, @@ -57,11 +56,7 @@ pub struct BranchListPopup { } impl DrawableComponent for BranchListPopup { - fn draw<B: Backend>( - &self, - f: &mut Frame<B>, - rect: Rect, - ) -> Result<()> { + fn draw(&self, f: &mut Frame, rect: Rect) -> Result<()> { if self.is_visible() { const PERCENT_SIZE: Size = Size::new(80, 50); const MIN_SIZE: Size = Size::new(60, 20); @@ -694,7 +689,7 @@ impl BranchListPopup { Ok(()) } - fn draw_tabs<B: Backend>(&self, f: &mut Frame<B>, r: Rect) { + fn draw_tabs(&self, f: &mut Frame, r: Rect) { let tabs = [Span::raw("Local"), Span::raw("Remote")] .iter() .cloned() @@ -716,11 +711,7 @@ impl BranchListPopup { ); } - fn draw_list<B: Backend>( - &self, - f: &mut Frame<B>, - r: Rect, - ) -> Result<()> { + fn draw_list(&self, f: &mut Frame, r: Rect) -> Result<()> { let height_in_lines = r.height as usize; self.current_height.set(height_in_lines.try_into()?); diff --git a/src/popups/commit.rs b/src/popups/commit.rs index 4bf4a07b..7385c004 100644 --- a/src/popups/commit.rs +++ b/src/popups/commit.rs @@ -22,7 +22,6 @@ use asyncgit::{ use crossterm::event::Event; use easy_cast::Cast; use ratatui::{ - backend::Backend, layout::{Alignment, Rect}, widgets::Paragraph, Frame, @@ -95,7 +94,7 @@ impl CommitPopup { self.git_branch_name.lookup().ok(); } - fn draw_branch_name<B: Backend>(&self, f: &mut Frame<B>) { + fn draw_branch_name(&self, f: &mut Frame) { if let Some(name) = self.git_branch_name.last() { let w = Paragraph::new(format!("{{{name}}}")) .alignment(Alignment::Right); @@ -111,7 +110,7 @@ impl CommitPopup { } < |