style: use Module imports_granularity (#1728)

I was swayed by the arguments about this made by the compiler team In
<https://github.com/rust-lang/compiler-team/issues/750> and decided to
look at how this organization affects ratatui. I found this reduces the
number of lines across the codebase by about 350 and makes the imports
more readable and definitely more greppable as you usually only have
to read a single line. I've found in the past that maintaining imports
regularly leads to merge conflicts which have to be resolved by hand
and this change should reduce the likelihood of that happening.

Main change is in rustfmt.toml, and the rest is just the result of
running `cargo xtask format`.

While implementing this, cargo machete brings up that the various
backend crates are unused by the example crates.

The re-export of each backend crate under ratatui is to make it possible
for libs that rely on a specific version of ratatui to use the same
version of the backend crate. Apps in general should use the backend
crate directly rather than through ratatui as this is less confusing.

- Removes all usages of `ratatui::{crossterm, termion, termwiz}`` in the
  examples.
- Adds the backend crate to the dependencies of the examples that use
  the backend crate directly.
This commit is contained in:
Josh McKinney 2025-03-19 16:48:02 -07:00 committed by GitHub
parent dca331c748
commit 2739391950
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
148 changed files with 1295 additions and 1640 deletions

5
Cargo.lock generated
View File

@ -579,6 +579,7 @@ name = "colors-rgb"
version = "0.0.0"
dependencies = [
"color-eyre",
"crossterm",
"palette",
"ratatui",
]
@ -821,8 +822,11 @@ name = "demo"
version = "0.0.0"
dependencies = [
"clap",
"crossterm",
"rand 0.9.0",
"ratatui",
"termion",
"termwiz",
]
[[package]]
@ -2635,6 +2639,7 @@ version = "0.3.0-alpha.2"
dependencies = [
"bitflags 2.9.0",
"color-eyre",
"crossterm",
"document-features",
"indoc",
"instability",

View File

@ -13,13 +13,11 @@ use std::time::{Duration, Instant};
use color_eyre::Result;
use crossterm::event::{self, Event, KeyCode};
use ratatui::{
buffer::Buffer,
layout::{Constraint, Layout, Position, Rect, Size},
style::{Color, Style},
widgets::{Widget, WidgetRef},
DefaultTerminal,
};
use ratatui::buffer::Buffer;
use ratatui::layout::{Constraint, Layout, Position, Rect, Size};
use ratatui::style::{Color, Style};
use ratatui::widgets::{Widget, WidgetRef};
use ratatui::DefaultTerminal;
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -27,25 +27,20 @@
//! [Ratatui]: https://github.com/ratatui/ratatui
//! [examples]: https://github.com/ratatui/ratatui/blob/main/examples
//! [examples readme]: https://github.com/ratatui/ratatui/blob/main/examples/README.md
use std::{
sync::{Arc, RwLock},
time::Duration,
};
use std::sync::{Arc, RwLock};
use std::time::Duration;
use color_eyre::Result;
use octocrab::{
params::{pulls::Sort, Direction},
Page,
};
use ratatui::{
buffer::Buffer,
crossterm::event::{Event, EventStream, KeyCode, KeyEventKind},
layout::{Constraint, Layout, Rect},
style::{Style, Stylize},
text::Line,
widgets::{Block, HighlightSpacing, Row, StatefulWidget, Table, TableState, Widget},
DefaultTerminal, Frame,
};
use crossterm::event::{Event, EventStream, KeyCode, KeyEventKind};
use octocrab::params::pulls::Sort;
use octocrab::params::Direction;
use octocrab::Page;
use ratatui::buffer::Buffer;
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::style::{Style, Stylize};
use ratatui::text::Line;
use ratatui::widgets::{Block, HighlightSpacing, Row, StatefulWidget, Table, TableState, Widget};
use ratatui::{DefaultTerminal, Frame};
use tokio_stream::StreamExt;
#[tokio::main]

View File

@ -12,14 +12,13 @@ use std::fmt;
use color_eyre::Result;
use crossterm::event::{self, Event, KeyCode, KeyEventKind};
use ratatui::{
layout::{Constraint, Layout, Margin, Rect},
style::{Color, Modifier, Style, Stylize},
text::{Line, Text},
widgets::calendar::{CalendarEventStore, Monthly},
DefaultTerminal, Frame,
};
use time::{ext::NumericalDuration, Date, Month, OffsetDateTime};
use ratatui::layout::{Constraint, Layout, Margin, Rect};
use ratatui::style::{Color, Modifier, Style, Stylize};
use ratatui::text::{Line, Text};
use ratatui::widgets::calendar::{CalendarEventStore, Monthly};
use ratatui::{DefaultTerminal, Frame};
use time::ext::NumericalDuration;
use time::{Date, Month, OffsetDateTime};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -14,23 +14,18 @@ use std::{
};
use color_eyre::Result;
use crossterm::{
event::{DisableMouseCapture, EnableMouseCapture, KeyEventKind},
ExecutableCommand,
use crossterm::event::{
self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind, MouseEventKind,
};
use crossterm::ExecutableCommand;
use itertools::Itertools;
use ratatui::{
crossterm::event::{self, Event, KeyCode, MouseEventKind},
layout::{Constraint, Layout, Position, Rect},
style::{Color, Stylize},
symbols::Marker,
text::Text,
widgets::{
canvas::{Canvas, Circle, Map, MapResolution, Points, Rectangle},
Block, Widget,
},
DefaultTerminal, Frame,
};
use ratatui::layout::{Constraint, Layout, Position, Rect};
use ratatui::style::{Color, Stylize};
use ratatui::symbols::Marker;
use ratatui::text::Text;
use ratatui::widgets::canvas::{Canvas, Circle, Map, MapResolution, Points, Rectangle};
use ratatui::widgets::{Block, Widget};
use ratatui::{DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -11,15 +11,13 @@
use std::time::{Duration, Instant};
use color_eyre::Result;
use ratatui::{
crossterm::event::{self, Event, KeyCode},
layout::{Constraint, Layout, Rect},
style::{Color, Modifier, Style, Stylize},
symbols::{self, Marker},
text::{Line, Span},
widgets::{Axis, Block, Chart, Dataset, GraphType, LegendPosition},
DefaultTerminal, Frame,
};
use crossterm::event::{self, Event, KeyCode};
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::style::{Color, Modifier, Style, Stylize};
use ratatui::symbols::{self, Marker};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Axis, Block, Chart, Dataset, GraphType, LegendPosition};
use ratatui::{DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -9,15 +9,13 @@
//! [`latest`]: https://github.com/ratatui/ratatui/tree/latest
use color_eyre::Result;
use crossterm::event::{self, Event, KeyCode, KeyEventKind};
use itertools::Itertools;
use ratatui::{
crossterm::event::{self, Event, KeyCode, KeyEventKind},
layout::{Alignment, Constraint, Layout, Rect},
style::{Color, Style, Stylize},
text::Line,
widgets::{Block, Borders, Paragraph},
DefaultTerminal, Frame,
};
use ratatui::layout::{Alignment, Constraint, Layout, Rect};
use ratatui::style::{Color, Style, Stylize};
use ratatui::text::Line;
use ratatui::widgets::{Block, Borders, Paragraph};
use ratatui::{DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -7,6 +7,7 @@ rust-version.workspace = true
[dependencies]
color-eyre.workspace = true
crossterm.workspace = true
palette = "0.7.6"
ratatui.workspace = true

View File

@ -19,16 +19,15 @@
use std::time::{Duration, Instant};
use color_eyre::Result;
use palette::{convert::FromColorUnclamped, Okhsv, Srgb};
use ratatui::{
buffer::Buffer,
crossterm::event::{self, Event, KeyCode, KeyEventKind},
layout::{Constraint, Layout, Position, Rect},
style::Color,
text::Text,
widgets::Widget,
DefaultTerminal,
};
use crossterm::event::{self, Event, KeyCode, KeyEventKind};
use palette::convert::FromColorUnclamped;
use palette::{Okhsv, Srgb};
use ratatui::buffer::Buffer;
use ratatui::layout::{Constraint, Layout, Position, Rect};
use ratatui::style::Color;
use ratatui::text::Text;
use ratatui::widgets::Widget;
use ratatui::DefaultTerminal;
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -9,23 +9,17 @@
///
/// [`latest`]: https://github.com/ratatui/ratatui/tree/latest
use color_eyre::Result;
use crossterm::event::{self, Event, KeyCode, KeyEventKind};
use itertools::Itertools;
use ratatui::{
buffer::Buffer,
crossterm::event::{self, Event, KeyCode, KeyEventKind},
layout::{
Constraint::{self, Fill, Length, Max, Min, Percentage, Ratio},
Flex, Layout, Rect,
},
style::{
palette::tailwind::{BLUE, SKY, SLATE, STONE},
Color, Style, Stylize,
},
symbols::{self, line},
text::{Line, Span, Text},
widgets::{Block, Paragraph, Widget, Wrap},
DefaultTerminal,
};
use ratatui::buffer::Buffer;
use ratatui::layout::Constraint::{self, Fill, Length, Max, Min, Percentage, Ratio};
use ratatui::layout::{Flex, Layout, Rect};
use ratatui::style::palette::tailwind::{BLUE, SKY, SLATE, STONE};
use ratatui::style::{Color, Style, Stylize};
use ratatui::symbols::{self, line};
use ratatui::text::{Line, Span, Text};
use ratatui::widgets::{Block, Paragraph, Widget, Wrap};
use ratatui::DefaultTerminal;
use strum::{Display, EnumIter, FromRepr};
fn main() -> Result<()> {

View File

@ -6,22 +6,18 @@
///
/// [`latest`]: https://github.com/ratatui/ratatui/tree/latest
use color_eyre::Result;
use ratatui::{
buffer::Buffer,
crossterm::event::{self, Event, KeyCode, KeyEventKind},
layout::{
Constraint::{self, Fill, Length, Max, Min, Percentage, Ratio},
Layout, Rect,
},
style::{palette::tailwind, Color, Modifier, Style, Stylize},
symbols,
text::Line,
widgets::{
Block, Padding, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget,
Tabs, Widget,
},
DefaultTerminal,
use crossterm::event::{self, Event, KeyCode, KeyEventKind};
use ratatui::buffer::Buffer;
use ratatui::layout::Constraint::{self, Fill, Length, Max, Min, Percentage, Ratio};
use ratatui::layout::{Layout, Rect};
use ratatui::style::palette::tailwind;
use ratatui::style::{Color, Modifier, Style, Stylize};
use ratatui::text::Line;
use ratatui::widgets::{
Block, Padding, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget,
Tabs, Widget,
};
use ratatui::{symbols, DefaultTerminal};
use strum::{Display, EnumIter, FromRepr, IntoEnumIterator};
const SPACER_HEIGHT: u16 = 0;

View File

@ -9,21 +9,17 @@
use std::{io::stdout, ops::ControlFlow, time::Duration};
use color_eyre::Result;
use ratatui::{
buffer::Buffer,
crossterm::{
event::{
self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, MouseButton, MouseEvent,
MouseEventKind,
},
execute,
},
layout::{Constraint, Layout, Rect},
style::{Color, Style},
text::Line,
widgets::{Paragraph, Widget},
DefaultTerminal, Frame,
use crossterm::event::{
self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, MouseButton, MouseEvent,
MouseEventKind,
};
use crossterm::execute;
use ratatui::buffer::Buffer;
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::style::{Color, Style};
use ratatui::text::Line;
use ratatui::widgets::{Paragraph, Widget};
use ratatui::{DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -7,11 +7,16 @@ rust-version.workspace = true
[features]
default = ["crossterm"]
crossterm = ["ratatui/crossterm"]
termion = ["ratatui/termion"]
termwiz = ["ratatui/termwiz"]
crossterm = ["ratatui/crossterm", "dep:crossterm"]
termion = ["ratatui/termion", "dep:termion"]
termwiz = ["ratatui/termwiz", "dep:termwiz"]
[dependencies]
clap = { version = "4.5.32", features = ["derive"] }
crossterm = { workspace = true, optional = true }
rand = "0.9.0"
ratatui.workspace = true
termwiz = { workspace = true, optional = true }
[target.'cfg(not(windows))'.dependencies]
termion = { workspace = true, optional = true }

View File

@ -1,7 +1,5 @@
use rand::{
distr::{Distribution, Uniform},
rngs::ThreadRng,
};
use rand::distr::{Distribution, Uniform};
use rand::rngs::ThreadRng;
use ratatui::widgets::ListState;
const TASKS: [&str; 24] = [

View File

@ -1,20 +1,19 @@
use std::{
error::Error,
io,
time::{Duration, Instant},
};
use std::error::Error;
use std::io;
use std::time::{Duration, Instant};
use ratatui::{
backend::{Backend, CrosstermBackend},
crossterm::{
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind},
execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
},
Terminal,
use crossterm::event::{
self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind,
};
use crossterm::execute;
use crossterm::terminal::{
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen,
};
use ratatui::backend::{Backend, CrosstermBackend};
use ratatui::Terminal;
use crate::{app::App, ui};
use crate::app::App;
use crate::ui;
pub fn run(tick_rate: Duration, enhanced_graphics: bool) -> Result<(), Box<dyn Error>> {
// setup terminal

View File

@ -13,7 +13,8 @@
//! [examples]: https://github.com/ratatui/ratatui/blob/main/examples
//! [examples readme]: https://github.com/ratatui/ratatui/blob/main/examples/README.md
use std::{error::Error, time::Duration};
use std::error::Error;
use std::time::Duration;
use clap::Parser;

View File

@ -1,18 +1,18 @@
#![allow(dead_code)]
use std::{error::Error, io, sync::mpsc, thread, time::Duration};
use std::error::Error;
use std::sync::mpsc;
use std::time::Duration;
use std::{io, thread};
use ratatui::{
backend::{Backend, TermionBackend},
termion::{
event::Key,
input::{MouseTerminal, TermRead},
raw::IntoRawMode,
screen::IntoAlternateScreen,
},
Terminal,
};
use ratatui::backend::{Backend, TermionBackend};
use ratatui::Terminal;
use termion::event::Key;
use termion::input::{MouseTerminal, TermRead};
use termion::raw::IntoRawMode;
use termion::screen::IntoAlternateScreen;
use crate::{app::App, ui};
use crate::app::App;
use crate::ui;
pub fn run(tick_rate: Duration, enhanced_graphics: bool) -> Result<(), Box<dyn Error>> {
// setup terminal

View File

@ -1,19 +1,14 @@
#![allow(dead_code)]
use std::{
error::Error,
time::{Duration, Instant},
};
use std::error::Error;
use std::time::{Duration, Instant};
use ratatui::{
backend::TermwizBackend,
termwiz::{
input::{InputEvent, KeyCode},
terminal::Terminal as TermwizTerminal,
},
Terminal,
};
use ratatui::backend::TermwizBackend;
use ratatui::Terminal;
use termwiz::input::{InputEvent, KeyCode};
use termwiz::terminal::Terminal as TermwizTerminal;
use crate::{app::App, ui};
use crate::app::App;
use crate::ui;
pub fn run(tick_rate: Duration, enhanced_graphics: bool) -> Result<(), Box<dyn Error>> {
let backend = TermwizBackend::new()?;

View File

@ -1,15 +1,12 @@
use ratatui::{
layout::{Constraint, Layout, Rect},
style::{Color, Modifier, Style},
symbols,
text::{self, Span},
widgets::{
canvas::{self, Canvas, Circle, Map, MapResolution, Rectangle},
Axis, BarChart, Block, Cell, Chart, Dataset, Gauge, LineGauge, List, ListItem, Paragraph,
Row, Sparkline, Table, Tabs, Wrap,
},
Frame,
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::style::{Color, Modifier, Style};
use ratatui::text::{self, Span};
use ratatui::widgets::canvas::{self, Canvas, Circle, Map, MapResolution, Rectangle};
use ratatui::widgets::{
Axis, BarChart, Block, Cell, Chart, Dataset, Gauge, LineGauge, List, ListItem, Paragraph, Row,
Sparkline, Table, Tabs, Wrap,
};
use ratatui::{symbols, Frame};
use crate::app::App;

View File

@ -1,24 +1,20 @@
use std::time::Duration;
use color_eyre::{eyre::Context, Result};
use color_eyre::eyre::Context;
use color_eyre::Result;
use crossterm::event;
use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind};
use itertools::Itertools;
use ratatui::{
buffer::Buffer,
crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind},
layout::{Constraint, Layout, Rect},
style::Color,
text::{Line, Span},
widgets::{Block, Tabs, Widget},
DefaultTerminal, Frame,
};
use ratatui::buffer::Buffer;
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::style::Color;
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, Tabs, Widget};
use ratatui::{DefaultTerminal, Frame};
use strum::{Display, EnumIter, FromRepr, IntoEnumIterator};
use crate::{
destroy,
tabs::{AboutTab, EmailTab, RecipeTab, TracerouteTab, WeatherTab},
THEME,
};
use crate::tabs::{AboutTab, EmailTab, RecipeTab, TracerouteTab, WeatherTab};
use crate::{destroy, THEME};
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct App {

View File

@ -1,5 +1,8 @@
use palette::{IntoColor, Okhsv, Srgb};
use ratatui::{buffer::Buffer, layout::Rect, style::Color, widgets::Widget};
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::style::Color;
use ratatui::widgets::Widget;
/// A widget that renders a color swatch of RGB colors.
///

View File

@ -1,13 +1,11 @@
use rand::Rng;
use rand_chacha::rand_core::SeedableRng;
use ratatui::{
buffer::Buffer,
layout::{Flex, Layout, Rect},
style::{Color, Style},
text::Text,
widgets::Widget,
Frame,
};
use ratatui::buffer::Buffer;
use ratatui::layout::{Flex, Layout, Rect};
use ratatui::style::{Color, Style};
use ratatui::text::Text;
use ratatui::widgets::Widget;
use ratatui::Frame;
/// delay the start of the animation so it doesn't start immediately
const DELAY: usize = 120;

View File

@ -29,16 +29,13 @@ use std::io::stdout;
use app::App;
use color_eyre::Result;
use crossterm::{
execute,
terminal::{EnterAlternateScreen, LeaveAlternateScreen},
};
use ratatui::{layout::Rect, TerminalOptions, Viewport};
use crossterm::execute;
use crossterm::terminal::{EnterAlternateScreen, LeaveAlternateScreen};
use ratatui::layout::Rect;
use ratatui::{TerminalOptions, Viewport};
pub use self::{
colors::{color_from_oklab, RgbSwatch},
theme::THEME,
};
pub use self::colors::{color_from_oklab, RgbSwatch};
pub use self::theme::THEME;
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -1,9 +1,7 @@
use ratatui::{
buffer::Buffer,
layout::{Alignment, Constraint, Layout, Margin, Rect},
widgets::{
Block, Borders, Clear, MascotEyeColor, Padding, Paragraph, RatatuiMascot, Widget, Wrap,
},
use ratatui::buffer::Buffer;
use ratatui::layout::{Alignment, Constraint, Layout, Margin, Rect};
use ratatui::widgets::{
Block, Borders, Clear, MascotEyeColor, Padding, Paragraph, RatatuiMascot, Widget, Wrap,
};
use crate::{RgbSwatch, THEME};

View File

@ -1,13 +1,11 @@
use itertools::Itertools;
use ratatui::{
buffer::Buffer,
layout::{Constraint, Layout, Margin, Rect},
style::{Styled, Stylize},
text::Line,
widgets::{
Block, BorderType, Borders, Clear, List, ListItem, ListState, Padding, Paragraph,
Scrollbar, ScrollbarState, StatefulWidget, Tabs, Widget,
},
use ratatui::buffer::Buffer;
use ratatui::layout::{Constraint, Layout, Margin, Rect};
use ratatui::style::{Styled, Stylize};
use ratatui::text::Line;
use ratatui::widgets::{
Block, BorderType, Borders, Clear, List, ListItem, ListState, Padding, Paragraph, Scrollbar,
ScrollbarState, StatefulWidget, Tabs, Widget,
};
use unicode_width::UnicodeWidthStr;

View File

@ -1,13 +1,11 @@
use itertools::Itertools;
use ratatui::{
buffer::Buffer,
layout::{Alignment, Constraint, Layout, Margin, Rect},
style::{Style, Stylize},
text::Line,
widgets::{
Block, Clear, Padding, Paragraph, Row, Scrollbar, ScrollbarOrientation, ScrollbarState,
StatefulWidget, Table, TableState, Widget, Wrap,
},
use ratatui::buffer::Buffer;
use ratatui::layout::{Alignment, Constraint, Layout, Margin, Rect};
use ratatui::style::{Style, Stylize};
use ratatui::text::Line;
use ratatui::widgets::{
Block, Clear, Padding, Paragraph, Row, Scrollbar, ScrollbarOrientation, ScrollbarState,
StatefulWidget, Table, TableState, Widget, Wrap,
};
use crate::{RgbSwatch, THEME};

View File

@ -1,14 +1,12 @@
use itertools::Itertools;
use ratatui::{
buffer::Buffer,
layout::{Alignment, Constraint, Layout, Margin, Rect},
style::{Styled, Stylize},
symbols::Marker,
widgets::{
canvas::{self, Canvas, Map, MapResolution, Points},
Block, BorderType, Clear, Padding, Row, Scrollbar, ScrollbarOrientation, ScrollbarState,
Sparkline, StatefulWidget, Table, TableState, Widget,
},
use ratatui::buffer::Buffer;
use ratatui::layout::{Alignment, Constraint, Layout, Margin, Rect};
use ratatui::style::{Styled, Stylize};
use ratatui::symbols::Marker;
use ratatui::widgets::canvas::{self, Canvas, Map, MapResolution, Points};
use ratatui::widgets::{
Block, BorderType, Clear, Padding, Row, Scrollbar, ScrollbarOrientation, ScrollbarState,
Sparkline, StatefulWidget, Table, TableState, Widget,
};
use crate::{RgbSwatch, THEME};

View File

@ -1,15 +1,11 @@
use itertools::Itertools;
use palette::Okhsv;
use ratatui::{
buffer::Buffer,
layout::{Constraint, Direction, Layout, Margin, Rect},
style::{Color, Style, Stylize},
symbols,
widgets::{
calendar::{CalendarEventStore, Monthly},
Bar, BarChart, BarGroup, Block, Clear, LineGauge, Padding, Widget,
},
};
use ratatui::buffer::Buffer;
use ratatui::layout::{Constraint, Direction, Layout, Margin, Rect};
use ratatui::style::{Color, Style, Stylize};
use ratatui::symbols;
use ratatui::widgets::calendar::{CalendarEventStore, Monthly};
use ratatui::widgets::{Bar, BarChart, BarGroup, Block, Clear, LineGauge, Padding, Widget};
use time::OffsetDateTime;
use crate::{color_from_oklab, RgbSwatch, THEME};

View File

@ -11,23 +11,18 @@
use std::num::NonZeroUsize;
use color_eyre::Result;
use ratatui::{
buffer::Buffer,
crossterm::event::{self, Event, KeyCode, KeyEventKind},
layout::{
Alignment,
Constraint::{self, Fill, Length, Max, Min, Percentage, Ratio},
Flex, Layout, Rect,
},
style::{palette::tailwind, Color, Modifier, Style, Stylize},
symbols::{self, line},
text::{Line, Text},
widgets::{
Block, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget, Tabs,
Widget,
},
DefaultTerminal,
use crossterm::event::{self, Event, KeyCode, KeyEventKind};
use ratatui::buffer::Buffer;
use ratatui::layout::Constraint::{self, Fill, Length, Max, Min, Percentage, Ratio};
use ratatui::layout::{Alignment, Flex, Layout, Rect};
use ratatui::style::palette::tailwind;
use ratatui::style::{Color, Modifier, Style, Stylize};
use ratatui::symbols::{self, line};
use ratatui::text::{Line, Text};
use ratatui::widgets::{
Block, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget, Tabs, Widget,
};
use ratatui::DefaultTerminal;
use strum::{Display, EnumIter, FromRepr, IntoEnumIterator};
fn main() -> Result<()> {

View File

@ -8,15 +8,14 @@
use std::time::Duration;
use color_eyre::Result;
use ratatui::{
buffer::Buffer,
crossterm::event::{self, Event, KeyCode, KeyEventKind},
layout::{Alignment, Constraint, Layout, Rect},
style::{palette::tailwind, Color, Style, Stylize},
text::{Line, Span},
widgets::{Block, Borders, Gauge, Padding, Paragraph, Widget},
DefaultTerminal,
};
use crossterm::event::{self, Event, KeyCode, KeyEventKind};
use ratatui::buffer::Buffer;
use ratatui::layout::{Alignment, Constraint, Layout, Rect};
use ratatui::style::palette::tailwind;
use ratatui::style::{Color, Style, Stylize};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, Borders, Gauge, Padding, Paragraph, Widget};
use ratatui::DefaultTerminal;
const GAUGE1_COLOR: Color = tailwind::RED.c800;
const GAUGE2_COLOR: Color = tailwind::GREEN.c800;

View File

@ -7,12 +7,11 @@
/// [`latest`]: https://github.com/ratatui/ratatui/tree/latest
use std::time::Duration;
use color_eyre::{eyre::Context, Result};
use ratatui::{
crossterm::event::{self, Event, KeyCode},
widgets::Paragraph,
DefaultTerminal, Frame,
};
use color_eyre::eyre::Context;
use color_eyre::Result;
use crossterm::event::{self, Event, KeyCode};
use ratatui::widgets::Paragraph;
use ratatui::{DefaultTerminal, Frame};
/// 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

View File

@ -7,16 +7,14 @@
/// [`latest`]: https://github.com/ratatui/ratatui/tree/latest
/// [OSC 8]: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
use color_eyre::Result;
use crossterm::event::{self, Event, KeyCode};
use itertools::Itertools;
use ratatui::{
buffer::Buffer,
crossterm::event::{self, Event, KeyCode},
layout::Rect,
style::Stylize,
text::{Line, Text},
widgets::Widget,
DefaultTerminal,
};
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::style::Stylize;
use ratatui::text::{Line, Text};
use ratatui::widgets::Widget;
use ratatui::DefaultTerminal;
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -15,17 +15,14 @@ use std::{
};
use color_eyre::Result;
use crossterm::event;
use rand::distr::{Distribution, Uniform};
use ratatui::{
backend::Backend,
crossterm::event,
layout::{Constraint, Layout, Rect},
style::{Color, Modifier, Style},
symbols,
text::{Line, Span},
widgets::{Block, Gauge, LineGauge, List, ListItem, Paragraph, Widget},
Frame, Terminal, TerminalOptions, Viewport,
};
use ratatui::backend::Backend;
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::style::{Color, Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, Gauge, LineGauge, List, ListItem, Paragraph, Widget};
use ratatui::{symbols, Frame, Terminal, TerminalOptions, Viewport};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -16,14 +16,12 @@
use color_eyre::Result;
use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind};
use ratatui::{
buffer::Buffer,
layout::{Constraint, Layout, Offset, Rect},
style::Stylize,
text::Line,
widgets::Widget,
DefaultTerminal, Frame,
};
use ratatui::buffer::Buffer;
use ratatui::layout::{Constraint, Layout, Offset, Rect};
use ratatui::style::Stylize;
use ratatui::text::Line;
use ratatui::widgets::Widget;
use ratatui::{DefaultTerminal, Frame};
use serde::Serialize;
fn main() -> Result<()> {

View File

@ -12,7 +12,8 @@
/// [examples]: https://github.com/ratatui/ratatui/blob/main/examples
/// [hello-world]: https://github.com/ratatui/ratatui/blob/main/examples/apps/hello-world
use crossterm::event::{self, Event};
use ratatui::{text::Text, Frame};
use ratatui::text::Text;
use ratatui::Frame;
fn main() {
let mut terminal = ratatui::init();

View File

@ -10,15 +10,13 @@
/// [`latest`]: https://github.com/ratatui/ratatui/tree/latest
use std::{error::Error, iter::once, result};
use crossterm::event::{self, Event, KeyCode, KeyEventKind};
use itertools::Itertools;
use ratatui::{
crossterm::event::{self, Event, KeyCode, KeyEventKind},
layout::{Constraint, Layout},
style::{Color, Modifier, Style, Stylize},
text::Line,
widgets::Paragraph,
DefaultTerminal, Frame,
};
use ratatui::layout::{Constraint, Layout};
use ratatui::style::{Color, Modifier, Style, Stylize};
use ratatui::text::Line;
use ratatui::widgets::Paragraph;
use ratatui::{DefaultTerminal, Frame};
type Result<T> = result::Result<T, Box<dyn Error>>;

View File

@ -9,20 +9,15 @@
///
/// [`latest`]: https://github.com/ratatui/ratatui/tree/latest
use color_eyre::Result;
use crossterm::{
event::{
self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEvent, MouseEvent,
MouseEventKind,
},
execute,
};
use ratatui::{
layout::{Position, Rect, Size},
style::{Color, Stylize},
symbols,
text::Line,
DefaultTerminal, Frame,
use crossterm::event::{
self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEvent, MouseEvent,
MouseEventKind,
};
use crossterm::execute;
use ratatui::layout::{Position, Rect, Size};
use ratatui::style::{Color, Stylize};
use ratatui::text::Line;
use ratatui::{symbols, DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -30,12 +30,10 @@
/// [`latest`]: https://github.com/ratatui/ratatui/tree/latest
/// [Color Eyre recipe]: https://ratatui.rs/recipes/apps/color-eyre
use color_eyre::{eyre::bail, Result};
use ratatui::{
crossterm::event::{self, Event, KeyCode},
text::Line,
widgets::{Block, Paragraph},
DefaultTerminal, Frame,
};
use crossterm::event::{self, Event, KeyCode};
use ratatui::text::Line;
use ratatui::widgets::{Block, Paragraph};
use ratatui::{DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -8,13 +8,11 @@
///
/// [`latest`]: https://github.com/ratatui/ratatui/tree/latest
use color_eyre::Result;
use ratatui::{
crossterm::event::{self, Event, KeyCode, KeyEventKind},
layout::{Constraint, Flex, Layout, Rect},
style::Stylize,
widgets::{Block, Clear, Paragraph, Wrap},
DefaultTerminal, Frame,
};
use crossterm::event::{self, Event, KeyCode, KeyEventKind};
use ratatui::layout::{Constraint, Flex, Layout, Rect};
use ratatui::style::Stylize;
use ratatui::widgets::{Block, Clear, Paragraph, Wrap};
use ratatui::{DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -11,15 +11,13 @@
use std::time::{Duration, Instant};
use color_eyre::Result;
use ratatui::{
crossterm::event::{self, Event, KeyCode},
layout::{Alignment, Constraint, Layout, Margin},
style::{Color, Style, Stylize},
symbols::scrollbar,
text::{Line, Masked, Span},
widgets::{Block, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState},
DefaultTerminal, Frame,
};
use crossterm::event::{self, Event, KeyCode};
use ratatui::layout::{Alignment, Constraint, Layout, Margin};
use ratatui::style::{Color, Style, Stylize};
use ratatui::symbols::scrollbar;
use ratatui::text::{Line, Masked, Span};
use ratatui::widgets::{Block, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState};
use ratatui::{DefaultTerminal, Frame};
#[derive(Default)]
struct App {

View File

@ -6,19 +6,16 @@
///
/// [`latest`]: https://github.com/ratatui/ratatui/tree/latest
use color_eyre::Result;
use crossterm::event::KeyModifiers;
use crossterm::event::{self, Event, KeyCode, KeyEventKind, KeyModifiers};
use itertools::Itertools;
use ratatui::{
crossterm::event::{self, Event, KeyCode, KeyEventKind},
layout::{Constraint, Layout, Margin, Rect},
style::{self, Color, Modifier, Style, Stylize},
text::Text,
widgets::{
Block, BorderType, Cell, HighlightSpacing, Paragraph, Row, Scrollbar, ScrollbarOrientation,
ScrollbarState, Table, TableState,
},
DefaultTerminal, Frame,
use ratatui::layout::{Constraint, Layout, Margin, Rect};
use ratatui::style::{self, Color, Modifier, Style, Stylize};
use ratatui::text::Text;
use ratatui::widgets::{
Block, BorderType, Cell, HighlightSpacing, Paragraph, Row, Scrollbar, ScrollbarOrientation,
ScrollbarState, Table, TableState,
};
use ratatui::{DefaultTerminal, Frame};
use style::palette::tailwind;
use unicode_width::UnicodeWidthStr;

View File

@ -6,22 +6,17 @@
///
/// [`latest`]: https://github.com/ratatui/ratatui/tree/latest
use color_eyre::Result;
use ratatui::{
buffer::Buffer,
crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind},
layout::{Constraint, Layout, Rect},
style::{
palette::tailwind::{BLUE, GREEN, SLATE},
Color, Modifier, Style, Stylize,
},
symbols,
text::Line,
widgets::{
Block, Borders, HighlightSpacing, List, ListItem, ListState, Padding, Paragraph,
StatefulWidget, Widget, Wrap,
},
DefaultTerminal,
use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind};
use ratatui::buffer::Buffer;
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::style::palette::tailwind::{BLUE, GREEN, SLATE};
use ratatui::style::{Color, Modifier, Style, Stylize};
use ratatui::text::Line;
use ratatui::widgets::{
Block, Borders, HighlightSpacing, List, ListItem, ListState, Padding, Paragraph,
StatefulWidget, Widget, Wrap,
};
use ratatui::{symbols, DefaultTerminal};
const TODO_HEADER_STYLE: Style = Style::new().fg(SLATE.c100).bg(BLUE.c800);
const NORMAL_ROW_BG: Color = SLATE.c950;

View File

@ -20,14 +20,14 @@
/// [`latest`]: https://github.com/ratatui/ratatui/tree/latest
use std::{fs::File, time::Duration};
use color_eyre::{eyre::Context, Result};
use ratatui::{
crossterm::event::{self, Event, KeyCode},
widgets::{Block, Paragraph},
Frame,
};
use color_eyre::eyre::Context;
use color_eyre::Result;
use crossterm::event::{self, Event, KeyCode};
use ratatui::widgets::{Block, Paragraph};
use ratatui::Frame;
use tracing::{debug, info, instrument, trace, Level};
use tracing_appender::{non_blocking, non_blocking::WorkerGuard};
use tracing_appender::non_blocking;
use tracing_appender::non_blocking::WorkerGuard;
use tracing_subscriber::EnvFilter;
fn main() -> Result<()> {

View File

@ -21,14 +21,12 @@
///
/// [`latest`]: https://github.com/ratatui/ratatui/tree/latest
use color_eyre::Result;
use ratatui::{
crossterm::event::{self, Event, KeyCode, KeyEventKind},
layout::{Constraint, Layout, Position},
style::{Color, Modifier, Style, Stylize},
text::{Line, Span, Text},
widgets::{Block, List, ListItem, Paragraph},
DefaultTerminal, Frame,
};
use crossterm::event::{self, Event, KeyCode, KeyEventKind};
use ratatui::layout::{Constraint, Layout, Position};
use ratatui::style::{Color, Modifier, Style, Stylize};
use ratatui::text::{Line, Span, Text};
use ratatui::widgets::{Block, List, ListItem, Paragraph};
use ratatui::{DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -9,15 +9,13 @@
//! [`BarChart`]: https://docs.rs/ratatui/latest/ratatui/widgets/struct.BarChart.html
use color_eyre::Result;
use crossterm::event::{self, Event, KeyCode, KeyEventKind};
use rand::{rng, Rng};
use ratatui::{
crossterm::event::{self, Event, KeyCode, KeyEventKind},
layout::{Constraint, Layout},
style::{Color, Style, Stylize},
text::Line,
widgets::{Bar, BarChart, BarGroup},
DefaultTerminal, Frame,
};
use ratatui::layout::{Constraint, Layout};
use ratatui::style::{Color, Style, Stylize};
use ratatui::text::Line;
use ratatui::widgets::{Bar, BarChart, BarGroup};
use ratatui::{DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -14,12 +14,10 @@ use std::iter::zip;
use color_eyre::Result;
use crossterm::event;
use ratatui::{
buffer::Buffer,
layout::{Constraint, Direction, Layout, Rect},
widgets::{Block, Paragraph, Widget, WidgetRef},
DefaultTerminal, Frame,
};
use ratatui::buffer::Buffer;
use ratatui::layout::{Constraint, Direction, Layout, Rect};
use ratatui::widgets::{Block, Paragraph, Widget, WidgetRef};
use ratatui::{DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -104,10 +104,8 @@ use std::io;
use strum::{Display, EnumString};
use crate::{
buffer::Cell,
layout::{Position, Size},
};
use crate::buffer::Cell;
use crate::layout::{Position, Size};
mod test;
pub use self::test::TestBackend;

View File

@ -1,18 +1,14 @@
//! 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::{self, Write},
io, iter,
};
use std::fmt::{self, Write};
use std::{io, iter};
use unicode_width::UnicodeWidthStr;
use crate::{
backend::{Backend, ClearType, WindowSize},
buffer::{Buffer, Cell},
layout::{Position, Rect, Size},
};
use crate::backend::{Backend, ClearType, WindowSize};
use crate::buffer::{Buffer, Cell};
use crate::layout::{Position, Rect, Size};
/// A [`Backend`] implementation used for integration testing that renders to an memory buffer.
///

View File

@ -41,11 +41,9 @@ macro_rules! assert_buffer_eq {
#[allow(deprecated)]
#[cfg(test)]
mod tests {
use crate::{
buffer::Buffer,
layout::Rect,
style::{Color, Style},
};
use crate::buffer::Buffer;
use crate::layout::Rect;
use crate::style::{Color, Style};
#[test]
fn assert_buffer_eq_does_not_panic_on_equal_buffers() {

View File

@ -1,17 +1,13 @@
use std::{
fmt,
ops::{Index, IndexMut},
};
use std::fmt;
use std::ops::{Index, IndexMut};
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
use crate::{
buffer::Cell,
layout::{Position, Rect},
style::Style,
text::{Line, Span},
};
use crate::buffer::Cell;
use crate::layout::{Position, Rect};
use crate::style::Style;
use crate::text::{Line, Span};
/// A buffer that maps to the desired content of the terminal after the draw call
///
@ -23,11 +19,9 @@ use crate::{
/// # Examples:
///
/// ```
/// use ratatui_core::{
/// buffer::{Buffer, Cell},
/// layout::{Position, Rect},
/// style::{Color, Style},
/// };
/// use ratatui_core::buffer::{Buffer, Cell};
/// use ratatui_core::layout::{Position, Rect};
/// use ratatui_core::style::{Color, Style};
///
/// # fn foo() -> Option<()> {
/// let mut buf = Buffer::empty(Rect {
@ -168,10 +162,8 @@ impl Buffer {
/// # Examples
///
/// ```rust
/// use ratatui_core::{
/// buffer::{Buffer, Cell},
/// layout::{Position, Rect},
/// };
/// use ratatui_core::buffer::{Buffer, Cell};
/// use ratatui_core::layout::{Position, Rect};
///
/// let mut buffer = Buffer::empty(Rect::new(0, 0, 10, 10));
///
@ -199,11 +191,9 @@ impl Buffer {
/// # Examples
///
/// ```rust
/// use ratatui_core::{
/// buffer::{Buffer, Cell},
/// layout::{Position, Rect},
/// style::{Color, Style},
/// };
/// use ratatui_core::buffer::{Buffer, Cell};
/// use ratatui_core::layout::{Position, Rect};
/// use ratatui_core::style::{Color, Style};
/// let mut buffer = Buffer::empty(Rect::new(0, 0, 10, 10));
///
/// if let Some(cell) = buffer.cell_mut(Position::new(0, 0)) {
@ -227,7 +217,8 @@ impl Buffer {
/// # Examples
///
/// ```
/// use ratatui_core::{buffer::Buffer, layout::Rect};
/// use ratatui_core::buffer::Buffer;
/// use ratatui_core::layout::Rect;
///
/// let buffer = Buffer::empty(Rect::new(200, 100, 10, 10));
/// // Global coordinates to the top corner of this buffer's area
@ -239,7 +230,8 @@ impl Buffer {
/// Panics when given an coordinate that is outside of this Buffer's area.
///
/// ```should_panic
/// use ratatui_core::{buffer::Buffer, layout::Rect};
/// use ratatui_core::buffer::Buffer;
/// use ratatui_core::layout::Rect;
///
/// let buffer = Buffer::empty(Rect::new(200, 100, 10, 10));
/// // Top coordinate is outside of the buffer in global coordinate space, as the Buffer's area
@ -282,7 +274,8 @@ impl Buffer {
/// # Examples
///
/// ```
/// use ratatui_core::{buffer::Buffer, layout::Rect};
/// use ratatui_core::buffer::Buffer;
/// use ratatui_core::layout::Rect;
///
/// let rect = Rect::new(200, 100, 10, 10);
/// let buffer = Buffer::empty(rect);
@ -295,7 +288,8 @@ impl Buffer {
/// Panics when given an index that is outside the Buffer's content.
///
/// ```should_panic
/// use ratatui_core::{buffer::Buffer, layout::Rect};
/// use ratatui_core::buffer::Buffer;
/// use ratatui_core::layout::Rect;
///
/// let rect = Rect::new(0, 0, 10, 10); // 100 cells in total
/// let buffer = Buffer::empty(rect);
@ -526,10 +520,8 @@ impl<P: Into<Position>> Index<P> for Buffer {
/// # Examples
///
/// ```
/// use ratatui_core::{
/// buffer::{Buffer, Cell},
/// layout::{Position, Rect},
/// };
/// use ratatui_core::buffer::{Buffer, Cell};
/// use ratatui_core::layout::{Position, Rect};
///
/// let buf = Buffer::empty(Rect::new(0, 0, 10, 10));
/// let cell = &buf[(0, 0)];
@ -556,10 +548,8 @@ impl<P: Into<Position>> IndexMut<P> for Buffer {
/// # Examples
///
/// ```
/// use ratatui_core::{
/// buffer::{Buffer, Cell},
/// layout::{Position, Rect},
/// };
/// use ratatui_core::buffer::{Buffer, Cell};
/// use ratatui_core::layout::{Position, Rect};
///
/// let mut buf = Buffer::empty(Rect::new(0, 0, 10, 10));
/// buf[(0, 0)].set_symbol("A");

View File

@ -1,10 +1,12 @@
use std::{cell::RefCell, collections::HashMap, iter, num::NonZeroUsize, rc::Rc};
use std::cell::RefCell;
use std::collections::HashMap;
use std::iter;
use std::num::NonZeroUsize;
use std::rc::Rc;
use cassowary::{
strength::REQUIRED,
AddConstraintError, Expression, Solver, Variable,
WeightedRelation::{EQ, GE, LE},
};
use cassowary::strength::REQUIRED;
use cassowary::WeightedRelation::{EQ, GE, LE};
use cassowary::{AddConstraintError, Expression, Solver, Variable};
use itertools::Itertools;
use lru::LruCache;
@ -148,12 +150,10 @@ impl From<i16> for Spacing {
/// # Example
///
/// ```rust
/// use ratatui_core::{
/// buffer::Buffer,
/// layout::{Constraint, Direction, Layout, Rect},
/// text::Text,
/// widgets::Widget,
/// };
/// use ratatui_core::buffer::Buffer;
/// use ratatui_core::layout::{Constraint, Direction, Layout, Rect};
/// use ratatui_core::text::Text;
/// use ratatui_core::widgets::Widget;
///
/// fn render(area: Rect, buf: &mut ratatui_core::buffer::Buffer) {
/// let layout = Layout::vertical([Constraint::Length(5), Constraint::Min(0)]);
@ -440,7 +440,8 @@ impl Layout {
/// In this example, the items in the layout will be aligned to the start.
///
/// ```rust
/// use ratatui_core::layout::{Constraint::*, Flex, Layout};
/// use ratatui_core::layout::Constraint::*;
/// use ratatui_core::layout::{Flex, Layout};
///
/// let layout = Layout::horizontal([Length(20), Length(20), Length(20)]).flex(Flex::Start);
/// ```
@ -449,7 +450,8 @@ impl Layout {
/// space.
///
/// ```rust
/// use ratatui_core::layout::{Constraint::*, Flex, Layout};
/// use ratatui_core::layout::Constraint::*;
/// use ratatui_core::layout::{Flex, Layout};
///
/// let layout = Layout::horizontal([Length(20), Length(20), Length(20)]).flex(Flex::Legacy);
/// ```
@ -477,7 +479,8 @@ impl Layout {
/// In this example, the spacing between each item in the layout is set to 2 cells.
///
/// ```rust
/// use ratatui_core::layout::{Constraint::*, Layout};
/// use ratatui_core::layout::Constraint::*;
/// use ratatui_core::layout::Layout;
///
/// let layout = Layout::horizontal([Length(20), Length(20), Length(20)]).spacing(2);
/// ```
@ -486,7 +489,8 @@ impl Layout {
/// three segments will have an overlapping border.
///
/// ```rust
/// use ratatui_core::layout::{Constraint::*, Layout};
/// use ratatui_core::layout::Constraint::*;
/// use ratatui_core::layout::Layout;
/// let layout = Layout::horizontal([Length(20), Length(20), Length(20)]).spacing(-1);
/// ```
#[must_use = "method moves the value of self and returns the modified value"]
@ -1406,15 +1410,11 @@ mod tests {
use pretty_assertions::assert_eq;
use rstest::rstest;
use crate::{
buffer::Buffer,
layout::{
Constraint::{self, *},
Direction, Flex, Layout, Rect,
},
text::Text,
widgets::Widget,
};
use crate::buffer::Buffer;
use crate::layout::Constraint::{self, *};
use crate::layout::{Direction, Flex, Layout, Rect};
use crate::text::Text;
use crate::widgets::Widget;
/// Test that the given constraints applied to the given area result in the expected layout.
/// Each chunk is filled with a letter repeated as many times as the width of the chunk. The

View File

@ -1,8 +1,6 @@
#![warn(missing_docs)]
use std::{
cmp::{max, min},
fmt,
};
use std::cmp::{max, min};
use std::fmt;
use crate::layout::{Margin, Position, Size};
@ -273,7 +271,10 @@ impl Rect {
/// # Example
///
/// ```
/// use ratatui_core::{buffer::Buffer, layout::Rect, text::Line, widgets::Widget};
/// use ratatui_core::buffer::Buffer;
/// use ratatui_core::layout::Rect;
/// use ratatui_core::text::Line;
/// use ratatui_core::widgets::Widget;
///
/// fn render(area: Rect, buf: &mut Buffer) {
/// for row in area.rows() {
@ -290,7 +291,10 @@ impl Rect {
/// # Example
///
/// ```
/// use ratatui_core::{buffer::Buffer, layout::Rect, text::Text, widgets::Widget};
/// use ratatui_core::buffer::Buffer;
/// use ratatui_core::layout::Rect;
/// use ratatui_core::text::Text;
/// use ratatui_core::widgets::Widget;
///
/// fn render(area: Rect, buf: &mut Buffer) {
/// for (i, column) in area.columns().enumerate() {
@ -309,7 +313,8 @@ impl Rect {
/// # Example
///
/// ```
/// use ratatui_core::{buffer::Buffer, layout::Rect};
/// use ratatui_core::buffer::Buffer;
/// use ratatui_core::layout::Rect;
///
/// fn render(area: Rect, buf: &mut Buffer) {
/// for position in area.positions() {

View File

@ -13,10 +13,8 @@
//! ## Example
//!
//! ```
//! use ratatui_core::{
//! style::{Color, Modifier, Style},
//! text::Span,
//! };
//! use ratatui_core::style::{Color, Modifier, Style};
//! use ratatui_core::text::Span;
//!
//! let heading_style = Style::new()
//! .fg(Color::Black)
@ -43,10 +41,8 @@
//! ## Example
//!
//! ```
//! use ratatui_core::{
//! style::{Color, Modifier, Style, Stylize},
//! text::{Span, Text},
//! };
//! use ratatui_core::style::{Color, Modifier, Style, Stylize};
//! use ratatui_core::text::{Span, Text};
//!
//! assert_eq!(
//! "hello".red().on_blue().bold(),
@ -156,10 +152,8 @@ impl fmt::Debug for Modifier {
/// anywhere that accepts `Into<Style>`.
///
/// ```rust
/// use ratatui_core::{
/// style::{Color, Modifier, Style},
/// text::Line,
/// };
/// use ratatui_core::style::{Color, Modifier, Style};
/// use ratatui_core::text::Line;
///
/// Line::styled("hello", Style::new().fg(Color::Red));
/// // simplifies to
@ -175,11 +169,9 @@ impl fmt::Debug for Modifier {
/// just S3.
///
/// ```rust
/// use ratatui_core::{
/// buffer::Buffer,
/// layout::Rect,
/// style::{Color, Modifier, Style},
/// };
/// use ratatui_core::buffer::Buffer;
/// use ratatui_core::layout::Rect;
/// use ratatui_core::style::{Color, Modifier, Style};
///
/// let styles = [
/// Style::default()
@ -215,11 +207,9 @@ impl fmt::Debug for Modifier {
/// reset all properties until that point use [`Style::reset`].
///
/// ```
/// use ratatui_core::{
/// buffer::Buffer,
/// layout::Rect,
/// style::{Color, Modifier, Style},
/// };
/// use ratatui_core::buffer::Buffer;
/// use ratatui_core::layout::Rect;
/// use ratatui_core::style::{Color, Modifier, Style};
///
/// let styles = [
/// Style::default()
@ -689,7 +679,8 @@ mod tests {
#[test]
fn combine_individual_modifiers() {
use crate::{buffer::Buffer, layout::Rect};
use crate::buffer::Buffer;
use crate::layout::Rect;
let mods = [
Modifier::BOLD,

View File

@ -1,6 +1,7 @@
#![allow(clippy::unreadable_literal)]
use std::{fmt, str::FromStr};
use std::fmt;
use std::str::FromStr;
use crate::style::stylize::{ColorDebug, ColorDebugKind};

View File

@ -403,10 +403,8 @@
//! # Example
//!
//! ```rust
//! use ratatui_core::style::{
//! palette::material::{BLUE, RED},
//! Color,
//! };
//! use ratatui_core::style::palette::material::{BLUE, RED};
//! use ratatui_core::style::Color;
//!
//! assert_eq!(RED.c500, Color::Rgb(244, 67, 54));
//! assert_eq!(BLUE.c500, Color::Rgb(33, 150, 243));

View File

@ -268,10 +268,8 @@
//! # Example
//!
//! ```rust
//! use ratatui_core::style::{
//! palette::tailwind::{BLUE, RED},
//! Color,
//! };
//! use ratatui_core::style::palette::tailwind::{BLUE, RED};
//! use ratatui_core::style::Color;
//!
//! assert_eq!(RED.c500, Color::Rgb(239, 68, 68));
//! assert_eq!(BLUE.c500, Color::Rgb(59, 130, 246));

View File

@ -1,11 +1,10 @@
//! Conversions from colors in the `palette` crate to [`Color`].
use ::palette::{
bool_mask::LazySelect,
num::{Arithmetics, MulSub, PartialCmp, Powf, Real},
LinSrgb,
};
use palette::{stimulus::IntoStimulus, Srgb};
use ::palette::bool_mask::LazySelect;
use ::palette::num::{Arithmetics, MulSub, PartialCmp, Powf, Real};
use ::palette::LinSrgb;
use palette::stimulus::IntoStimulus;
use palette::Srgb;
use crate::style::Color;

View File

@ -1,9 +1,7 @@
use std::fmt;
use crate::{
style::{Color, Modifier, Style},
text::Span,
};
use crate::style::{Color, Modifier, Style};
use crate::text::Span;
/// A trait for objects that have a `Style`.
///

View File

@ -1,8 +1,6 @@
use crate::{
buffer::Buffer,
layout::{Position, Rect},
widgets::{StatefulWidget, Widget},
};
use crate::buffer::Buffer;
use crate::layout::{Position, Rect};
use crate::widgets::{StatefulWidget, Widget};
/// A consistent view into the terminal state for rendering a single frame.
///

View File

@ -1,11 +1,9 @@
use std::io;
use crate::{
backend::{Backend, ClearType},
buffer::{Buffer, Cell},
layout::{Position, Rect, Size},
terminal::{CompletedFrame, Frame, TerminalOptions, Viewport},
};
use crate::backend::{Backend, ClearType};
use crate::buffer::{Buffer, Cell};
use crate::layout::{Position, Rect, Size};
use crate::terminal::{CompletedFrame, Frame, TerminalOptions, Viewport};
/// An interface to interact and draw [`Frame`]s on the user's terminal.
///

View File

@ -1,16 +1,15 @@
#![deny(missing_docs)]
#![warn(clippy::pedantic, clippy::nursery, clippy::arithmetic_side_effects)]
use std::{borrow::Cow, fmt};
use std::borrow::Cow;
use std::fmt;
use unicode_truncate::UnicodeTruncateStr;
use crate::{
buffer::Buffer,
layout::{Alignment, Rect},
style::{Style, Styled},
text::{Span, StyledGrapheme, Text},
widgets::Widget,
};
use crate::buffer::Buffer;
use crate::layout::{Alignment, Rect};
use crate::style::{Style, Styled};
use crate::text::{Span, StyledGrapheme, Text};
use crate::widgets::Widget;
/// A line of text, consisting of one or more [`Span`]s.
///
@ -75,10 +74,8 @@ use crate::{
/// [`Style`].
///
/// ```rust
/// use ratatui_core::{
/// style::{Color, Modifier, Style, Stylize},
/// text::{Line, Span},
/// };
/// use ratatui_core::style::{Color, Modifier, Style, Stylize};
/// use ratatui_core::text::{Line, Span};
///
/// let style = Style::new().yellow();
/// let line = Line::raw("Hello, world!").style(style);
@ -102,10 +99,8 @@ use crate::{
/// methods of the [`Stylize`] trait.
///
/// ```rust
/// use ratatui_core::{
/// style::{Color, Modifier, Style, Stylize},
/// text::Line,
/// };
/// use ratatui_core::style::{Color, Modifier, Style, Stylize};
/// use ratatui_core::text::Line;
///
/// let line = Line::from("Hello world!").style(Style::new().yellow().italic());
/// let line = Line::from("Hello world!").style(Color::Yellow);
@ -121,7 +116,8 @@ use crate::{
/// ignored and the line is truncated.
///
/// ```rust
/// use ratatui_core::{layout::Alignment, text::Line};
/// use ratatui_core::layout::Alignment;
/// use ratatui_core::text::Line;
///
/// let line = Line::from("Hello world!").alignment(Alignment::Right);
/// let line = Line::from("Hello world!").centered();
@ -134,13 +130,11 @@ use crate::{
/// `Line` implements the [`Widget`] trait, which means it can be rendered to a [`Buffer`].
///
/// ```rust
/// use ratatui_core::{
/// buffer::Buffer,
/// layout::Rect,
/// style::{Style, Stylize},
/// text::Line,
/// widgets::Widget,
/// };
/// use ratatui_core::buffer::Buffer;
/// use ratatui_core::layout::Rect;
/// use ratatui_core::style::{Style, Stylize};
/// use ratatui_core::text::Line;
/// use ratatui_core::widgets::Widget;
///
/// # fn render(area: Rect, buf: &mut Buffer) {
/// // in another widget's render method
@ -274,10 +268,8 @@ impl<'a> Line<'a> {
/// ```rust
/// use std::borrow::Cow;
///
/// use ratatui_core::{
/// style::{Style, Stylize},
/// text::Line,
/// };
/// use ratatui_core::style::{Style, Stylize};
/// use ratatui_core::text::Line;
///
/// let style = Style::new().yellow().italic();
/// Line::styled("My text", style);
@ -306,7 +298,8 @@ impl<'a> Line<'a> {
/// # Examples
///
/// ```rust
/// use ratatui_core::{style::Stylize, text::Line};
/// use ratatui_core::style::Stylize;
/// use ratatui_core::text::Line;
///
/// let line = Line::default().spans(vec!["Hello".blue(), " world!".green()]);
/// let line = Line::default().spans([1, 2, 3].iter().map(|i| format!("Item {}", i)));
@ -334,10 +327,8 @@ impl<'a> Line<'a> {
///
/// # Examples
/// ```rust
/// use ratatui_core::{
/// style::{Style, Stylize},
/// text::Line,
/// };
/// use ratatui_core::style::{Style, Stylize};
/// use ratatui_core::text::Line;
///
/// let mut line = Line::from("foo").style(Style::new().red());
/// ```
@ -358,7 +349,8 @@ impl<'a> Line<'a> {
/// # Examples
///
/// ```rust
/// use ratatui_core::{layout::Alignment, text::Line};
/// use ratatui_core::layout::Alignment;
/// use ratatui_core::text::Line;
///
/// let mut line = Line::from("Hi, what's up?");
/// assert_eq!(None, line.alignment);
@ -434,7 +426,8 @@ impl<'a> Line<'a> {
/// # Examples
///
/// ```rust
/// use ratatui_core::{style::Stylize, text::Line};
/// use ratatui_core::style::Stylize;
/// use ratatui_core::text::Line;
///
/// let line = Line::from(vec!["Hello".blue(), " world!".green()]);
/// assert_eq!(12, line.width());
@ -456,10 +449,8 @@ impl<'a> Line<'a> {
/// ```rust
/// use std::iter::Iterator;
///
/// use ratatui_core::{
/// style::{Color, Style},
/// text::{Line, StyledGrapheme},
/// };
/// use ratatui_core::style::{Color, Style};
/// use ratatui_core::text::{Line, StyledGrapheme};
///
/// let line = Line::styled("Text", Style::default().fg(Color::Yellow));
/// let style = Style::default().fg(Color::Green).bg(Color::Black);
@ -500,10 +491,8 @@ impl<'a> Line<'a> {
/// # Examples
///
/// ```rust
/// use ratatui_core::{
/// style::{Color, Modifier},
/// text::Line,
/// };
/// use ratatui_core::style::{Color, Modifier};
/// use ratatui_core::text::Line;
///
/// let line = Line::styled("My text", Modifier::ITALIC);
///
@ -529,10 +518,8 @@ impl<'a> Line<'a> {
///
/// ```rust
/// # let style = Style::default().yellow();
/// use ratatui_core::{
/// style::{Style, Stylize},
/// text::Line,
/// };
/// use ratatui_core::style::{Style, Stylize};
/// use ratatui_core::text::Line;
///
/// let line = Line::styled("My text", style);
///

View File

@ -1,4 +1,5 @@
use std::{borrow::Cow, fmt};
use std::borrow::Cow;
use std::fmt;
use crate::text::Text;
@ -10,12 +11,10 @@ use crate::text::Text;
/// # Examples
///
/// ```rust
/// use ratatui_core::{
/// buffer::Buffer,
/// layout::Rect,
/// text::{Masked, Text},
/// widgets::Widget,
/// };
/// use ratatui_core::buffer::Buffer;
/// use ratatui_core::layout::Rect;
/// use ratatui_core::text::{Masked, Text};
/// use ratatui_core::widgets::Widget;
///
/// let mut buffer = Buffer::empty(Rect::new(0, 0, 5, 1));
/// let password = Masked::new("12345", 'x');

View File

@ -1,15 +1,14 @@
use std::{borrow::Cow, fmt};
use std::borrow::Cow;
use std::fmt;
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
use crate::{
buffer::Buffer,
layout::Rect,
style::{Style, Styled},
text::{Line, StyledGrapheme},
widgets::Widget,
};
use crate::buffer::Buffer;
use crate::layout::Rect;
use crate::style::{Style, Styled};
use crate::text::{Line, StyledGrapheme};
use crate::widgets::Widget;
/// Represents a part of a line that is contiguous and where all characters share the same style.
///
@ -56,10 +55,8 @@ use crate::{
/// the [`Stylize`] trait.
///
/// ```rust
/// use ratatui_core::{
/// style::{Style, Stylize},
/// text::Span,
/// };
/// use ratatui_core::style::{Style, Stylize};
/// use ratatui_core::text::Span;
///
/// let span = Span::styled("test content", Style::new().green());
/// let span = Span::styled(String::from("test content"), Style::new().green());
@ -73,7 +70,8 @@ use crate::{
/// defined in the [`Stylize`] trait.
///
/// ```rust
/// use ratatui_core::{style::Stylize, text::Span};
/// use ratatui_core::style::Stylize;
/// use ratatui_core::text::Span;
///
/// let span = Span::raw("test content").green().on_yellow().italic();
/// let span = Span::raw(String::from("test content"))
@ -150,10 +148,8 @@ impl<'a> Span<'a> {
/// # Examples
///
/// ```rust
/// use ratatui_core::{
/// style::{Style, Stylize},
/// text::Span,
/// };
/// use ratatui_core::style::{Style, Stylize};
/// use ratatui_core::text::Span;
///
/// let style = Style::new().yellow().on_green().italic();
/// Span::styled("test content", style);
@ -208,10 +204,8 @@ impl<'a> Span<'a> {
/// # Examples
///
/// ```rust
/// use ratatui_core::{
/// style::{Style, Stylize},
/// text::Span,
/// };
/// use ratatui_core::style::{Style, Stylize};
/// use ratatui_core::text::Span;
///
/// let mut span = Span::default().style(Style::new().green());
/// ```
@ -233,10 +227,8 @@ impl<'a> Span<'a> {
/// # Example
///
/// ```rust
/// use ratatui_core::{
/// style::{Style, Stylize},
/// text::Span,
/// };
/// use ratatui_core::style::{Style, Stylize};
/// use ratatui_core::text::Span;
///
/// let span = Span::styled("test content", Style::new().green().italic())
/// .patch_style(Style::new().red().on_yellow().bold());
@ -259,10 +251,8 @@ impl<'a> Span<'a> {
/// # Example
///
/// ```rust
/// use ratatui_core::{
/// style::{Style, Stylize},
/// text::Span,
/// };
/// use ratatui_core::style::{Style, Stylize};
/// use ratatui_core::text::Span;
///
/// let span = Span::styled(
/// "Test Content",
@ -294,10 +284,8 @@ impl<'a> Span<'a> {
/// ```rust
/// use std::iter::Iterator;
///
/// use ratatui_core::{
/// style::{Style, Stylize},
/// text::{Span, StyledGrapheme},
/// };
/// use ratatui_core::style::{Style, Stylize};
/// use ratatui_core::text::{Span, StyledGrapheme};
///
/// let span = Span::styled("Test", Style::new().green().italic());
/// let style = Style::new().red().on_yellow();
@ -509,7 +497,9 @@ mod tests {
use rstest::{fixture, rstest};
use super::*;
use crate::{buffer::Cell, layout::Alignment, style::Stylize};
use crate::buffer::Cell;
use crate::layout::Alignment;
use crate::style::Stylize;
#[fixture]
fn small_buf() -> Buffer {

View File

@ -1,13 +1,12 @@
#![warn(missing_docs)]
use std::{borrow::Cow, fmt};
use std::borrow::Cow;
use std::fmt;
use crate::{
buffer::Buffer,
layout::{Alignment, Rect},
style::{Style, Styled},
text::{Line, Span},
widgets::Widget,
};
use crate::buffer::Buffer;
use crate::layout::{Alignment, Rect};
use crate::style::{Style, Styled};
use crate::text::{Line, Span};
use crate::widgets::Widget;
/// A string split over one or more lines.
///
@ -66,12 +65,11 @@ use crate::{
/// [`core::iter::Extend`] which enables the concatenation of several [`Text`] blocks.
///
/// ```rust
/// use std::{borrow::Cow, iter};
/// use std::borrow::Cow;
/// use std::iter;
///
/// use ratatui_core::{
/// style::{Color, Modifier, Style, Stylize},
/// text::{Line, Span, Text},
/// };
/// use ratatui_core::style::{Color, Modifier, Style, Stylize};
/// use ratatui_core::text::{Line, Span, Text};
///
/// let style = Style::new().yellow().italic();
/// let text = Text::raw("The first line\nThe second line").style(style);
@ -108,10 +106,8 @@ use crate::{
/// [`Stylize`] trait.
///
/// ```rust
/// use ratatui_core::{
/// style::{Color, Modifier, Style, Stylize},
/// text::{Line, Text},
/// };
/// use ratatui_core::style::{Color, Modifier, Style, Stylize};
/// use ratatui_core::text::{Line, Text};
///
/// let text = Text::from("The first line\nThe second line").style(Style::new().yellow().italic());
/// let text = Text::from("The first line\nThe second line")
@ -129,10 +125,8 @@ use crate::{
/// Lines composing the text can also be individually aligned with [`Line::alignment`].
///
/// ```rust
/// use ratatui_core::{
/// layout::Alignment,
/// text::{Line, Text},
/// };
/// use ratatui_core::layout::Alignment;
/// use ratatui_core::text::{Line, Text};
///
/// let text = Text::from("The first line\nThe second line").alignment(Alignment::Right);
/// let text = Text::from("The first line\nThe second line").right_aligned();
@ -150,7 +144,8 @@ use crate::{
///
/// ```rust
/// # use ratatui_core::{buffer::Buffer, layout::Rect};
/// use ratatui_core::{text::Text, widgets::Widget};
/// use ratatui_core::text::Text;
/// use ratatui_core::widgets::Widget;
///
/// // within another widget's `render` method:
/// # fn render(area: Rect, buf: &mut Buffer) {
@ -256,10 +251,8 @@ impl<'a> Text<'a> {
/// # Examples
///
/// ```rust
/// use ratatui_core::{
/// style::{Color, Modifier, Style},
/// text::Text,
/// };
/// use ratatui_core::style::{Color, Modifier, Style};
/// use ratatui_core::text::Text;
///
/// let style = Style::default()
/// .fg(Color::Yellow)
@ -318,10 +311,8 @@ impl<'a> Text<'a> {
///
/// # Examples
/// ```rust
/// use ratatui_core::{
/// style::{Style, Stylize},
/// text::Text,
/// };
/// use ratatui_core::style::{Style, Stylize};
/// use ratatui_core::text::Text;
///
/// let mut line = Text::from("foo").style(Style::new().red());
/// ```
@ -350,10 +341,8 @@ impl<'a> Text<'a> {
/// # Examples
///
/// ```rust
/// use ratatui_core::{
/// style::{Color, Modifier},
/// text::Text,
/// };
/// use ratatui_core::style::{Color, Modifier};
/// use ratatui_core::text::Text;
///
/// let raw_text = Text::styled("The first line\nThe second line", Modifier::ITALIC);
/// let styled_text = Text::styled(
@ -383,10 +372,8 @@ impl<'a> Text<'a> {
/// # Examples
///
/// ```rust
/// use ratatui_core::{
/// style::{Color, Modifier, Style},
/// text::Text,
/// };
/// use ratatui_core::style::{Color, Modifier, Style};
/// use ratatui_core::text::Text;
///
/// let text = Text::styled(
/// "The first line\nThe second line",
@ -414,7 +401,8 @@ impl<'a> Text<'a> {
/// Set alignment to the whole text.
///
/// ```rust
/// use ratatui_core::{layout::Alignment, text::Text};
/// use ratatui_core::layout::Alignment;
/// use ratatui_core::text::Text;
///
/// let mut text = Text::from("Hi, what's up?");
/// assert_eq!(None, text.alignment);
@ -427,10 +415,8 @@ impl<'a> Text<'a> {
/// Set a default alignment and override it on a per line basis.
///
/// ```rust
/// use ratatui_core::{
/// layout::Alignment,
/// text::{Line, Text},
/// };
/// use ratatui_core::layout::Alignment;
/// use ratatui_core::text::{Line, Text};
///
/// let text = Text::from(vec![
/// Line::from("left").alignment(Alignment::Left),

View File

@ -2,7 +2,8 @@
//! The `widgets` module contains the `Widget` and `StatefulWidget` traits, which are used to
//! render UI elements on the screen.
pub use self::{stateful_widget::StatefulWidget, widget::Widget};
pub use self::stateful_widget::StatefulWidget;
pub use self::widget::Widget;
mod stateful_widget;
mod widget;

View File

@ -1,4 +1,5 @@
use crate::{buffer::Buffer, layout::Rect};
use crate::buffer::Buffer;
use crate::layout::Rect;
/// A `StatefulWidget` is a widget that can take advantage of some local state to remember things
/// between two draw calls.
@ -132,7 +133,10 @@ mod tests {
use rstest::{fixture, rstest};
use super::*;
use crate::{buffer::Buffer, layout::Rect, text::Line, widgets::Widget};
use crate::buffer::Buffer;
use crate::layout::Rect;
use crate::text::Line;
use crate::widgets::Widget;
#[fixture]
fn buf() -> Buffer {

View File

@ -1,4 +1,6 @@
use crate::{buffer::Buffer, layout::Rect, style::Style};
use crate::buffer::Buffer;
use crate::layout::Rect;
use crate::style::Style;
/// A `Widget` is a type that can be drawn on a [`Buffer`] in a given [`Rect`].
///
@ -45,7 +47,10 @@ use crate::{buffer::Buffer, layout::Rect, style::Style};
/// It's common to render widgets inside other widgets:
///
/// ```rust
/// use ratatui_core::{buffer::Buffer, layout::Rect, text::Line, widgets::Widget};
/// use ratatui_core::buffer::Buffer;
/// use ratatui_core::layout::Rect;
/// use ratatui_core::text::Line;
/// use ratatui_core::widgets::Widget;
///
/// struct MyWidget;
///
@ -98,7 +103,9 @@ mod tests {
use rstest::{fixture, rstest};
use super::*;
use crate::{buffer::Buffer, layout::Rect, text::Line};
use crate::buffer::Buffer;
use crate::layout::Rect;
use crate::text::Line;
#[fixture]
fn buf() -> Buffer {

View File

@ -16,24 +16,20 @@
use std::io::{self, Write};
pub use crossterm;
use crossterm::cursor::{Hide, MoveTo, Show};
#[cfg(feature = "underline-color")]
use crossterm::style::SetUnderlineColor;
use crossterm::{
cursor::{Hide, MoveTo, Show},
execute, queue,
style::{
Attribute as CrosstermAttribute, Attributes as CrosstermAttributes,
Color as CrosstermColor, Colors as CrosstermColors, ContentStyle, Print, SetAttribute,
SetBackgroundColor, SetColors, SetForegroundColor,
},
terminal::{self, Clear},
};
use ratatui_core::{
backend::{Backend, ClearType, WindowSize},
buffer::Cell,
layout::{Position, Size},
style::{Color, Modifier, Style},
use crossterm::style::{
Attribute as CrosstermAttribute, Attributes as CrosstermAttributes, Color as CrosstermColor,
Colors as CrosstermColors, ContentStyle, Print, SetAttribute, SetBackgroundColor, SetColors,
SetForegroundColor,
};
use crossterm::terminal::{self, Clear};
use crossterm::{execute, queue};
use ratatui_core::backend::{Backend, ClearType, WindowSize};
use ratatui_core::buffer::Cell;
use ratatui_core::layout::{Position, Size};
use ratatui_core::style::{Color, Modifier, Style};
/// A [`Backend`] implementation that uses [Crossterm] to render to the terminal.
///
@ -56,11 +52,12 @@ use ratatui_core::{
/// ```rust,no_run
/// use std::io::{stderr, stdout};
///
/// use crossterm::{
/// terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
/// ExecutableCommand,
/// use crossterm::terminal::{
/// disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen,
/// };
/// use ratatui::{backend::CrosstermBackend, Terminal};
/// use crossterm::ExecutableCommand;
/// use ratatui::backend::CrosstermBackend;
/// use ratatui::Terminal;
///
/// let mut backend = CrosstermBackend::new(stdout());
/// // or

View File

@ -14,19 +14,16 @@
#![cfg_attr(feature = "document-features", doc = "\n## Features")]
#![cfg_attr(feature = "document-features", doc = document_features::document_features!())]
use std::{
fmt,
io::{self, Write},
};
use std::fmt;
use std::io::{self, Write};
use ratatui_core::{
backend::{Backend, ClearType, WindowSize},
buffer::Cell,
layout::{Position, Size},
style::{Color, Modifier, Style},
};
use ratatui_core::backend::{Backend, ClearType, WindowSize};
use ratatui_core::buffer::Cell;
use ratatui_core::layout::{Position, Size};
use ratatui_core::style::{Color, Modifier, Style};
pub use termion;
use termion::{color as tcolor, color::Color as _, style as tstyle};
use termion::color::Color as _;
use termion::{color as tcolor, style as tstyle};
/// A [`Backend`] implementation that uses [Termion] to render to the terminal.
///
@ -50,11 +47,10 @@ use termion::{color as tcolor, color::Color as _, style as tstyle};
/// ```rust,no_run
/// use std::io::{stderr, stdout};
///
/// use ratatui::{
/// backend::TermionBackend,
/// termion::{raw::IntoRawMode, screen::IntoAlternateScreen},
/// Terminal,
/// };
/// use ratatui::backend::TermionBackend;
/// use ratatui::termion::raw::IntoRawMode;
/// use ratatui::termion::screen::IntoAlternateScreen;
/// use ratatui::Terminal;
///
/// let writer = stdout().into_raw_mode()?.into_alternate_screen()?;
/// let mut backend = TermionBackend::new(writer);

View File

@ -14,22 +14,20 @@
#![cfg_attr(feature = "document-features", doc = "\n## Features")]
#![cfg_attr(feature = "document-features", doc = document_features::document_features!())]
use std::{error::Error, io};
use std::error::Error;
use std::io;
use ratatui_core::{
backend::{Backend, WindowSize},
buffer::Cell,
layout::{Position, Size},
style::{Color, Modifier, Style},
};
use ratatui_core::backend::{Backend, WindowSize};
use ratatui_core::buffer::Cell;
use ratatui_core::layout::{Position, Size};
use ratatui_core::style::{Color, Modifier, Style};
pub use termwiz;
use termwiz::{
caps::Capabilities,
cell::{AttributeChange, Blink, CellAttributes, Intensity, Underline},
color::{AnsiColor, ColorAttribute, ColorSpec, LinearRgba, RgbColor, SrgbaTuple},
surface::{Change, CursorVisibility, Position as TermwizPosition},
terminal::{buffered::BufferedTerminal, ScreenSize, SystemTerminal, Terminal},
};
use termwiz::caps::Capabilities;
use termwiz::cell::{AttributeChange, Blink, CellAttributes, Intensity, Underline};
use termwiz::color::{AnsiColor, ColorAttribute, ColorSpec, LinearRgba, RgbColor, SrgbaTuple};
use termwiz::surface::{Change, CursorVisibility, Position as TermwizPosition};
use termwiz::terminal::buffered::BufferedTerminal;
use termwiz::terminal::{ScreenSize, SystemTerminal, Terminal};
/// A [`Backend`] implementation that uses [Termwiz] to render to the terminal.
///
@ -48,7 +46,8 @@ use termwiz::{
/// # Example
///
/// ```rust,no_run
/// use ratatui::{backend::TermwizBackend, Terminal};
/// use ratatui::backend::TermwizBackend;
/// use ratatui::Terminal;
///
/// let backend = TermwizBackend::new()?;
/// let mut terminal = Terminal::new(backend)?;

View File

@ -48,6 +48,7 @@ unstable-rendered-line-info = []
[dependencies]
bitflags.workspace = true
crossterm.workspace = true
document-features = { workspace = true, optional = true }
indoc.workspace = true
instability.workspace = true

View File

@ -17,14 +17,12 @@
use std::iter::zip;
use color_eyre::Result;
use ratatui::{
crossterm::event::{self, Event},
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Stylize},
text::{Line, Span},
widgets::{Bar, BarChart, BarGroup},
DefaultTerminal, Frame,
};
use crossterm::event::{self, Event};
use ratatui::layout::{Constraint, Direction, Layout, Rect};
use ratatui::style::{Color, Stylize};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Bar, BarChart, BarGroup};
use ratatui::{DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -15,14 +15,12 @@
//! [examples readme]: https://github.com/ratatui/ratatui/blob/main/examples/README.md
use color_eyre::Result;
use ratatui::{
crossterm::event::{self, Event},
layout::{Constraint, Layout, Rect},
style::Stylize,
text::{Line, Span},
widgets::{Bar, BarChart},
DefaultTerminal, Frame,
};
use crossterm::event::{self, Event};
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::style::Stylize;
use ratatui::text::{Line, Span};
use ratatui::widgets::{Bar, BarChart};
use ratatui::{DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -15,14 +15,12 @@
//! [examples readme]: https://github.com/ratatui/ratatui/blob/main/examples/README.md
use color_eyre::Result;
use ratatui::{
crossterm::event::{self, Event},
layout::{Constraint, Layout, Rect},
style::{Style, Stylize},
text::{Line, Span},
widgets::{Block, BorderType},
DefaultTerminal, Frame,
};
use crossterm::event::{self, Event};
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::style::{Style, Stylize};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, BorderType};
use ratatui::{DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -15,14 +15,12 @@
//! [examples readme]: https://github.com/ratatui/ratatui/blob/main/examples/README.md
use color_eyre::Result;
use ratatui::{
crossterm::event::{self, Event},
layout::{Constraint, Layout, Rect},
style::{Color, Modifier, Style, Stylize},
text::{Line, Span},
widgets::{Block, Padding},
DefaultTerminal, Frame,
};
use crossterm::event::{self, Event};
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::style::{Color, Modifier, Style, Stylize};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, Padding};
use ratatui::{DefaultTerminal, Frame};
use ratatui_widgets::calendar::{CalendarEventStore, Monthly};
use time::{Date, Month, OffsetDateTime};

View File

@ -15,15 +15,13 @@
//! [examples readme]: https://github.com/ratatui/ratatui/blob/main/examples/README.md
use color_eyre::Result;
use ratatui::{
crossterm::event::{self, Event},
layout::{Constraint, Layout, Rect},
style::{Color, Stylize},
symbols::Marker,
text::{Line as TextLine, Span},
widgets::canvas::{Canvas, Line, Map, MapResolution, Rectangle},
DefaultTerminal, Frame,
};
use crossterm::event::{self, Event};
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::style::{Color, Stylize};
use ratatui::symbols::Marker;
use ratatui::text::{Line as TextLine, Span};
use ratatui::widgets::canvas::{Canvas, Line, Map, MapResolution, Rectangle};
use ratatui::{DefaultTerminal, Frame};
use ratatui_widgets::canvas::Points;
fn main() -> Result<()> {

View File

@ -15,15 +15,13 @@
//! [examples readme]: https://github.com/ratatui/ratatui/blob/main/examples/README.md
use color_eyre::Result;
use ratatui::{
crossterm::event::{self, Event},
layout::{Constraint, Layout, Rect},
style::{Color, Stylize},
symbols::Marker,
text::{Line, Span},
widgets::{Axis, Chart, Dataset, GraphType},
DefaultTerminal, Frame,
};
use crossterm::event::{self, Event};
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::style::{Color, Stylize};
use ratatui::symbols::Marker;
use ratatui::text::{Line, Span};
use ratatui::widgets::{Axis, Chart, Dataset, GraphType};
use ratatui::{DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -15,15 +15,12 @@
//! [examples readme]: https://github.com/ratatui/ratatui/blob/main/examples/README.md
use color_eyre::Result;
use ratatui::{
crossterm::event::{self, Event},
layout::{Constraint, Layout, Rect},
style::{Modifier, Style, Stylize},
symbols,
text::{Line, Span},
widgets::{Gauge, LineGauge},
DefaultTerminal, Frame,
};
use crossterm::event::{self, Event};
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::style::{Modifier, Style, Stylize};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Gauge, LineGauge};
use ratatui::{symbols, DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -17,17 +17,14 @@
use std::time::Duration;
use color_eyre::Result;
use ratatui::{
buffer::Buffer,
crossterm::event::{self, Event, KeyCode, KeyEventKind},
layout::{
Constraint::{Length, Min},
Layout, Rect,
},
style::{palette::tailwind, Style, Stylize},
widgets::{LineGauge, Paragraph, Widget},
DefaultTerminal,
};
use crossterm::event::{self, Event, KeyCode, KeyEventKind};
use ratatui::buffer::Buffer;
use ratatui::layout::Constraint::{Length, Min};
use ratatui::layout::{Layout, Rect};
use ratatui::style::palette::tailwind;
use ratatui::style::{Style, Stylize};
use ratatui::widgets::{LineGauge, Paragraph, Widget};
use ratatui::DefaultTerminal;
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -15,14 +15,12 @@
//! [examples readme]: https://github.com/ratatui/ratatui/blob/main/examples/README.md
use color_eyre::Result;
use ratatui::{
crossterm::event::{self, Event, KeyCode},
layout::{Constraint, Layout, Rect},
style::{Color, Modifier, Style, Stylize},
text::{Line, Span},
widgets::{List, ListDirection, ListState},
DefaultTerminal, Frame,
};
use crossterm::event::{self, Event, KeyCode};
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::style::{Color, Modifier, Style, Stylize};
use ratatui::text::{Line, Span};
use ratatui::widgets::{List, ListDirection, ListState};
use ratatui::{DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -17,12 +17,10 @@
use std::env::args;
use color_eyre::Result;
use ratatui::{
crossterm::event::{self, Event},
layout::{Constraint, Layout},
widgets::{RatatuiLogo, RatatuiLogoSize},
DefaultTerminal, Frame, TerminalOptions, Viewport,
};
use crossterm::event::{self, Event};
use ratatui::layout::{Constraint, Layout};
use ratatui::widgets::{RatatuiLogo, RatatuiLogoSize};
use ratatui::{DefaultTerminal, Frame, TerminalOptions, Viewport};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -15,14 +15,12 @@
//! [examples readme]: https://github.com/ratatui/ratatui/blob/main/examples/README.md
use color_eyre::Result;
use ratatui::{
crossterm::event::{self, Event},
layout::{Alignment, Constraint, Layout, Rect},
style::{Color, Stylize},
text::{Line, Masked, Span},
widgets::{Paragraph, Wrap},
DefaultTerminal, Frame,
};
use crossterm::event::{self, Event};
use ratatui::layout::{Alignment, Constraint, Layout, Rect};
use ratatui::style::{Color, Stylize};
use ratatui::text::{Line, Masked, Span};
use ratatui::widgets::{Paragraph, Wrap};
use ratatui::{DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -15,15 +15,13 @@
//! [examples readme]: https://github.com/ratatui/ratatui/blob/main/examples/README.md
use color_eyre::Result;
use ratatui::{
crossterm::event::{self, Event, KeyCode},
layout::{Constraint, Layout, Margin, Rect},
style::{Color, Stylize},
symbols::scrollbar::Set,
text::{Line, Span},
widgets::{Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState},
DefaultTerminal, Frame,
};
use crossterm::event::{self, Event, KeyCode};
use ratatui::layout::{Constraint, Layout, Margin, Rect};
use ratatui::style::{Color, Stylize};
use ratatui::symbols::scrollbar::Set;
use ratatui::text::{Line, Span};
use ratatui::widgets::{Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState};
use ratatui::{DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -17,15 +17,12 @@
use std::time::Duration;
use color_eyre::Result;
use ratatui::{
crossterm::event::{self, Event},
layout::{Constraint, Layout, Rect},
style::{Color, Style, Stylize},
symbols,
text::{Line, Span},
widgets::{RenderDirection, Sparkline},
DefaultTerminal, Frame,
};
use crossterm::event::{self, Event};
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::style::{Color, Style, Stylize};
use ratatui::text::{Line, Span};
use ratatui::widgets::{RenderDirection, Sparkline};
use ratatui::{symbols, DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -15,14 +15,12 @@
//! [examples readme]: https://github.com/ratatui/ratatui/blob/main/examples/README.md
use color_eyre::Result;
use ratatui::{
crossterm::event::{self, Event, KeyCode},
layout::{Constraint, Layout, Rect},
style::{Color, Style, Stylize},
text::{Line, Span},
widgets::{Row, Table, TableState},
DefaultTerminal, Frame,
};
use crossterm::event::{self, Event, KeyCode};
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::style::{Color, Style, Stylize};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Row, Table, TableState};
use ratatui::{DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -15,15 +15,12 @@
//! [examples readme]: https://github.com/ratatui/ratatui/blob/main/examples/README.md
use color_eyre::Result;
use ratatui::{
crossterm::event::{self, Event, KeyCode},
layout::{Alignment, Constraint, Layout, Offset, Rect},
style::{Color, Style, Stylize},
symbols,
text::{Line, Span},
widgets::{Block, Paragraph, Tabs},
DefaultTerminal, Frame,
};
use crossterm::event::{self, Event, KeyCode};
use ratatui::layout::{Alignment, Constraint, Layout, Offset, Rect};
use ratatui::style::{Color, Style, Stylize};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, Paragraph, Tabs};
use ratatui::{symbols, DefaultTerminal, Frame};
fn main() -> Result<()> {
color_eyre::install()?;

View File

@ -1,15 +1,14 @@
//! The [`BarChart`] widget and its related types (e.g. [`Bar`], [`BarGroup`]).
use ratatui_core::{
buffer::Buffer,
layout::{Direction, Rect},
style::{Style, Styled},
symbols::{self},
text::Line,
widgets::Widget,
};
use ratatui_core::buffer::Buffer;
use ratatui_core::layout::{Direction, Rect};
use ratatui_core::style::{Style, Styled};
use ratatui_core::symbols;
use ratatui_core::text::Line;
use ratatui_core::widgets::Widget;
pub use self::{bar::Bar, bar_group::BarGroup};
pub use self::bar::Bar;
pub use self::bar_group::BarGroup;
use crate::block::{Block, BlockExt};
mod bar;
@ -51,10 +50,8 @@ mod bar_group;
/// The first group is added by an array slice (`&[(&str, u64)]`).
/// The second group is added by a [`BarGroup`] instance.
/// ```
/// use ratatui::{
/// style::{Style, Stylize},
/// widgets::{Bar, BarChart, BarGroup, Block},
/// };
/// use ratatui::style::{Style, Stylize};
/// use ratatui::widgets::{Bar, BarChart, BarGroup, Block};
///
/// BarChart::default()
/// .block(Block::bordered().title("BarChart"))
@ -135,10 +132,8 @@ impl<'a> BarChart<'a> {
/// # Examples
///
/// ```rust
/// use ratatui::{
/// layout::Direction,
/// widgets::{Bar, BarChart},
/// };
/// use ratatui::layout::Direction;
/// use ratatui::widgets::{Bar, BarChart};
///
/// BarChart::new(vec![Bar::with_label("A", 10), Bar::with_label("B", 10)]);
/// ```
@ -696,11 +691,9 @@ impl Styled for BarChart<'_> {
#[cfg(test)]
mod tests {
use itertools::iproduct;
use ratatui_core::{
layout::Alignment,
style::{Color, Modifier, Stylize},
text::Span,
};
use ratatui_core::layout::Alignment;
use ratatui_core::style::{Color, Modifier, Stylize};
use ratatui_core::text::Span;
use super::*;
use crate::borders::BorderType;

View File

@ -1,10 +1,8 @@
use ratatui_core::{
buffer::Buffer,
layout::Rect,
style::{Style, Styled},
text::Line,
widgets::Widget,
};
use ratatui_core::buffer::Buffer;
use ratatui_core::layout::Rect;
use ratatui_core::style::{Style, Styled};
use ratatui_core::text::Line;
use ratatui_core::widgets::Widget;
use unicode_width::UnicodeWidthStr;
/// A bar to be shown by the [`BarChart`](super::BarChart) widget.
@ -22,10 +20,8 @@ use unicode_width::UnicodeWidthStr;
/// The following example creates a bar with the label "Bar 1", a value "10",
/// red background and a white value foreground.
/// ```
/// use ratatui::{
/// style::{Style, Stylize},
/// widgets::Bar,
/// };
/// use ratatui::style::{Style, Stylize};
/// use ratatui::widgets::Bar;
///
/// Bar::with_label("Bar 1", 10)
/// .red()
@ -119,7 +115,9 @@ impl<'a> Bar<'a> {
/// From a [`Line`] with red foreground color:
///
/// ```rust
/// use ratatui::{style::Stylize, text::Line, widgets::Bar};
/// use ratatui::style::Stylize;
/// use ratatui::text::Line;
/// use ratatui::widgets::Bar;
///
/// Bar::default().label(Line::from("Line").red());
/// ```

View File

@ -1,10 +1,8 @@
use ratatui_core::{
buffer::Buffer,
layout::{Alignment, Rect},
style::Style,
text::Line,
widgets::Widget,
};
use ratatui_core::buffer::Buffer;
use ratatui_core::layout::{Alignment, Rect};
use ratatui_core::style::Style;
use ratatui_core::text::Line;
use ratatui_core::widgets::Widget;
use crate::barchart::Bar;
@ -31,10 +29,8 @@ impl<'a> BarGroup<'a> {
/// # Examples
///
/// ```
/// use ratatui::{
/// style::{Style, Stylize},
/// widgets::{Bar, BarGroup},
/// };
/// use ratatui::style::{Style, Stylize};
/// use ratatui::widgets::{Bar, BarGroup};
///
/// let group = BarGroup::new(vec![Bar::with_label("A", 10), Bar::with_label("B", 20)]);
/// ```
@ -63,7 +59,9 @@ impl<'a> BarGroup<'a> {
/// From a [`Line`] with red foreground color:
///
/// ```rust
/// use ratatui::{style::Stylize, text::Line, widgets::BarGroup};
/// use ratatui::style::Stylize;
/// use ratatui::text::Line;
/// use ratatui::widgets::BarGroup;
///
/// BarGroup::default().label(Line::from("Line").red());
/// ```

View File

@ -7,19 +7,15 @@
#![allow(deprecated)] // to avoid having to add `#[deprecated]` to every use of `Title`
use itertools::Itertools;
use ratatui_core::{
buffer::Buffer,
layout::{Alignment, Rect},
style::{Style, Styled},
symbols::border,
text::Line,
widgets::Widget,
};
use ratatui_core::buffer::Buffer;
use ratatui_core::layout::{Alignment, Rect};
use ratatui_core::style::{Style, Styled};
use ratatui_core::symbols::border;
use ratatui_core::text::Line;
use ratatui_core::widgets::Widget;
pub use self::{
padding::Padding,
title::{Position, Title},
};
pub use self::padding::Padding;
pub use self::title::{Position, Title};
use crate::borders::{BorderType, Borders};
mod padding;
@ -76,10 +72,8 @@ pub mod title;
/// # Examples
///
/// ```
/// use ratatui::{
/// style::{Color, Style},
/// widgets::{Block, BorderType, Borders},
/// };
/// use ratatui::style::{Color, Style};
/// use ratatui::widgets::{Block, BorderType, Borders};
///
/// Block::new()
/// .border_type(BorderType::Rounded)
@ -91,10 +85,8 @@ pub mod title;
///
/// You may also use multiple titles like in the following:
/// ```
/// use ratatui::widgets::{
/// block::{Position, Title},
/// Block,
/// };
/// use ratatui::widgets::block::{Position, Title};
/// use ratatui::widgets::Block;
///
/// Block::new()
/// .title("Title 1")
@ -201,10 +193,8 @@ impl<'a> Block<'a> {
/// the leftover space)
/// - Two titles with the same alignment (notice the left titles are separated)
/// ```
/// use ratatui::{
/// text::Line,
/// widgets::{Block, Borders},
/// };
/// use ratatui::text::Line;
/// use ratatui::widgets::{Block, Borders};
///
/// Block::new()
/// .title("Title") // By default in the top left corner
@ -330,7 +320,9 @@ impl<'a> Block<'a> {
/// This example aligns all titles in the center except the "right" title which explicitly sets
/// [`Alignment::Right`].
/// ```
/// use ratatui::{layout::Alignment, text::Line, widgets::Block};
/// use ratatui::layout::Alignment;
/// use ratatui::text::Line;
/// use ratatui::widgets::Block;
///
/// Block::new()
/// .title_alignment(Alignment::Center)
@ -354,7 +346,8 @@ impl<'a> Block<'a> {
/// This example positions all titles on the bottom except the "top" title which explicitly sets
/// [`Position::Top`].
/// ```
/// use ratatui::widgets::{block::Position, Block};
/// use ratatui::widgets::block::Position;
/// use ratatui::widgets::Block;
///
/// Block::new()
/// .title_position(Position::Bottom)
@ -383,10 +376,8 @@ impl<'a> Block<'a> {
///
/// This example shows a `Block` with blue borders.
/// ```
/// use ratatui::{
/// style::{Style, Stylize},
/// widgets::Block,
/// };
/// use ratatui::style::{Style, Stylize};
/// use ratatui::widgets::Block;
/// Block::bordered().border_style(Style::new().blue());
/// ```
///
@ -413,10 +404,8 @@ impl<'a> Block<'a> {
/// # Example
///
/// ```
/// use ratatui::{
/// style::{Color, Style, Stylize},
/// widgets::{Block, Paragraph},
/// };
/// use ratatui::style::{Color, Style, Stylize};
/// use ratatui::widgets::{Block, Paragraph};
///
/// let block = Block::new().style(Style::new().red().on_black());
///
@ -545,7 +534,8 @@ impl<'a> Block<'a> {
///
/// Draw a block nested within another block
/// ```
/// use ratatui::{widgets::Block, Frame};
/// use ratatui::widgets::Block;
/// use ratatui::Frame;
///
/// # fn render_nested_block(frame: &mut Frame) {
/// let outer_block = Block::bordered().title("Outer");

View File

@ -1,7 +1,8 @@
//! This module holds the [`Title`] element and its related configuration types.
//! A title is a piece of [`Block`](crate::block::Block) configuration.
use ratatui_core::{layout::Alignment, text::Line};
use ratatui_core::layout::Alignment;
use ratatui_core::text::Line;
use strum::{Display, EnumString};
/// A [`Block`](crate::block::Block) title.
@ -30,27 +31,26 @@ use strum::{Display, EnumString};
///
/// Blue title on a white background (via [`Stylize`](ratatui_core::style::Stylize) trait).
/// ```
/// use ratatui::{style::Stylize, widgets::block::Title};
/// use ratatui::style::Stylize;
/// use ratatui::widgets::block::Title;
///
/// Title::from("Title".blue().on_white());
/// ```
///
/// Title with multiple styles (see [`Line`] and [`Stylize`](ratatui_core::style::Stylize)).
/// ```
/// use ratatui::{style::Stylize, text::Line, widgets::block::Title};
/// use ratatui::style::Stylize;
/// use ratatui::text::Line;
/// use ratatui::widgets::block::Title;
///
/// Title::from(Line::from(vec!["Q".white().underlined(), "uit".gray()]));
/// ```
///
/// Complete example
/// ```
/// use ratatui::{
/// layout::Alignment,
/// widgets::{
/// block::{Position, Title},
/// Block,
/// },
/// };
/// use ratatui::layout::Alignment;
/// use ratatui::widgets::block::{Position, Title};
/// use ratatui::widgets::Block;
///
/// Title::from("Title")
/// .position(Position::Top)
@ -84,10 +84,8 @@ pub struct Title<'a> {
/// # Example
///
/// ```
/// use ratatui::widgets::{
/// block::{Position, Title},
/// Block,
/// };
/// use ratatui::widgets::block::{Position, Title};
/// use ratatui::widgets::Block;
///
/// Block::new().title(Title::from("title").position(Position::Bottom));
/// ```

View File

@ -209,10 +209,8 @@ impl fmt::Debug for Borders {
/// ## Examples
///
/// ```
/// use ratatui::{
/// border,
/// widgets::{Block, Borders},
/// };
/// use ratatui::border;
/// use ratatui::widgets::{Block, Borders};
///
/// Block::new()
/// .title("Construct Borders and use them in place")
@ -222,7 +220,8 @@ impl fmt::Debug for Borders {
/// `border!` can be called with any number of individual sides:
///
/// ```
/// use ratatui::{border, widgets::Borders};
/// use ratatui::border;
/// use ratatui::widgets::Borders;
/// let right_open = border!(TOP, LEFT, BOTTOM);
/// assert_eq!(right_open, Borders::TOP | Borders::LEFT | Borders::BOTTOM);
/// ```
@ -230,7 +229,8 @@ impl fmt::Debug for Borders {
/// Single borders work but using `Borders::` directly would be simpler.
///
/// ```
/// use ratatui::{border, widgets::Borders};
/// use ratatui::border;
/// use ratatui::widgets::Borders;
///
/// assert_eq!(border!(TOP), Borders::TOP);
/// assert_eq!(border!(ALL), Borders::ALL);

View File

@ -10,13 +10,11 @@
//! [`Monthly`] has several controls for what should be displayed
use std::collections::HashMap;
use ratatui_core::{
buffer::Buffer,
layout::{Alignment, Constraint, Layout, Rect},
style::Style,
text::{Line, Span},
widgets::Widget,
};
use ratatui_core::buffer::Buffer;
use ratatui_core::layout::{Alignment, Constraint, Layout, Rect};
use ratatui_core::style::Style;
use ratatui_core::text::{Line, Span};
use ratatui_core::widgets::Widget;
use time::{Date, Duration, OffsetDateTime};
use crate::block::{Block, BlockExt};

View File

@ -13,25 +13,22 @@
//!
//! You can also implement your own custom [`Shape`]s.
use std::{fmt, iter::zip};
use std::fmt;
use std::iter::zip;
use itertools::Itertools;
use ratatui_core::{
buffer::Buffer,
layout::Rect,
style::{Color, Style},
symbols::{self, Marker},
text::Line as TextLine,
widgets::Widget,
};
use ratatui_core::buffer::Buffer;
use ratatui_core::layout::Rect;
use ratatui_core::style::{Color, Style};
use ratatui_core::symbols::{self, Marker};
use ratatui_core::text::Line as TextLine;
use ratatui_core::widgets::Widget;
pub use self::{
circle::Circle,
line::Line,
map::{Map, MapResolution},
points::Points,
rectangle::Rectangle,
};
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 crate::block::{Block, BlockExt};
mod circle;
@ -368,10 +365,8 @@ impl Painter<'_, '_> {
/// # Examples
///
/// ```
/// use ratatui::{
/// symbols,
/// widgets::canvas::{Context, Painter},
/// };
/// use ratatui::symbols;
/// use ratatui::widgets::canvas::{Context, Painter};
///
/// let mut ctx = Context::new(2, 2, [1.0, 2.0], [0.0, 2.0], symbols::Marker::Braille);
/// let mut painter = Painter::from(&mut ctx);
@ -412,11 +407,9 @@ impl Painter<'_, '_> {
/// # Example
///
/// ```
/// use ratatui::{
/// style::Color,
/// symbols,
/// widgets::canvas::{Context, Painter},
/// };
/// use ratatui::style::Color;
/// use ratatui::symbols;
/// use ratatui::widgets::canvas::{Context, Painter};
///
/// let mut ctx = Context::new(1, 1, [0.0, 2.0], [0.0, 2.0], symbols::Marker::Braille);
/// let mut painter = Painter::from(&mut ctx);
@ -431,11 +424,9 @@ impl Painter<'_, '_> {
/// # Example
///
/// ```
/// use ratatui::{
/// style::Color,
/// symbols,
/// widgets::canvas::{Context, Painter},
/// };
/// use ratatui::style::Color;
/// use ratatui::symbols;
/// use ratatui::widgets::canvas::{Context, Painter};
///
/// let mut ctx = Context::new(1, 1, [0.0, 2.0], [0.0, 2.0], symbols::Marker::Braille);
/// let mut painter = Painter::from(&mut ctx);
@ -483,7 +474,8 @@ impl<'a> Context<'a> {
/// example, if you want to draw a map of the world, you might want to use the following bounds:
///
/// ```
/// use ratatui::{symbols, widgets::canvas::Context};
/// use ratatui::symbols;
/// use ratatui::widgets::canvas::Context;
///
/// let ctx = Context::new(
/// 100,
@ -597,13 +589,9 @@ impl<'a> Context<'a> {
/// # Examples
///
/// ```
/// use ratatui::{
/// style::Color,
/// widgets::{
/// canvas::{Canvas, Line, Map, MapResolution, Rectangle},
/// Block,
/// },
/// };
/// use ratatui::style::Color;
/// use ratatui::widgets::canvas::{Canvas, Line, Map, MapResolution, Rectangle};
/// use ratatui::widgets::Block;
///
/// Canvas::default()
/// .block(Block::bordered().title("Canvas"))
@ -737,7 +725,8 @@ where
/// # Examples
///
/// ```
/// use ratatui::{symbols, widgets::canvas::Canvas};
/// use ratatui::symbols;
/// use ratatui::widgets::canvas::Canvas;
///
/// Canvas::default()
/// .marker(symbols::Marker::Braille)

View File

@ -42,9 +42,11 @@ impl Shape for Circle {
#[cfg(test)]
mod tests {
use ratatui_core::{
buffer::Buffer, layout::Rect, style::Color, symbols::Marker, widgets::Widget,
};
use ratatui_core::buffer::Buffer;
use ratatui_core::layout::Rect;
use ratatui_core::style::Color;
use ratatui_core::symbols::Marker;
use ratatui_core::widgets::Widget;
use crate::canvas::{Canvas, Circle};

View File

@ -141,13 +141,11 @@ fn draw_line_high(painter: &mut Painter, x1: usize, y1: usize, x2: usize, y2: us
#[cfg(test)]
mod tests {
use ratatui_core::{
buffer::Buffer,
layout::Rect,
style::{Style, Stylize},
symbols::Marker,
widgets::Widget,
};
use ratatui_core::buffer::Buffer;
use ratatui_core::layout::Rect;
use ratatui_core::style::{Style, Stylize};
use ratatui_core::symbols::Marker;
use ratatui_core::widgets::Widget;
use rstest::rstest;
use super::*;

View File

@ -1,10 +1,8 @@
use ratatui_core::style::Color;
use strum::{Display, EnumString};
use crate::canvas::{
world::{WORLD_HIGH_RESOLUTION, WORLD_LOW_RESOLUTION},
Painter, Shape,
};
use crate::canvas::world::{WORLD_HIGH_RESOLUTION, WORLD_LOW_RESOLUTION};
use crate::canvas::{Painter, Shape};
/// Defines how many points are going to be used to draw a [`Map`].
///
@ -60,7 +58,10 @@ impl Shape for Map {
#[cfg(test)]
mod tests {
use ratatui_core::{buffer::Buffer, layout::Rect, symbols::Marker, widgets::Widget};
use ratatui_core::buffer::Buffer;
use ratatui_core::layout::Rect;
use ratatui_core::symbols::Marker;
use ratatui_core::widgets::Widget;
use strum::ParseError;
use super::*;

View File

@ -77,13 +77,11 @@ impl Shape for Rectangle {
#[cfg(test)]
mod tests {
use ratatui_core::{
buffer::Buffer,
layout::{Margin, Rect},
style::{Style, Stylize},
symbols::Marker,
widgets::Widget,
};
use ratatui_core::buffer::Buffer;
use ratatui_core::layout::{Margin, Rect};
use ratatui_core::style::{Style, Stylize};
use ratatui_core::symbols::Marker;
use ratatui_core::widgets::Widget;
use super::*;
use crate::canvas::Canvas;

View File

@ -1,20 +1,17 @@
//! The [`Chart`] widget is used to plot one or more [`Dataset`] in a cartesian coordinate system.
use std::{cmp::max, ops::Not};
use std::cmp::max;
use std::ops::Not;
use ratatui_core::{
buffer::Buffer,
layout::{Alignment, Constraint, Flex, Layout, Position, Rect},
style::{Color, Style, Styled},
symbols::{self},
text::Line,
widgets::Widget,
};
use ratatui_core::buffer::Buffer;
use ratatui_core::layout::{Alignment, Constraint, Flex, Layout, Position, Rect};
use ratatui_core::style::{Color, Style, Styled};
use ratatui_core::symbols;
use ratatui_core::text::Line;
use ratatui_core::widgets::Widget;
use strum::{Display, EnumString};
use crate::{
block::{Block, BlockExt},
canvas::{Canvas, Line as CanvasLine, Points},
};
use crate::block::{Block, BlockExt};
use crate::canvas::{Canvas, Line as CanvasLine, Points};
/// An X or Y axis for the [`Chart`] widget
///
@ -29,10 +26,8 @@ use crate::{
/// # Example
///
/// ```rust
/// use ratatui::{
/// style::{Style, Stylize},
/// widgets::Axis,
/// };
/// use ratatui::style::{Style, Stylize};
/// use ratatui::widgets::Axis;
///
/// let axis = Axis::default()
/// .title("X Axis")
@ -102,7 +97,8 @@ impl<'a> Axis<'a> {
/// # Examples
///
/// ```rust
/// use ratatui::{style::Stylize, widgets::Axis};
/// use ratatui::style::Stylize;
/// use ratatui::widgets::Axis;
///
/// let axis = Axis::default()
/// .bounds([0.0, 50.0])
@ -131,7 +127,8 @@ impl<'a> Axis<'a> {
/// it like so
///
/// ```rust
/// use ratatui::{style::Stylize, widgets::Axis};
/// use ratatui::style::Stylize;
/// use ratatui::widgets::Axis;
///
/// let axis = Axis::default().red();
/// ```
@ -307,11 +304,9 @@ impl LegendPosition {
/// This example draws a red line between two points.
///
/// ```rust
/// use ratatui::{
/// style::Stylize,
/// symbols::Marker,
/// widgets::{Dataset, GraphType},
/// };
/// use ratatui::style::Stylize;
/// use ratatui::symbols::Marker;
/// use ratatui::widgets::{Dataset, GraphType};
///
/// let dataset = Dataset::default()
/// .name("dataset 1")
@ -415,7 +410,8 @@ impl<'a> Dataset<'a> {
/// style it like so
///
/// ```rust
/// use ratatui::{style::Stylize, widgets::Dataset};
/// use ratatui::style::Stylize;
/// use ratatui::widgets::Dataset;
///
/// let dataset = Dataset::default().red();
/// ```
@ -467,11 +463,9 @@ struct ChartLayout {
/// # Examples
///
/// ```
/// use ratatui::{
/// style::{Style, Stylize},
/// symbols,
/// widgets::{Axis, Block, Chart, Dataset, GraphType},
/// };
/// use ratatui::style::{Style, Stylize};
/// use ratatui::symbols;
/// use ratatui::widgets::{Axis, Block, Chart, Dataset, GraphType};
///
/// // Create the datasets to fill the chart with
/// let datasets = vec![
@ -658,7 +652,8 @@ impl<'a> Chart<'a> {
/// its height is greater than 25% of the total widget height.
///
/// ```
/// use ratatui::{layout::Constraint, widgets::Chart};
/// use ratatui::layout::Constraint;
/// use ratatui::widgets::Chart;
///
/// let constraints = (Constraint::Ratio(1, 3), Constraint::Ratio(1, 4));
/// let chart = Chart::new(vec![]).hidden_legend_constraints(constraints);
@ -668,7 +663,8 @@ impl<'a> Chart<'a> {
/// first one is always true.
///
/// ```
/// use ratatui::{layout::Constraint, widgets::Chart};
/// use ratatui::layout::Constraint;
/// use ratatui::widgets::Chart;
///
/// let constraints = (Constraint::Min(0), Constraint::Ratio(1, 4));
/// let chart = Chart::new(vec![]).hidden_legend_constraints(constraints);
@ -678,7 +674,8 @@ impl<'a> Chart<'a> {
/// [`Chart::legend_position`].
///
/// ```
/// use ratatui::{layout::Constraint, widgets::Chart};
/// use ratatui::layout::Constraint;
/// use ratatui::widgets::Chart;
///
/// let constraints = (Constraint::Length(0), Constraint::Ratio(1, 4));
/// let chart = Chart::new(vec![]).hidden_legend_constraints(constraints);

View File

@ -1,5 +1,7 @@
//! The [`Clear`] widget allows you to clear a certain area to allow overdrawing (e.g. for popups).
use ratatui_core::{buffer::Buffer, layout::Rect, widgets::Widget};
use ratatui_core::buffer::Buffer;
use ratatui_core::layout::Rect;
use ratatui_core::widgets::Widget;
/// A widget to clear/reset a certain area to allow overdrawing (e.g. for popups).
///
@ -9,11 +11,9 @@ use ratatui_core::{buffer::Buffer, layout::Rect, widgets::Widget};
/// # Examples
///
/// ```
/// use ratatui::{
/// layout::Rect,
/// widgets::{Block, Clear},
/// Frame,
/// };
/// use ratatui::layout::Rect;
/// use ratatui::widgets::{Block, Clear};
/// use ratatui::Frame;
///
/// fn draw_on_clear(f: &mut Frame, area: Rect) {
/// let block = Block::bordered().title("Block");
@ -47,7 +47,9 @@ impl Widget for &Clear {
#[cfg(test)]
mod tests {
use ratatui_core::{buffer::Buffer, layout::Rect, widgets::Widget};
use ratatui_core::buffer::Buffer;
use ratatui_core::layout::Rect;
use ratatui_core::widgets::Widget;
use super::*;

Some files were not shown because too many files have changed in this diff Show More