mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-22 20:53:19 +00:00
chore: fix all clippy warnings
This commit is contained in:
parent
d25e263b8e
commit
6069d89dee
20 changed files with 39 additions and 118 deletions
|
@ -94,16 +94,15 @@ fn run_app<B: Backend>(
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
let mut last_tick = Instant::now();
|
let mut last_tick = Instant::now();
|
||||||
loop {
|
loop {
|
||||||
terminal.draw(|f| ui(f, &mut app))?;
|
terminal.draw(|f| ui(f, &app))?;
|
||||||
|
|
||||||
let timeout = tick_rate
|
let timeout = tick_rate
|
||||||
.checked_sub(last_tick.elapsed())
|
.checked_sub(last_tick.elapsed())
|
||||||
.unwrap_or_else(|| Duration::from_secs(0));
|
.unwrap_or_else(|| Duration::from_secs(0));
|
||||||
if crossterm::event::poll(timeout)? {
|
if crossterm::event::poll(timeout)? {
|
||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
match key.code {
|
if let KeyCode::Char('q') = key.code {
|
||||||
KeyCode::Char('q') => return Ok(()),
|
return Ok(());
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,9 +45,8 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>) -> io::Result<()> {
|
||||||
terminal.draw(ui)?;
|
terminal.draw(ui)?;
|
||||||
|
|
||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
match key.code {
|
if let KeyCode::Char('q') = key.code {
|
||||||
KeyCode::Char('q') => return Ok(()),
|
return Ok(());
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,16 +130,15 @@ fn run_app<B: Backend>(
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
let mut last_tick = Instant::now();
|
let mut last_tick = Instant::now();
|
||||||
loop {
|
loop {
|
||||||
terminal.draw(|f| ui(f, &mut app))?;
|
terminal.draw(|f| ui(f, &app))?;
|
||||||
|
|
||||||
let timeout = tick_rate
|
let timeout = tick_rate
|
||||||
.checked_sub(last_tick.elapsed())
|
.checked_sub(last_tick.elapsed())
|
||||||
.unwrap_or_else(|| Duration::from_secs(0));
|
.unwrap_or_else(|| Duration::from_secs(0));
|
||||||
if crossterm::event::poll(timeout)? {
|
if crossterm::event::poll(timeout)? {
|
||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
match key.code {
|
if let KeyCode::Char('q') = key.code {
|
||||||
KeyCode::Char('q') => return Ok(()),
|
return Ok(());
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,16 +13,11 @@ use tui::{
|
||||||
Frame, Terminal,
|
Frame, Terminal,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
struct Label<'a> {
|
struct Label<'a> {
|
||||||
text: &'a str,
|
text: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Default for Label<'a> {
|
|
||||||
fn default() -> Label<'a> {
|
|
||||||
Label { text: "" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Widget for Label<'a> {
|
impl<'a> Widget for Label<'a> {
|
||||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||||
buf.set_string(area.left(), area.top(), self.text, Style::default());
|
buf.set_string(area.left(), area.top(), self.text, Style::default());
|
||||||
|
@ -68,9 +63,8 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>) -> io::Result<()> {
|
||||||
terminal.draw(ui)?;
|
terminal.draw(ui)?;
|
||||||
|
|
||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
match key.code {
|
if let KeyCode::Char('q') = key.code {
|
||||||
KeyCode::Char('q') => return Ok(()),
|
return Ok(());
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,14 +62,12 @@ fn events(tick_rate: Duration) -> mpsc::Receiver<Event> {
|
||||||
let keys_tx = tx.clone();
|
let keys_tx = tx.clone();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let stdin = io::stdin();
|
let stdin = io::stdin();
|
||||||
for evt in stdin.keys() {
|
for key in stdin.keys().flatten() {
|
||||||
if let Ok(key) = evt {
|
|
||||||
if let Err(err) = keys_tx.send(Event::Input(key)) {
|
if let Err(err) = keys_tx.send(Event::Input(key)) {
|
||||||
eprintln!("{}", err);
|
eprintln!("{}", err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
thread::spawn(move || loop {
|
thread::spawn(move || loop {
|
||||||
if let Err(err) = tx.send(Event::Tick) {
|
if let Err(err) = tx.send(Event::Tick) {
|
||||||
|
|
|
@ -90,16 +90,15 @@ fn run_app<B: Backend>(
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
let mut last_tick = Instant::now();
|
let mut last_tick = Instant::now();
|
||||||
loop {
|
loop {
|
||||||
terminal.draw(|f| ui(f, &mut app))?;
|
terminal.draw(|f| ui(f, &app))?;
|
||||||
|
|
||||||
let timeout = tick_rate
|
let timeout = tick_rate
|
||||||
.checked_sub(last_tick.elapsed())
|
.checked_sub(last_tick.elapsed())
|
||||||
.unwrap_or_else(|| Duration::from_secs(0));
|
.unwrap_or_else(|| Duration::from_secs(0));
|
||||||
if crossterm::event::poll(timeout)? {
|
if crossterm::event::poll(timeout)? {
|
||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
match key.code {
|
if let KeyCode::Char('q') = key.code {
|
||||||
KeyCode::Char('q') => return Ok(()),
|
return Ok(());
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,9 +43,8 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>) -> io::Result<()> {
|
||||||
terminal.draw(|f| ui(f))?;
|
terminal.draw(|f| ui(f))?;
|
||||||
|
|
||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
match key.code {
|
if let KeyCode::Char('q') = key.code {
|
||||||
KeyCode::Char('q') => return Ok(()),
|
return Ok(());
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,16 +68,15 @@ fn run_app<B: Backend>(
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
let mut last_tick = Instant::now();
|
let mut last_tick = Instant::now();
|
||||||
loop {
|
loop {
|
||||||
terminal.draw(|f| ui(f, &mut app))?;
|
terminal.draw(|f| ui(f, &app))?;
|
||||||
|
|
||||||
let timeout = tick_rate
|
let timeout = tick_rate
|
||||||
.checked_sub(last_tick.elapsed())
|
.checked_sub(last_tick.elapsed())
|
||||||
.unwrap_or_else(|| Duration::from_secs(0));
|
.unwrap_or_else(|| Duration::from_secs(0));
|
||||||
if crossterm::event::poll(timeout)? {
|
if crossterm::event::poll(timeout)? {
|
||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
match key.code {
|
if let KeyCode::Char('q') = key.code {
|
||||||
KeyCode::Char('q') => return Ok(()),
|
return Ok(());
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
|
||||||
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()> {
|
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()> {
|
||||||
loop {
|
loop {
|
||||||
terminal.draw(|f| ui(f, &mut app))?;
|
terminal.draw(|f| ui(f, &app))?;
|
||||||
|
|
||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
match key.code {
|
match key.code {
|
||||||
|
|
|
@ -112,16 +112,15 @@ fn run_app<B: Backend>(
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
let mut last_tick = Instant::now();
|
let mut last_tick = Instant::now();
|
||||||
loop {
|
loop {
|
||||||
terminal.draw(|f| ui(f, &mut app))?;
|
terminal.draw(|f| ui(f, &app))?;
|
||||||
|
|
||||||
let timeout = tick_rate
|
let timeout = tick_rate
|
||||||
.checked_sub(last_tick.elapsed())
|
.checked_sub(last_tick.elapsed())
|
||||||
.unwrap_or_else(|| Duration::from_secs(0));
|
.unwrap_or_else(|| Duration::from_secs(0));
|
||||||
if crossterm::event::poll(timeout)? {
|
if crossterm::event::poll(timeout)? {
|
||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
match key.code {
|
if let KeyCode::Char('q') = key.code {
|
||||||
KeyCode::Char('q') => return Ok(()),
|
return Ok(());
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
|
||||||
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()> {
|
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()> {
|
||||||
loop {
|
loop {
|
||||||
terminal.draw(|f| ui(f, &mut app))?;
|
terminal.draw(|f| ui(f, &app))?;
|
||||||
|
|
||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
match key.code {
|
match key.code {
|
||||||
|
|
|
@ -80,7 +80,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
|
||||||
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()> {
|
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()> {
|
||||||
loop {
|
loop {
|
||||||
terminal.draw(|f| ui(f, &mut app))?;
|
terminal.draw(|f| ui(f, &app))?;
|
||||||
|
|
||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
match app.input_mode {
|
match app.input_mode {
|
||||||
|
|
|
@ -105,7 +105,7 @@ impl Default for Cell {
|
||||||
/// buf.get_mut(5, 0).set_char('x');
|
/// buf.get_mut(5, 0).set_char('x');
|
||||||
/// assert_eq!(buf.get(5, 0).symbol, "x");
|
/// assert_eq!(buf.get(5, 0).symbol, "x");
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq, Default)]
|
||||||
pub struct Buffer {
|
pub struct Buffer {
|
||||||
/// The area represented by this buffer
|
/// The area represented by this buffer
|
||||||
pub area: Rect,
|
pub area: Rect,
|
||||||
|
@ -114,15 +114,6 @@ pub struct Buffer {
|
||||||
pub content: Vec<Cell>,
|
pub content: Vec<Cell>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Buffer {
|
|
||||||
fn default() -> Buffer {
|
|
||||||
Buffer {
|
|
||||||
area: Default::default(),
|
|
||||||
content: Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Buffer {
|
impl Buffer {
|
||||||
/// Returns a Buffer with all cells set to the default one
|
/// Returns a Buffer with all cells set to the default one
|
||||||
pub fn empty(area: Rect) -> Buffer {
|
pub fn empty(area: Rect) -> Buffer {
|
||||||
|
|
|
@ -363,7 +363,7 @@ impl Element {
|
||||||
|
|
||||||
/// A simple rectangle used in the computation of the layout and to give widgets an hint about the
|
/// A simple rectangle used in the computation of the layout and to give widgets an hint about the
|
||||||
/// area they are supposed to render to.
|
/// area they are supposed to render to.
|
||||||
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Default)]
|
||||||
pub struct Rect {
|
pub struct Rect {
|
||||||
pub x: u16,
|
pub x: u16,
|
||||||
pub y: u16,
|
pub y: u16,
|
||||||
|
@ -371,17 +371,6 @@ pub struct Rect {
|
||||||
pub height: u16,
|
pub height: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Rect {
|
|
||||||
fn default() -> Rect {
|
|
||||||
Rect {
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
width: 0,
|
|
||||||
height: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Rect {
|
impl Rect {
|
||||||
/// Creates a new rect, with width and height limited to keep the area under max u16.
|
/// Creates a new rect, with width and height limited to keep the area under max u16.
|
||||||
/// If clipped, aspect ratio will be preserved.
|
/// If clipped, aspect ratio will be preserved.
|
||||||
|
|
16
src/text.rs
16
src/text.rs
|
@ -194,15 +194,9 @@ impl<'a> From<&'a str> for Span<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A string composed of clusters of graphemes, each with their own style.
|
/// A string composed of clusters of graphemes, each with their own style.
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq, Default)]
|
||||||
pub struct Spans<'a>(pub Vec<Span<'a>>);
|
pub struct Spans<'a>(pub Vec<Span<'a>>);
|
||||||
|
|
||||||
impl<'a> Default for Spans<'a> {
|
|
||||||
fn default() -> Spans<'a> {
|
|
||||||
Spans(Vec::new())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Spans<'a> {
|
impl<'a> Spans<'a> {
|
||||||
/// Returns the width of the underlying string.
|
/// Returns the width of the underlying string.
|
||||||
///
|
///
|
||||||
|
@ -279,17 +273,11 @@ impl<'a> From<Spans<'a>> for String {
|
||||||
/// text.extend(Text::styled("Some more lines\nnow with more style!", style));
|
/// text.extend(Text::styled("Some more lines\nnow with more style!", style));
|
||||||
/// assert_eq!(6, text.height());
|
/// assert_eq!(6, text.height());
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq, Default)]
|
||||||
pub struct Text<'a> {
|
pub struct Text<'a> {
|
||||||
pub lines: Vec<Spans<'a>>,
|
pub lines: Vec<Spans<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Default for Text<'a> {
|
|
||||||
fn default() -> Text<'a> {
|
|
||||||
Text { lines: Vec::new() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Text<'a> {
|
impl<'a> Text<'a> {
|
||||||
/// Create some text (potentially multiple lines) with no style.
|
/// Create some text (potentially multiple lines) with no style.
|
||||||
///
|
///
|
||||||
|
|
|
@ -6122,6 +6122,7 @@ pub static WORLD_LOW_RESOLUTION: [(f64, f64); 1166] = [
|
||||||
(120.43, 16.43),
|
(120.43, 16.43),
|
||||||
(121.72, 18.40),
|
(121.72, 18.40),
|
||||||
(125.34, 9.79),
|
(125.34, 9.79),
|
||||||
|
#[allow(clippy::approx_constant)]
|
||||||
(125.56, 6.28),
|
(125.56, 6.28),
|
||||||
(122.38, 7.00),
|
(122.38, 7.00),
|
||||||
(125.10, 9.38),
|
(125.10, 9.38),
|
||||||
|
|
|
@ -141,7 +141,7 @@ impl<'a> Dataset<'a> {
|
||||||
|
|
||||||
/// A container that holds all the infos about where to display each elements of the chart (axis,
|
/// A container that holds all the infos about where to display each elements of the chart (axis,
|
||||||
/// labels, legend, ...).
|
/// labels, legend, ...).
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq, Default)]
|
||||||
struct ChartLayout {
|
struct ChartLayout {
|
||||||
/// Location of the title of the x axis
|
/// Location of the title of the x axis
|
||||||
title_x: Option<(u16, u16)>,
|
title_x: Option<(u16, u16)>,
|
||||||
|
@ -161,21 +161,6 @@ struct ChartLayout {
|
||||||
graph_area: Rect,
|
graph_area: Rect,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ChartLayout {
|
|
||||||
fn default() -> ChartLayout {
|
|
||||||
ChartLayout {
|
|
||||||
title_x: None,
|
|
||||||
title_y: None,
|
|
||||||
label_x: None,
|
|
||||||
label_y: None,
|
|
||||||
axis_x: None,
|
|
||||||
axis_y: None,
|
|
||||||
legend_area: None,
|
|
||||||
graph_area: Rect::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A widget to plot one or more dataset in a cartesian coordinate system
|
/// A widget to plot one or more dataset in a cartesian coordinate system
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
|
|
|
@ -7,21 +7,12 @@ use crate::{
|
||||||
};
|
};
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct ListState {
|
pub struct ListState {
|
||||||
offset: usize,
|
offset: usize,
|
||||||
selected: Option<usize>,
|
selected: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ListState {
|
|
||||||
fn default() -> ListState {
|
|
||||||
ListState {
|
|
||||||
offset: 0,
|
|
||||||
selected: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ListState {
|
impl ListState {
|
||||||
pub fn selected(&self) -> Option<usize> {
|
pub fn selected(&self) -> Option<usize> {
|
||||||
self.selected
|
self.selected
|
||||||
|
|
|
@ -403,8 +403,8 @@ mod test {
|
||||||
let text = "コンピュータ上で文字を扱う場合、典型的には文字による通信を行う場合にその両端点\
|
let text = "コンピュータ上で文字を扱う場合、典型的には文字による通信を行う場合にその両端点\
|
||||||
では、";
|
では、";
|
||||||
let (word_wrapper, word_wrapper_width) =
|
let (word_wrapper, word_wrapper_width) =
|
||||||
run_composer(Composer::WordWrapper { trim: true }, &text, width);
|
run_composer(Composer::WordWrapper { trim: true }, text, width);
|
||||||
let (line_truncator, _) = run_composer(Composer::LineTruncator, &text, width);
|
let (line_truncator, _) = run_composer(Composer::LineTruncator, text, width);
|
||||||
assert_eq!(line_truncator, vec!["コンピュータ上で文字"]);
|
assert_eq!(line_truncator, vec!["コンピュータ上で文字"]);
|
||||||
let wrapped = vec![
|
let wrapped = vec![
|
||||||
"コンピュータ上で文字",
|
"コンピュータ上で文字",
|
||||||
|
|
|
@ -335,21 +335,12 @@ impl<'a> Table<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct TableState {
|
pub struct TableState {
|
||||||
offset: usize,
|
offset: usize,
|
||||||
selected: Option<usize>,
|
selected: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for TableState {
|
|
||||||
fn default() -> TableState {
|
|
||||||
TableState {
|
|
||||||
offset: 0,
|
|
||||||
selected: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TableState {
|
impl TableState {
|
||||||
pub fn selected(&self) -> Option<usize> {
|
pub fn selected(&self) -> Option<usize> {
|
||||||
self.selected
|
self.selected
|
||||||
|
|
Loading…
Reference in a new issue