From f7af8a3863e8b357748d897d2c6e36aca2577286 Mon Sep 17 00:00:00 2001 From: Josh McKinney Date: Sun, 11 Jun 2023 22:07:15 -0700 Subject: [PATCH] style: reformat imports (#219) Order imports by std, external, crate and group them by crate --- examples/barchart.rs | 11 ++++++----- examples/block.rs | 3 ++- examples/calendar.rs | 5 +---- examples/canvas.rs | 11 ++++++----- examples/chart.rs | 11 ++++++----- examples/custom_widget.rs | 3 ++- examples/demo/crossterm.rs | 14 ++++++++------ examples/demo/main.rs | 7 ++++--- examples/demo/termion.rs | 6 ++++-- examples/demo/termwiz.rs | 3 ++- examples/demo/ui.rs | 5 +++-- examples/gauge.rs | 11 ++++++----- examples/hello_world.rs | 9 +++++---- examples/inline.rs | 17 +++++++++-------- examples/layout.rs | 3 ++- examples/list.rs | 11 ++++++----- examples/panic.rs | 23 ++++++++++++----------- examples/paragraph.rs | 11 ++++++----- examples/popup.rs | 14 +++++++------- examples/sparkline.rs | 11 ++++++----- examples/table.rs | 3 ++- examples/tabs.rs | 3 ++- examples/user_input.rs | 3 ++- rustfmt.toml | 3 ++- src/backend/crossterm.rs | 16 +++++++++------- src/backend/mod.rs | 3 +-- src/backend/termion.rs | 9 +++++---- src/backend/termwiz.rs | 14 ++++++++------ src/backend/test.rs | 12 +++++++----- src/buffer.rs | 14 ++++++++------ src/layout.rs | 18 +++++++++++------- src/style.rs | 3 ++- src/terminal.rs | 3 ++- src/text.rs | 4 +++- src/text/line.rs | 8 +++++--- src/text/masked.rs | 3 ++- src/text/spans.rs | 9 +++++---- src/widgets/barchart.rs | 6 ++++-- src/widgets/calendar.rs | 7 ++++--- src/widgets/canvas/circle.rs | 16 ++++++++++------ src/widgets/canvas/mod.rs | 17 ++++++++++------- src/widgets/chart.rs | 3 +-- src/widgets/list.rs | 6 +++--- src/widgets/mod.rs | 26 ++++++++++++++------------ src/widgets/paragraph.rs | 2 +- src/widgets/reflow.rs | 15 ++++++++------- src/widgets/sparkline.rs | 3 ++- src/widgets/table.rs | 3 ++- tests/terminal.rs | 3 ++- tests/widgets_barchart.rs | 10 ++++++---- tests/widgets_calendar.rs | 1 - tests/widgets_chart.rs | 3 +-- 52 files changed, 247 insertions(+), 191 deletions(-) diff --git a/examples/barchart.rs b/examples/barchart.rs index 0bedc875..54da58b5 100644 --- a/examples/barchart.rs +++ b/examples/barchart.rs @@ -1,3 +1,9 @@ +use std::{ + error::Error, + io, + time::{Duration, Instant}, +}; + use crossterm::{ event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode}, execute, @@ -10,11 +16,6 @@ use ratatui::{ widgets::{BarChart, Block, Borders}, Frame, Terminal, }; -use std::{ - error::Error, - io, - time::{Duration, Instant}, -}; struct App<'a> { data: Vec<(&'a str, u64)>, diff --git a/examples/block.rs b/examples/block.rs index c11a8e61..33cbb01c 100644 --- a/examples/block.rs +++ b/examples/block.rs @@ -1,3 +1,5 @@ +use std::{error::Error, io}; + use crossterm::{ event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode}, execute, @@ -11,7 +13,6 @@ use ratatui::{ widgets::{Block, BorderType, Borders, Padding, Paragraph}, Frame, Terminal, }; -use std::{error::Error, io}; fn main() -> Result<(), Box> { // setup terminal diff --git a/examples/calendar.rs b/examples/calendar.rs index 6736f8e0..d4d051d8 100644 --- a/examples/calendar.rs +++ b/examples/calendar.rs @@ -5,18 +5,15 @@ use crossterm::{ execute, terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, }; - use ratatui::{ backend::{Backend, CrosstermBackend}, layout::{Constraint, Direction, Layout, Rect}, style::{Color, Modifier, Style}, + widgets::calendar::{CalendarEventStore, DateStyler, Monthly}, Frame, Terminal, }; - use time::{Date, Month, OffsetDateTime}; -use ratatui::widgets::calendar::{CalendarEventStore, DateStyler, Monthly}; - fn main() -> Result<(), Box> { enable_raw_mode()?; let mut stdout = io::stdout(); diff --git a/examples/canvas.rs b/examples/canvas.rs index a0d5be72..0c99536d 100644 --- a/examples/canvas.rs +++ b/examples/canvas.rs @@ -1,3 +1,9 @@ +use std::{ + error::Error, + io, + time::{Duration, Instant}, +}; + use crossterm::{ event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode}, execute, @@ -15,11 +21,6 @@ use ratatui::{ }, Frame, Terminal, }; -use std::{ - error::Error, - io, - time::{Duration, Instant}, -}; struct App { x: f64, diff --git a/examples/chart.rs b/examples/chart.rs index b83a98ca..0bfb850d 100644 --- a/examples/chart.rs +++ b/examples/chart.rs @@ -1,3 +1,9 @@ +use std::{ + error::Error, + io, + time::{Duration, Instant}, +}; + use crossterm::{ event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode}, execute, @@ -12,11 +18,6 @@ use ratatui::{ widgets::{Axis, Block, Borders, Chart, Dataset, GraphType}, Frame, Terminal, }; -use std::{ - error::Error, - io, - time::{Duration, Instant}, -}; const DATA: [(f64, f64); 5] = [(0.0, 0.0), (1.0, 1.0), (2.0, 2.0), (3.0, 3.0), (4.0, 4.0)]; const DATA2: [(f64, f64); 7] = [ diff --git a/examples/custom_widget.rs b/examples/custom_widget.rs index 3f79e075..cc58c84f 100644 --- a/examples/custom_widget.rs +++ b/examples/custom_widget.rs @@ -1,3 +1,5 @@ +use std::{error::Error, io}; + use crossterm::{ event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode}, execute, @@ -11,7 +13,6 @@ use ratatui::{ widgets::Widget, Frame, Terminal, }; -use std::{error::Error, io}; #[derive(Default)] struct Label<'a> { diff --git a/examples/demo/crossterm.rs b/examples/demo/crossterm.rs index 34394f3e..b2af0301 100644 --- a/examples/demo/crossterm.rs +++ b/examples/demo/crossterm.rs @@ -1,4 +1,9 @@ -use crate::{app::App, ui}; +use std::{ + error::Error, + io, + time::{Duration, Instant}, +}; + use crossterm::{ event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind}, execute, @@ -8,11 +13,8 @@ use ratatui::{ backend::{Backend, CrosstermBackend}, Terminal, }; -use std::{ - error::Error, - io, - time::{Duration, Instant}, -}; + +use crate::{app::App, ui}; pub fn run(tick_rate: Duration, enhanced_graphics: bool) -> Result<(), Box> { // setup terminal diff --git a/examples/demo/main.rs b/examples/demo/main.rs index 4b4b198e..3fee860d 100644 --- a/examples/demo/main.rs +++ b/examples/demo/main.rs @@ -8,6 +8,10 @@ mod termwiz; mod ui; +use std::{error::Error, time::Duration}; + +use argh::FromArgs; + #[cfg(feature = "crossterm")] use crate::crossterm::run; #[cfg(feature = "termion")] @@ -15,9 +19,6 @@ use crate::termion::run; #[cfg(feature = "termwiz")] use crate::termwiz::run; -use argh::FromArgs; -use std::{error::Error, time::Duration}; - /// Demo #[derive(Debug, FromArgs)] struct Cli { diff --git a/examples/demo/termion.rs b/examples/demo/termion.rs index 70458e4b..8258e98c 100644 --- a/examples/demo/termion.rs +++ b/examples/demo/termion.rs @@ -1,9 +1,9 @@ -use crate::{app::App, ui}; +use std::{error::Error, io, sync::mpsc, thread, time::Duration}; + use ratatui::{ backend::{Backend, TermionBackend}, Terminal, }; -use std::{error::Error, io, sync::mpsc, thread, time::Duration}; use termion::{ event::Key, input::{MouseTerminal, TermRead}, @@ -11,6 +11,8 @@ use termion::{ screen::IntoAlternateScreen, }; +use crate::{app::App, ui}; + pub fn run(tick_rate: Duration, enhanced_graphics: bool) -> Result<(), Box> { // setup terminal let stdout = io::stdout() diff --git a/examples/demo/termwiz.rs b/examples/demo/termwiz.rs index aa7295a0..d49be801 100644 --- a/examples/demo/termwiz.rs +++ b/examples/demo/termwiz.rs @@ -1,9 +1,10 @@ -use ratatui::{backend::TermwizBackend, Terminal}; use std::{ error::Error, io, time::{Duration, Instant}, }; + +use ratatui::{backend::TermwizBackend, Terminal}; use termwiz::{input::*, terminal::Terminal as TermwizTerminal}; use crate::{app::App, ui}; diff --git a/examples/demo/ui.rs b/examples/demo/ui.rs index 7481ec69..96956cba 100644 --- a/examples/demo/ui.rs +++ b/examples/demo/ui.rs @@ -1,18 +1,19 @@ -use crate::app::App; use ratatui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, style::{Color, Modifier, Style}, symbols, text::{Line, Span}, - widgets::canvas::{Canvas, Circle, Line as CanvasLine, Map, MapResolution, Rectangle}, widgets::{ + canvas::{Canvas, Circle, Line as CanvasLine, Map, MapResolution, Rectangle}, Axis, BarChart, Block, Borders, Cell, Chart, Dataset, Gauge, LineGauge, List, ListItem, Paragraph, Row, Sparkline, Table, Tabs, Wrap, }, Frame, }; +use crate::app::App; + pub fn draw(f: &mut Frame, app: &mut App) { let chunks = Layout::default() .constraints([Constraint::Length(3), Constraint::Min(0)].as_ref()) diff --git a/examples/gauge.rs b/examples/gauge.rs index 604d1e3a..85858353 100644 --- a/examples/gauge.rs +++ b/examples/gauge.rs @@ -1,3 +1,9 @@ +use std::{ + error::Error, + io, + time::{Duration, Instant}, +}; + use crossterm::{ event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode}, execute, @@ -11,11 +17,6 @@ use ratatui::{ widgets::{Block, Borders, Gauge}, Frame, Terminal, }; -use std::{ - error::Error, - io, - time::{Duration, Instant}, -}; struct App { progress1: u16, diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 08c04b2e..57e703a8 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -1,3 +1,8 @@ +use std::{ + io::{self, Stdout}, + time::Duration, +}; + use anyhow::{Context, Result}; use crossterm::{ event::{self, Event, KeyCode}, @@ -5,10 +10,6 @@ use crossterm::{ terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, }; use ratatui::{backend::CrosstermBackend, widgets::Paragraph, Terminal}; -use std::{ - io::{self, Stdout}, - time::Duration, -}; /// This is a bare minimum example. There are many approaches to running an application loop, so /// this is not meant to be prescriptive. It is only meant to demonstrate the basic setup and diff --git a/examples/inline.rs b/examples/inline.rs index 2ba834f7..f1dfa905 100644 --- a/examples/inline.rs +++ b/examples/inline.rs @@ -1,3 +1,12 @@ +use std::{ + collections::{BTreeMap, VecDeque}, + error::Error, + io, + sync::mpsc, + thread, + time::{Duration, Instant}, +}; + use rand::distributions::{Distribution, Uniform}; use ratatui::{ backend::{Backend, CrosstermBackend}, @@ -8,14 +17,6 @@ use ratatui::{ widgets::{Block, Gauge, LineGauge, List, ListItem, Paragraph, Widget}, Frame, Terminal, TerminalOptions, Viewport, }; -use std::{ - collections::{BTreeMap, VecDeque}, - error::Error, - io, - sync::mpsc, - thread, - time::{Duration, Instant}, -}; const NUM_DOWNLOADS: usize = 10; diff --git a/examples/layout.rs b/examples/layout.rs index bb9690c5..979321df 100644 --- a/examples/layout.rs +++ b/examples/layout.rs @@ -1,3 +1,5 @@ +use std::{error::Error, io}; + use crossterm::{ event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode}, execute, @@ -9,7 +11,6 @@ use ratatui::{ widgets::{Block, Borders}, Frame, Terminal, }; -use std::{error::Error, io}; fn main() -> Result<(), Box> { // setup terminal diff --git a/examples/list.rs b/examples/list.rs index 10cf7084..66fa60fa 100644 --- a/examples/list.rs +++ b/examples/list.rs @@ -1,3 +1,9 @@ +use std::{ + error::Error, + io, + time::{Duration, Instant}, +}; + use crossterm::{ event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind}, execute, @@ -11,11 +17,6 @@ use ratatui::{ widgets::{Block, Borders, List, ListItem, ListState}, Frame, Terminal, }; -use std::{ - error::Error, - io, - time::{Duration, Instant}, -}; struct StatefulList { state: ListState, diff --git a/examples/panic.rs b/examples/panic.rs index a088a72c..82ae7919 100644 --- a/examples/panic.rs +++ b/examples/panic.rs @@ -17,18 +17,19 @@ #![deny(clippy::all)] #![warn(clippy::pedantic, clippy::nursery)] -use std::error::Error; -use std::io; +use std::{error::Error, io}; -use crossterm::event::{self, Event, KeyCode}; -use crossterm::terminal::{disable_raw_mode, enable_raw_mode}; -use crossterm::terminal::{EnterAlternateScreen, LeaveAlternateScreen}; - -use ratatui::backend::{Backend, CrosstermBackend}; -use ratatui::layout::Alignment; -use ratatui::text::Line; -use ratatui::widgets::{Block, Borders, Paragraph}; -use ratatui::{Frame, Terminal}; +use crossterm::{ + event::{self, Event, KeyCode}, + terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, +}; +use ratatui::{ + backend::{Backend, CrosstermBackend}, + layout::Alignment, + text::Line, + widgets::{Block, Borders, Paragraph}, + Frame, Terminal, +}; type Result = std::result::Result>; diff --git a/examples/paragraph.rs b/examples/paragraph.rs index a0b65a29..add8ce61 100644 --- a/examples/paragraph.rs +++ b/examples/paragraph.rs @@ -1,3 +1,9 @@ +use std::{ + error::Error, + io, + time::{Duration, Instant}, +}; + use crossterm::{ event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode}, execute, @@ -11,11 +17,6 @@ use ratatui::{ widgets::{Block, Borders, Paragraph, Wrap}, Frame, Terminal, }; -use std::{ - error::Error, - io, - time::{Duration, Instant}, -}; struct App { scroll: u16, diff --git a/examples/popup.rs b/examples/popup.rs index 0928c0e8..70edde24 100644 --- a/examples/popup.rs +++ b/examples/popup.rs @@ -1,3 +1,10 @@ +use std::{error::Error, io}; + +use crossterm::{ + event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind}, + execute, + terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, +}; use ratatui::{ backend::{Backend, CrosstermBackend}, layout::{Alignment, Constraint, Direction, Layout, Rect}, @@ -6,13 +13,6 @@ use ratatui::{ widgets::{Block, Borders, Clear, Paragraph, Wrap}, Frame, Terminal, }; -use std::{error::Error, io}; - -use crossterm::{ - event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind}, - execute, - terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, -}; struct App { show_popup: bool, diff --git a/examples/sparkline.rs b/examples/sparkline.rs index ecd2bf31..ef1671c1 100644 --- a/examples/sparkline.rs +++ b/examples/sparkline.rs @@ -1,3 +1,9 @@ +use std::{ + error::Error, + io, + time::{Duration, Instant}, +}; + use crossterm::{ event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode}, execute, @@ -14,11 +20,6 @@ use ratatui::{ widgets::{Block, Borders, Sparkline}, Frame, Terminal, }; -use std::{ - error::Error, - io, - time::{Duration, Instant}, -}; #[derive(Clone)] pub struct RandomSignal { diff --git a/examples/table.rs b/examples/table.rs index e3141f12..b41ea503 100644 --- a/examples/table.rs +++ b/examples/table.rs @@ -1,3 +1,5 @@ +use std::{error::Error, io}; + use crossterm::{ event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind}, execute, @@ -10,7 +12,6 @@ use ratatui::{ widgets::{Block, Borders, Cell, Row, Table, TableState}, Frame, Terminal, }; -use std::{error::Error, io}; struct App<'a> { state: TableState, diff --git a/examples/tabs.rs b/examples/tabs.rs index 8b271ecf..d47c4771 100644 --- a/examples/tabs.rs +++ b/examples/tabs.rs @@ -1,3 +1,5 @@ +use std::{error::Error, io}; + use crossterm::{ event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind}, execute, @@ -11,7 +13,6 @@ use ratatui::{ widgets::{Block, Borders, Tabs}, Frame, Terminal, }; -use std::{error::Error, io}; struct App<'a> { pub titles: Vec<&'a str>, diff --git a/examples/user_input.rs b/examples/user_input.rs index 7088e2d6..767bce39 100644 --- a/examples/user_input.rs +++ b/examples/user_input.rs @@ -1,3 +1,5 @@ +use std::{error::Error, io}; + /// A simple example demonstrating how to handle user input. This is /// a bit out of the scope of the library as it does not provide any /// input handling out of the box. However, it may helps some to get @@ -22,7 +24,6 @@ use ratatui::{ widgets::{Block, Borders, List, ListItem, Paragraph}, Frame, Terminal, }; -use std::{error::Error, io}; use unicode_width::UnicodeWidthStr; enum InputMode { diff --git a/rustfmt.toml b/rustfmt.toml index c5e57a1b..38b953ad 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,4 +1,5 @@ # configuration for https://rust-lang.github.io/rustfmt/ - +group_imports = "StdExternalCrate" +imports_granularity = "Crate" wrap_comments = true comment_width = 100 diff --git a/src/backend/crossterm.rs b/src/backend/crossterm.rs index bdc0e4c6..7a6cb969 100644 --- a/src/backend/crossterm.rs +++ b/src/backend/crossterm.rs @@ -5,12 +5,8 @@ //! [`Backend`]: trait.Backend.html //! [`CrosstermBackend`]: struct.CrosstermBackend.html -use crate::{ - backend::{Backend, ClearType}, - buffer::Cell, - layout::Rect, - style::{Color, Modifier}, -}; +use std::io::{self, Write}; + use crossterm::{ cursor::{Hide, MoveTo, Show}, execute, queue, @@ -20,7 +16,13 @@ use crossterm::{ }, terminal::{self, Clear}, }; -use std::io::{self, Write}; + +use crate::{ + backend::{Backend, ClearType}, + buffer::Cell, + layout::Rect, + style::{Color, Modifier}, +}; /// A backend implementation using the `crossterm` crate. /// diff --git a/src/backend/mod.rs b/src/backend/mod.rs index a098825e..186cf5e0 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -27,8 +27,7 @@ use std::io; -use crate::buffer::Cell; -use crate::layout::Rect; +use crate::{buffer::Cell, layout::Rect}; #[cfg(feature = "termion")] mod termion; diff --git a/src/backend/termion.rs b/src/backend/termion.rs index cbeafcd9..cba51454 100644 --- a/src/backend/termion.rs +++ b/src/backend/termion.rs @@ -4,16 +4,17 @@ //! [`Backend`]: crate::backend::Backend //! [`TermionBackend`]: crate::backend::TermionBackend +use std::{ + fmt, + io::{self, Write}, +}; + use crate::{ backend::{Backend, ClearType}, buffer::Cell, layout::Rect, style::{Color, Modifier}, }; -use std::{ - fmt, - io::{self, Write}, -}; /// A backend that uses the Termion library to draw content, manipulate the cursor, /// and clear the terminal screen. diff --git a/src/backend/termwiz.rs b/src/backend/termwiz.rs index b89bdd8c..3167523e 100644 --- a/src/backend/termwiz.rs +++ b/src/backend/termwiz.rs @@ -4,13 +4,8 @@ //! [`Backend`]: trait.Backend.html //! [`TermwizBackend`]: crate::backend::TermionBackend -use crate::{ - backend::Backend, - buffer::Cell, - layout::Rect, - style::{Color, Modifier}, -}; use std::{error::Error, io}; + use termwiz::{ caps::Capabilities, cell::{AttributeChange, Blink, Intensity, Underline}, @@ -19,6 +14,13 @@ use termwiz::{ terminal::{buffered::BufferedTerminal, SystemTerminal, Terminal}, }; +use crate::{ + backend::Backend, + buffer::Cell, + layout::Rect, + style::{Color, Modifier}, +}; + /// Termwiz backend implementation for the [`Backend`] trait. /// # Example /// diff --git a/src/backend/test.rs b/src/backend/test.rs index 30b965a6..e31dee2a 100644 --- a/src/backend/test.rs +++ b/src/backend/test.rs @@ -1,16 +1,18 @@ //! This module provides the `TestBackend` implementation for the [`Backend`] trait. //! It is used in the integration tests to verify the correctness of the library. +use std::{ + fmt::{Display, Write}, + io, +}; + +use unicode_width::UnicodeWidthStr; + use crate::{ backend::Backend, buffer::{Buffer, Cell}, layout::Rect, }; -use std::{ - fmt::{Display, Write}, - io, -}; -use unicode_width::UnicodeWidthStr; /// A backend used for the integration tests. /// diff --git a/src/buffer.rs b/src/buffer.rs index 1b92cb2f..f9956928 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -1,15 +1,17 @@ +use std::{ + cmp::min, + fmt::{Debug, Formatter, Result}, +}; + +use unicode_segmentation::UnicodeSegmentation; +use unicode_width::UnicodeWidthStr; + #[allow(deprecated)] use crate::{ layout::Rect, style::{Color, Modifier, Style}, text::{Line, Span, Spans}, }; -use std::{ - cmp::min, - fmt::{Debug, Formatter, Result}, -}; -use unicode_segmentation::UnicodeSegmentation; -use unicode_width::UnicodeWidthStr; /// A buffer cell #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/src/layout.rs b/src/layout.rs index 4b88a855..8542b107 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -1,11 +1,15 @@ -use std::cell::RefCell; -use std::cmp::{max, min}; -use std::collections::HashMap; -use std::rc::Rc; +use std::{ + cell::RefCell, + cmp::{max, min}, + collections::HashMap, + rc::Rc, +}; -use cassowary::strength::{MEDIUM, REQUIRED, WEAK}; -use cassowary::WeightedRelation::{EQ, GE, LE}; -use cassowary::{Constraint as CassowaryConstraint, Expression, Solver, Variable}; +use cassowary::{ + strength::{MEDIUM, REQUIRED, WEAK}, + Constraint as CassowaryConstraint, Expression, Solver, Variable, + WeightedRelation::{EQ, GE, LE}, +}; #[derive(Debug, Hash, Clone, Copy, PartialEq, Eq)] pub enum Corner { diff --git a/src/style.rs b/src/style.rs index 8cae24e7..3a25e0bf 100644 --- a/src/style.rs +++ b/src/style.rs @@ -1,11 +1,12 @@ //! `style` contains the primitives used to control how your user interface will look. -use bitflags::bitflags; use std::{ fmt::{self, Debug}, str::FromStr, }; +use bitflags::bitflags; + #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum Color { diff --git a/src/terminal.rs b/src/terminal.rs index de43bdd7..0b38b565 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -1,10 +1,11 @@ +use std::io; + use crate::{ backend::{Backend, ClearType}, buffer::Buffer, layout::Rect, widgets::{StatefulWidget, Widget}, }; -use std::io; #[derive(Debug, Clone, PartialEq, Eq)] pub enum Viewport { diff --git a/src/text.rs b/src/text.rs index 9d555870..07ac0f41 100644 --- a/src/text.rs +++ b/src/text.rs @@ -46,11 +46,13 @@ //! Span::raw(" title"), //! ]); //! ``` -use crate::style::Style; use std::{borrow::Cow, fmt::Debug}; + use unicode_segmentation::UnicodeSegmentation; use unicode_width::UnicodeWidthStr; +use crate::style::Style; + mod line; mod masked; mod spans; diff --git a/src/text/line.rs b/src/text/line.rs index 61167cee..c2f53a87 100644 --- a/src/text/line.rs +++ b/src/text/line.rs @@ -143,9 +143,11 @@ impl<'a> From> for Line<'a> { #[cfg(test)] mod tests { - use crate::layout::Alignment; - use crate::style::{Color, Modifier, Style}; - use crate::text::{Line, Span, Spans}; + use crate::{ + layout::Alignment, + style::{Color, Modifier, Style}, + text::{Line, Span, Spans}, + }; #[test] fn test_width() { diff --git a/src/text/masked.rs b/src/text/masked.rs index 1ee8bb54..133d06ec 100644 --- a/src/text/masked.rs +++ b/src/text/masked.rs @@ -86,9 +86,10 @@ impl<'a> From> for Text<'a> { #[cfg(test)] mod tests { + use std::borrow::Borrow; + use super::*; use crate::text::Line; - use std::borrow::Borrow; #[test] fn test_masked_value() { diff --git a/src/text/spans.rs b/src/text/spans.rs index 65322bb7..f51e2b98 100644 --- a/src/text/spans.rs +++ b/src/text/spans.rs @@ -1,8 +1,7 @@ #![allow(deprecated)] use super::{Span, Style}; -use crate::layout::Alignment; -use crate::text::Line; +use crate::{layout::Alignment, text::Line}; /// A string composed of clusters of graphemes, each with their own style. /// @@ -137,8 +136,10 @@ impl<'a> From> for String { #[cfg(test)] mod tests { - use crate::style::{Color, Modifier, Style}; - use crate::text::{Span, Spans}; + use crate::{ + style::{Color, Modifier, Style}, + text::{Span, Spans}, + }; #[test] fn test_width() { diff --git a/src/widgets/barchart.rs b/src/widgets/barchart.rs index 60679cb7..d829ec9c 100644 --- a/src/widgets/barchart.rs +++ b/src/widgets/barchart.rs @@ -1,3 +1,7 @@ +use std::cmp::min; + +use unicode_width::UnicodeWidthStr; + use crate::{ buffer::Buffer, layout::Rect, @@ -5,8 +9,6 @@ use crate::{ symbols, widgets::{Block, Widget}, }; -use std::cmp::min; -use unicode_width::UnicodeWidthStr; /// Display multiple bars in a single widgets /// diff --git a/src/widgets/calendar.rs b/src/widgets/calendar.rs index 8198fe84..b2136e76 100644 --- a/src/widgets/calendar.rs +++ b/src/widgets/calendar.rs @@ -10,6 +10,8 @@ //! [`Monthly`] has several controls for what should be displayed use std::collections::HashMap; +use time::{Date, Duration, OffsetDateTime}; + use crate::{ buffer::Buffer, layout::Rect, @@ -18,8 +20,6 @@ use crate::{ widgets::{Block, Widget}, }; -use time::{Date, Duration, OffsetDateTime}; - /// Display a month calendar for the month containing `display_date` pub struct Monthly<'a, S: DateStyler> { display_date: Date, @@ -214,9 +214,10 @@ impl Default for CalendarEventStore { #[cfg(test)] mod tests { + use time::Month; + use super::*; use crate::style::Color; - use time::Month; #[test] fn event_store() { diff --git a/src/widgets/canvas/circle.rs b/src/widgets/canvas/circle.rs index db746e71..22b08217 100644 --- a/src/widgets/canvas/circle.rs +++ b/src/widgets/canvas/circle.rs @@ -27,12 +27,16 @@ impl Shape for Circle { #[cfg(test)] mod tests { - use crate::buffer::Buffer; - use crate::layout::Rect; - use crate::style::Color; - use crate::symbols::Marker; - use crate::widgets::canvas::{Canvas, Circle}; - use crate::widgets::Widget; + use crate::{ + buffer::Buffer, + layout::Rect, + style::Color, + symbols::Marker, + widgets::{ + canvas::{Canvas, Circle}, + Widget, + }, + }; #[test] fn test_it_draws_a_circle() { diff --git a/src/widgets/canvas/mod.rs b/src/widgets/canvas/mod.rs index afb7b2b8..7829a81a 100644 --- a/src/widgets/canvas/mod.rs +++ b/src/widgets/canvas/mod.rs @@ -5,12 +5,15 @@ mod points; mod rectangle; mod world; -pub use self::circle::Circle; -pub use self::line::Line; -pub use self::map::{Map, MapResolution}; -pub use self::points::Points; -pub use self::rectangle::Rectangle; +use std::fmt::Debug; +pub use self::{ + circle::Circle, + line::Line, + map::{Map, MapResolution}, + points::Points, + rectangle::Rectangle, +}; use crate::{ buffer::Buffer, layout::Rect, @@ -19,7 +22,6 @@ use crate::{ text::Line as TextLine, widgets::{Block, Widget}, }; -use std::fmt::Debug; /// Interface for all shapes that may be drawn on a Canvas widget. pub trait Shape { @@ -514,9 +516,10 @@ where #[cfg(test)] mod tests { + use indoc::indoc; + use super::*; use crate::{buffer::Cell, symbols::Marker}; - use indoc::indoc; // helper to test the canvas checks that drawing a vertical and horizontal line // results in the expected output diff --git a/src/widgets/chart.rs b/src/widgets/chart.rs index 703b8c7e..761718f3 100644 --- a/src/widgets/chart.rs +++ b/src/widgets/chart.rs @@ -2,10 +2,9 @@ use std::{borrow::Cow, cmp::max}; use unicode_width::UnicodeWidthStr; -use crate::layout::Alignment; use crate::{ buffer::Buffer, - layout::{Constraint, Rect}, + layout::{Alignment, Constraint, Rect}, style::{Color, Style}, symbols, text::{Line as TextLine, Span}, diff --git a/src/widgets/list.rs b/src/widgets/list.rs index a92b8ee2..32189f29 100644 --- a/src/widgets/list.rs +++ b/src/widgets/list.rs @@ -1,3 +1,5 @@ +use unicode_width::UnicodeWidthStr; + use crate::{ buffer::Buffer, layout::{Corner, Rect}, @@ -5,7 +7,6 @@ use crate::{ text::Text, widgets::{Block, StatefulWidget, Widget}, }; -use unicode_width::UnicodeWidthStr; #[derive(Debug, Clone, Default)] pub struct ListState { @@ -294,6 +295,7 @@ impl<'a> Widget for List<'a> { mod tests { use std::borrow::Cow; + use super::*; use crate::{ assert_buffer_eq, style::Color, @@ -301,8 +303,6 @@ mod tests { widgets::{Borders, StatefulWidget, Widget}, }; - use super::*; - #[test] fn test_list_state_selected() { let mut state = ListState::default(); diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index c31d43c8..487edf67 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -33,20 +33,22 @@ mod tabs; use std::fmt::{self, Debug}; -pub use self::barchart::BarChart; -pub use self::block::{Block, BorderType, Padding}; -pub use self::chart::{Axis, Chart, Dataset, GraphType}; -pub use self::clear::Clear; -pub use self::gauge::{Gauge, LineGauge}; -pub use self::list::{List, ListItem, ListState}; -pub use self::paragraph::{Paragraph, Wrap}; -pub use self::sparkline::{RenderDirection, Sparkline}; -pub use self::table::{Cell, Row, Table, TableState}; -pub use self::tabs::Tabs; - -use crate::{buffer::Buffer, layout::Rect}; use bitflags::bitflags; +pub use self::{ + barchart::BarChart, + block::{Block, BorderType, Padding}, + chart::{Axis, Chart, Dataset, GraphType}, + clear::Clear, + gauge::{Gauge, LineGauge}, + list::{List, ListItem, ListState}, + paragraph::{Paragraph, Wrap}, + sparkline::{RenderDirection, Sparkline}, + table::{Cell, Row, Table, TableState}, + tabs::Tabs, +}; +use crate::{buffer::Buffer, layout::Rect}; + bitflags! { /// Bitflags that can be composed to set the visible borders essentially on the block widget. #[derive(Clone, Copy, Default, PartialEq, Eq)] diff --git a/src/widgets/paragraph.rs b/src/widgets/paragraph.rs index 5d252383..1beb1701 100644 --- a/src/widgets/paragraph.rs +++ b/src/widgets/paragraph.rs @@ -200,8 +200,8 @@ impl<'a> Widget for Paragraph<'a> { #[cfg(test)] mod test { use super::*; - use crate::backend::TestBackend; use crate::{ + backend::TestBackend, style::Color, text::{Line, Span}, widgets::Borders, diff --git a/src/widgets/reflow.rs b/src/widgets/reflow.rs index a566577d..94284bfa 100644 --- a/src/widgets/reflow.rs +++ b/src/widgets/reflow.rs @@ -1,11 +1,9 @@ -use std::collections::VecDeque; -use std::vec::IntoIter; +use std::{collections::VecDeque, vec::IntoIter}; use unicode_segmentation::UnicodeSegmentation; use unicode_width::UnicodeWidthStr; -use crate::layout::Alignment; -use crate::text::StyledGrapheme; +use crate::{layout::Alignment, text::StyledGrapheme}; const NBSP: &str = "\u{00a0}"; @@ -323,11 +321,14 @@ fn trim_offset(src: &str, mut offset: usize) -> &str { #[cfg(test)] mod test { - use super::*; - use crate::style::Style; - use crate::text::{Line, Text}; use unicode_segmentation::UnicodeSegmentation; + use super::*; + use crate::{ + style::Style, + text::{Line, Text}, + }; + enum Composer { WordWrapper { trim: bool }, LineTruncator, diff --git a/src/widgets/sparkline.rs b/src/widgets/sparkline.rs index afa427fe..9c362818 100644 --- a/src/widgets/sparkline.rs +++ b/src/widgets/sparkline.rs @@ -1,3 +1,5 @@ +use std::cmp::min; + use crate::{ buffer::Buffer, layout::Rect, @@ -5,7 +7,6 @@ use crate::{ symbols, widgets::{Block, Widget}, }; -use std::cmp::min; /// Widget to render a sparkline over one or more lines. /// diff --git a/src/widgets/table.rs b/src/widgets/table.rs index e57f122f..a8dcc4d6 100644 --- a/src/widgets/table.rs +++ b/src/widgets/table.rs @@ -1,3 +1,5 @@ +use unicode_width::UnicodeWidthStr; + use crate::{ buffer::Buffer, layout::{Constraint, Direction, Layout, Rect}, @@ -5,7 +7,6 @@ use crate::{ text::Text, widgets::{Block, StatefulWidget, Widget}, }; -use unicode_width::UnicodeWidthStr; /// A [`Cell`] contains the [`Text`] to be displayed in a [`Row`] of a [`Table`]. /// diff --git a/tests/terminal.rs b/tests/terminal.rs index c699d641..a090dec2 100644 --- a/tests/terminal.rs +++ b/tests/terminal.rs @@ -1,10 +1,11 @@ +use std::error::Error; + use ratatui::{ backend::{Backend, TestBackend}, layout::Rect, widgets::Paragraph, Terminal, }; -use std::error::Error; #[test] fn terminal_buffer_size_should_be_limited() { diff --git a/tests/widgets_barchart.rs b/tests/widgets_barchart.rs index 9720094f..5711782f 100644 --- a/tests/widgets_barchart.rs +++ b/tests/widgets_barchart.rs @@ -1,7 +1,9 @@ -use ratatui::backend::TestBackend; -use ratatui::buffer::Buffer; -use ratatui::widgets::{BarChart, Block, Borders}; -use ratatui::Terminal; +use ratatui::{ + backend::TestBackend, + buffer::Buffer, + widgets::{BarChart, Block, Borders}, + Terminal, +}; #[test] fn widgets_barchart_not_full_below_max_value() { diff --git a/tests/widgets_calendar.rs b/tests/widgets_calendar.rs index 79d40454..b1ba6479 100644 --- a/tests/widgets_calendar.rs +++ b/tests/widgets_calendar.rs @@ -9,7 +9,6 @@ use ratatui::{ }, Terminal, }; - use time::{Date, Month}; fn test_render(widget: W, expected: Buffer, size: (u16, u16)) { diff --git a/tests/widgets_chart.rs b/tests/widgets_chart.rs index 161326cb..1f4dc9a8 100644 --- a/tests/widgets_chart.rs +++ b/tests/widgets_chart.rs @@ -1,8 +1,7 @@ -use ratatui::layout::Alignment; use ratatui::{ backend::TestBackend, buffer::Buffer, - layout::Rect, + layout::{Alignment, Rect}, style::{Color, Style}, symbols, text::Span,