Skip to content

Commit 910ad00

Browse files
authored
chore(rustfmt): enable format_code_in_doc_comments (#695)
This enables more consistently formatted code in doc comments, especially since ratatui heavily uses fluent setters. See https://rust-lang.github.io/rustfmt/?version=v1.6.0#format_code_in_doc_comments
1 parent b282a06 commit 910ad00

24 files changed

+285
-173
lines changed

rustfmt.toml

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ group_imports = "StdExternalCrate"
33
imports_granularity = "Crate"
44
wrap_comments = true
55
comment_width = 100
6+
format_code_in_doc_comments = true

src/backend.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
//!
2727
//! ```rust,no_run
2828
//! use std::io::stdout;
29+
//!
2930
//! use ratatui::prelude::*;
3031
//!
3132
//! let backend = CrosstermBackend::new(stdout());

src/backend/crossterm.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ use crate::{
4343
/// # Example
4444
///
4545
/// ```rust,no_run
46-
/// use std::io::{stdout, stderr};
46+
/// use std::io::{stderr, stdout};
47+
///
4748
/// use crossterm::{
4849
/// terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
4950
/// ExecutableCommand,

src/backend/termion.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ use crate::{
3636
/// # Example
3737
///
3838
/// ```rust,no_run
39-
/// use std::io::{stdout, stderr};
39+
/// use std::io::{stderr, stdout};
40+
///
4041
/// use ratatui::prelude::*;
4142
/// use termion::{raw::IntoRawMode, screen::IntoAlternateScreen};
4243
///

src/buffer.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,23 @@ impl Default for Cell {
140140
/// # Examples:
141141
///
142142
/// ```
143-
/// use ratatui::{prelude::*, buffer::Cell};
143+
/// use ratatui::{buffer::Cell, prelude::*};
144144
///
145-
/// let mut buf = Buffer::empty(Rect{x: 0, y: 0, width: 10, height: 5});
145+
/// let mut buf = Buffer::empty(Rect {
146+
/// x: 0,
147+
/// y: 0,
148+
/// width: 10,
149+
/// height: 5,
150+
/// });
146151
/// buf.get_mut(0, 2).set_symbol("x");
147152
/// assert_eq!(buf.get(0, 2).symbol(), "x");
148153
///
149-
/// buf.set_string(3, 0, "string", Style::default().fg(Color::Red).bg(Color::White));
154+
/// buf.set_string(
155+
/// 3,
156+
/// 0,
157+
/// "string",
158+
/// Style::default().fg(Color::Red).bg(Color::White),
159+
/// );
150160
/// let cell = buf.get_mut(5, 0);
151161
/// assert_eq!(cell.symbol(), "r");
152162
/// assert_eq!(cell.fg, Color::Red);

src/layout.rs

+17-24
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl Layout {
268268
///
269269
/// let layout = Layout::new(
270270
/// Direction::Vertical,
271-
/// [1,2,3].iter().map(|&c| Constraint::Length(c)),
271+
/// [1, 2, 3].iter().map(|&c| Constraint::Length(c)),
272272
/// );
273273
/// ```
274274
pub fn new<I>(direction: Direction, constraints: I) -> Layout
@@ -353,19 +353,22 @@ impl Layout {
353353
/// Constraint::Max(2),
354354
/// ])
355355
/// .split(Rect::new(0, 0, 10, 10));
356-
/// assert_eq!(layout[..], [
357-
/// Rect::new(0, 0, 10, 2),
358-
/// Rect::new(0, 2, 10, 2),
359-
/// Rect::new(0, 4, 10, 2),
360-
/// Rect::new(0, 6, 10, 2),
361-
/// Rect::new(0, 8, 10, 2),
362-
/// ]);
356+
/// assert_eq!(
357+
/// layout[..],
358+
/// [
359+
/// Rect::new(0, 0, 10, 2),
360+
/// Rect::new(0, 2, 10, 2),
361+
/// Rect::new(0, 4, 10, 2),
362+
/// Rect::new(0, 6, 10, 2),
363+
/// Rect::new(0, 8, 10, 2),
364+
/// ]
365+
/// );
363366
///
364367
/// let layout = Layout::default().constraints([Constraint::Min(0)]);
365368
/// let layout = Layout::default().constraints(&[Constraint::Min(0)]);
366369
/// let layout = Layout::default().constraints(vec![Constraint::Min(0)]);
367370
/// let layout = Layout::default().constraints([Constraint::Min(0)].iter().filter(|_| true));
368-
/// let layout = Layout::default().constraints([1,2,3].iter().map(|&c| Constraint::Length(c)));
371+
/// let layout = Layout::default().constraints([1, 2, 3].iter().map(|&c| Constraint::Length(c)));
369372
/// ```
370373
#[must_use = "method moves the value of self and returns the modified value"]
371374
pub fn constraints<I>(mut self, constraints: I) -> Layout
@@ -660,9 +663,7 @@ impl Constraint {
660663
/// # use ratatui::prelude::*;
661664
/// # let area = Rect::default();
662665
/// let constraints = Constraint::from_lengths([1, 2, 3]);
663-
/// let layout = Layout::default()
664-
/// .constraints(constraints)
665-
/// .split(area);
666+
/// let layout = Layout::default().constraints(constraints).split(area);
666667
/// ```
667668
pub fn from_lengths<T>(lengths: T) -> Vec<Constraint>
668669
where
@@ -679,9 +680,7 @@ impl Constraint {
679680
/// # use ratatui::prelude::*;
680681
/// # let area = Rect::default();
681682
/// let constraints = Constraint::from_ratios([(1, 4), (1, 2), (1, 4)]);
682-
/// let layout = Layout::default()
683-
/// .constraints(constraints)
684-
/// .split(area);
683+
/// let layout = Layout::default().constraints(constraints).split(area);
685684
/// ```
686685
pub fn from_ratios<T>(ratios: T) -> Vec<Constraint>
687686
where
@@ -701,9 +700,7 @@ impl Constraint {
701700
/// # use ratatui::prelude::*;
702701
/// # let area = Rect::default();
703702
/// let constraints = Constraint::from_percentages([25, 50, 25]);
704-
/// let layout = Layout::default()
705-
/// .constraints(constraints)
706-
/// .split(area);
703+
/// let layout = Layout::default().constraints(constraints).split(area);
707704
/// ```
708705
pub fn from_percentages<T>(percentages: T) -> Vec<Constraint>
709706
where
@@ -723,9 +720,7 @@ impl Constraint {
723720
/// # use ratatui::prelude::*;
724721
/// # let area = Rect::default();
725722
/// let constraints = Constraint::from_maxes([1, 2, 3]);
726-
/// let layout = Layout::default()
727-
/// .constraints(constraints)
728-
/// .split(area);
723+
/// let layout = Layout::default().constraints(constraints).split(area);
729724
/// ```
730725
pub fn from_maxes<T>(maxes: T) -> Vec<Constraint>
731726
where
@@ -742,9 +737,7 @@ impl Constraint {
742737
/// # use ratatui::prelude::*;
743738
/// # let area = Rect::default();
744739
/// let constraints = Constraint::from_mins([1, 2, 3]);
745-
/// let layout = Layout::default()
746-
/// .constraints(constraints)
747-
/// .split(area);
740+
/// let layout = Layout::default().constraints(constraints).split(area);
748741
/// ```
749742
pub fn from_mins<T>(mins: T) -> Vec<Constraint>
750743
where

src/lib.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,11 @@
110110
//!
111111
//! ```rust,no_run
112112
//! use std::io::{self, stdout};
113+
//!
113114
//! use crossterm::{
114115
//! event::{self, Event, KeyCode},
116+
//! terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
115117
//! ExecutableCommand,
116-
//! terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}
117118
//! };
118119
//! use ratatui::{prelude::*, widgets::*};
119120
//!
@@ -139,7 +140,7 @@
139140
//! if key.kind == event::KeyEventKind::Press && key.code == KeyCode::Char('q') {
140141
//! return Ok(true);
141142
//! }
142-
//! }
143+
//! }
143144
//! }
144145
//! Ok(false)
145146
//! }
@@ -174,7 +175,7 @@
174175
//! Constraint::Length(1),
175176
//! Constraint::Min(0),
176177
//! Constraint::Length(1),
177-
//! ]
178+
//! ],
178179
//! )
179180
//! .split(frame.size());
180181
//! frame.render_widget(
@@ -188,7 +189,7 @@
188189
//!
189190
//! let inner_layout = Layout::new(
190191
//! Direction::Horizontal,
191-
//! [Constraint::Percentage(50), Constraint::Percentage(50)]
192+
//! [Constraint::Percentage(50), Constraint::Percentage(50)],
192193
//! )
193194
//! .split(main_layout[1]);
194195
//! frame.render_widget(
@@ -230,7 +231,7 @@
230231
//! Constraint::Length(1),
231232
//! Constraint::Length(1),
232233
//! Constraint::Min(0),
233-
//! ]
234+
//! ],
234235
//! )
235236
//! .split(frame.size());
236237
//!

src/style.rs

+46-20
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
//! use ratatui::prelude::*;
1717
//!
1818
//! let heading_style = Style::new()
19-
//! .fg(Color::Black)
20-
//! .bg(Color::Green)
21-
//! .add_modifier(Modifier::ITALIC | Modifier::BOLD);
19+
//! .fg(Color::Black)
20+
//! .bg(Color::Green)
21+
//! .add_modifier(Modifier::ITALIC | Modifier::BOLD);
2222
//! let span = Span::styled("hello", heading_style);
2323
//! ```
2424
//!
@@ -44,16 +44,24 @@
4444
//! use ratatui::{prelude::*, widgets::*};
4545
//!
4646
//! assert_eq!(
47-
//! "hello".red().on_blue().bold(),
47+
//! "hello".red().on_blue().bold(),
4848
//! Span::styled(
4949
//! "hello",
50-
//! Style::default().fg(Color::Red).bg(Color::Blue).add_modifier(Modifier::BOLD))
50+
//! Style::default()
51+
//! .fg(Color::Red)
52+
//! .bg(Color::Blue)
53+
//! .add_modifier(Modifier::BOLD)
54+
//! )
5155
//! );
5256
//!
5357
//! assert_eq!(
5458
//! Paragraph::new("hello").red().on_blue().bold(),
55-
//! Paragraph::new("hello")
56-
//! .style(Style::default().fg(Color::Red).bg(Color::Blue).add_modifier(Modifier::BOLD))
59+
//! Paragraph::new("hello").style(
60+
//! Style::default()
61+
//! .fg(Color::Red)
62+
//! .bg(Color::Blue)
63+
//! .add_modifier(Modifier::BOLD)
64+
//! )
5765
//! );
5866
//! ```
5967
//!
@@ -113,7 +121,7 @@ impl fmt::Debug for Modifier {
113121
/// Style lets you control the main characteristics of the displayed elements.
114122
///
115123
/// ```rust
116-
/// use ratatui::{prelude::*};
124+
/// use ratatui::prelude::*;
117125
///
118126
/// Style::default()
119127
/// .fg(Color::Black)
@@ -135,18 +143,24 @@ impl fmt::Debug for Modifier {
135143
/// just S3.
136144
///
137145
/// ```rust
138-
/// use ratatui::{prelude::*};
146+
/// use ratatui::prelude::*;
139147
///
140148
/// let styles = [
141-
/// Style::default().fg(Color::Blue).add_modifier(Modifier::BOLD | Modifier::ITALIC),
142-
/// Style::default().bg(Color::Red).add_modifier(Modifier::UNDERLINED),
149+
/// Style::default()
150+
/// .fg(Color::Blue)
151+
/// .add_modifier(Modifier::BOLD | Modifier::ITALIC),
152+
/// Style::default()
153+
/// .bg(Color::Red)
154+
/// .add_modifier(Modifier::UNDERLINED),
143155
/// #[cfg(feature = "underline-color")]
144156
/// Style::default().underline_color(Color::Green),
145-
/// Style::default().fg(Color::Yellow).remove_modifier(Modifier::ITALIC),
157+
/// Style::default()
158+
/// .fg(Color::Yellow)
159+
/// .remove_modifier(Modifier::ITALIC),
146160
/// ];
147161
/// let mut buffer = Buffer::empty(Rect::new(0, 0, 1, 1));
148162
/// for style in &styles {
149-
/// buffer.get_mut(0, 0).set_style(*style);
163+
/// buffer.get_mut(0, 0).set_style(*style);
150164
/// }
151165
/// assert_eq!(
152166
/// Style {
@@ -165,15 +179,17 @@ impl fmt::Debug for Modifier {
165179
/// reset all properties until that point use [`Style::reset`].
166180
///
167181
/// ```
168-
/// use ratatui::{prelude::*};
182+
/// use ratatui::prelude::*;
169183
///
170184
/// let styles = [
171-
/// Style::default().fg(Color::Blue).add_modifier(Modifier::BOLD | Modifier::ITALIC),
185+
/// Style::default()
186+
/// .fg(Color::Blue)
187+
/// .add_modifier(Modifier::BOLD | Modifier::ITALIC),
172188
/// Style::reset().fg(Color::Yellow),
173189
/// ];
174190
/// let mut buffer = Buffer::empty(Rect::new(0, 0, 1, 1));
175191
/// for style in &styles {
176-
/// buffer.get_mut(0, 0).set_style(*style);
192+
/// buffer.get_mut(0, 0).set_style(*style);
177193
/// }
178194
/// assert_eq!(
179195
/// Style {
@@ -285,9 +301,18 @@ impl Style {
285301
///
286302
/// ```rust
287303
/// # use ratatui::prelude::*;
288-
/// let style = Style::default().underline_color(Color::Blue).add_modifier(Modifier::UNDERLINED);
289-
/// let diff = Style::default().underline_color(Color::Red).add_modifier(Modifier::UNDERLINED);
290-
/// assert_eq!(style.patch(diff), Style::default().underline_color(Color::Red).add_modifier(Modifier::UNDERLINED));
304+
/// let style = Style::default()
305+
/// .underline_color(Color::Blue)
306+
/// .add_modifier(Modifier::UNDERLINED);
307+
/// let diff = Style::default()
308+
/// .underline_color(Color::Red)
309+
/// .add_modifier(Modifier::UNDERLINED);
310+
/// assert_eq!(
311+
/// style.patch(diff),
312+
/// Style::default()
313+
/// .underline_color(Color::Red)
314+
/// .add_modifier(Modifier::UNDERLINED)
315+
/// );
291316
/// ```
292317
#[cfg(feature = "underline-color")]
293318
#[must_use = "`underline_color` returns the modified style without modifying the original"]
@@ -349,7 +374,8 @@ impl Style {
349374
/// let combined = style_1.patch(style_2);
350375
/// assert_eq!(
351376
/// Style::default().patch(style_1).patch(style_2),
352-
/// Style::default().patch(combined));
377+
/// Style::default().patch(combined)
378+
/// );
353379
/// ```
354380
#[must_use = "`patch` returns the modified style without modifying the original"]
355381
pub fn patch(mut self, other: Style) -> Style {

src/style/color.rs

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use std::{
3939
///
4040
/// ```
4141
/// use std::str::FromStr;
42+
///
4243
/// use ratatui::prelude::*;
4344
///
4445
/// assert_eq!(Color::from_str("red"), Ok(Color::Red));
@@ -147,6 +148,7 @@ impl std::error::Error for ParseColorError {}
147148
///
148149
/// ```
149150
/// use std::str::FromStr;
151+
///
150152
/// use ratatui::prelude::*;
151153
///
152154
/// let color: Color = Color::from_str("blue").unwrap();

src/style/stylize.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ macro_rules! modifier {
127127
/// "world".green().on_yellow().not_bold(),
128128
/// ]);
129129
/// let paragraph = Paragraph::new(line).italic().underlined();
130-
/// let block = Block::default().title("Title").borders(Borders::ALL).on_white().bold();
130+
/// let block = Block::default()
131+
/// .title("Title")
132+
/// .borders(Borders::ALL)
133+
/// .on_white()
134+
/// .bold();
131135
/// ```
132136
pub trait Stylize<'a, T>: Sized {
133137
#[must_use = "`bg` returns the modified style without modifying the original"]

0 commit comments

Comments
 (0)