refactor: use new instead of default

This commit is contained in:
sxyazi 2023-07-24 07:56:08 +08:00
parent a8a5ab7f8c
commit 2df2671f3c
No known key found for this signature in database
10 changed files with 30 additions and 32 deletions

View File

@ -60,7 +60,7 @@ impl Watcher {
}
}
},
notify::Config::default(),
Default::default(),
)
.unwrap();

View File

@ -13,7 +13,7 @@ impl<'a> Layout<'a> {
impl<'a> Widget for Layout<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
let chunks = layout::Layout::default()
let chunks = layout::Layout::new()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
.split(area);
@ -25,7 +25,7 @@ impl<'a> Widget for Layout<'a> {
format!("{}", readable_home(&current.cwd))
};
Paragraph::new(location).style(Style::default().fg(Color::Cyan)).render(chunks[0], buf);
Paragraph::new(location).style(Style::new().fg(Color::Cyan)).render(chunks[0], buf);
Tabs::new(self.cx).render(chunks[1], buf);
}

View File

@ -19,21 +19,21 @@ impl<'a> Widget for Input<'a> {
Clear.render(area, buf);
Paragraph::new(input.value())
.block(
Block::default()
Block::new()
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(Color::Blue))
.border_style(Style::new().fg(Color::Blue))
.title({
let mut line = Line::from(input.title());
line.patch_style(Style::default().fg(Color::White));
line.patch_style(Style::new().fg(Color::White));
line
}),
)
.style(Style::default().fg(Color::White))
.style(Style::new().fg(Color::White))
.render(area, buf);
if let Some(selected) = input.selected() {
buf.set_style(selected, Style::default().bg(Color::Rgb(72, 77, 102)))
buf.set_style(selected, Style::new().bg(Color::Rgb(72, 77, 102)))
}
let _ = match input.mode() {

View File

@ -15,7 +15,7 @@ impl<'a> Widget for Layout<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
let manager = &self.cx.manager;
let chunks = layout::Layout::default()
let chunks = layout::Layout::new()
.direction(Direction::Horizontal)
.constraints(
[
@ -28,7 +28,7 @@ impl<'a> Widget for Layout<'a> {
.split(area);
// Parent
let block = Block::default().borders(Borders::RIGHT).padding(Padding::new(1, 0, 0, 0));
let block = Block::new().borders(Borders::RIGHT).padding(Padding::new(1, 0, 0, 0));
if let Some(ref parent) = manager.parent() {
Folder::new(self.cx, parent).render(block.inner(chunks[0]), buf);
}
@ -40,7 +40,7 @@ impl<'a> Widget for Layout<'a> {
.render(chunks[1], buf);
// Preview
let block = Block::default().borders(Borders::LEFT).padding(Padding::new(0, 1, 0, 0));
let block = Block::new().borders(Borders::LEFT).padding(Padding::new(0, 1, 0, 0));
Preview::new(self.cx).render(block.inner(chunks[2]), buf);
block.render(chunks[2], buf);
}

View File

@ -12,7 +12,7 @@ impl<'a> Root<'a> {
impl<'a> Widget for Root<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
let chunks = Layout::default()
let chunks = Layout::new()
.direction(Direction::Vertical)
.constraints([Constraint::Length(1), Constraint::Min(0), Constraint::Length(1)].as_ref())
.split(area);

View File

@ -24,18 +24,18 @@ impl<'a> Widget for Select<'a> {
return ListItem::new(format!(" {}", v));
}
ListItem::new(format!("{}", v)).style(Style::default().fg(Color::Magenta))
ListItem::new(format!("{}", v)).style(Style::new().fg(Color::Magenta))
})
.collect::<Vec<_>>();
Clear.render(area, buf);
List::new(items)
.block(
Block::default()
Block::new()
.title(select.title())
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(Color::Blue)),
.border_style(Style::new().fg(Color::Blue)),
)
.render(area, buf);
}

View File

@ -13,7 +13,7 @@ impl<'a> Layout<'a> {
impl<'a> Widget for Layout<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
let chunks = layout::Layout::default()
let chunks = layout::Layout::new()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
.split(area);

View File

@ -11,7 +11,7 @@ impl<'a> Layout<'a> {
pub fn new(cx: &'a Ctx) -> Self { Self { cx } }
pub fn area(area: Rect) -> Rect {
let chunk = layout::Layout::default()
let chunk = layout::Layout::new()
.direction(Direction::Vertical)
.constraints(
[
@ -23,7 +23,7 @@ impl<'a> Layout<'a> {
)
.split(area)[1];
let chunk = layout::Layout::default()
let chunk = layout::Layout::new()
.direction(Direction::Horizontal)
.constraints(
[
@ -44,13 +44,13 @@ impl<'a> Widget for Layout<'a> {
let area = Self::area(area);
Clear.render(area, buf);
let block = Block::default()
let block = Block::new()
.title("Tasks")
.title_alignment(Alignment::Center)
.padding(Padding::new(0, 0, 1, 1))
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(Color::Rgb(128, 174, 250)));
.border_style(Style::new().fg(Color::Rgb(128, 174, 250)));
block.clone().render(area, buf);
let tasks = &self.cx.tasks;
@ -61,7 +61,7 @@ impl<'a> Widget for Layout<'a> {
.map(|(i, v)| {
let mut item = ListItem::new(v.name.clone());
if i == tasks.cursor {
item = item.style(Style::default().add_modifier(Modifier::UNDERLINED));
item = item.style(Style::new().add_modifier(Modifier::UNDERLINED));
}
item
})

View File

@ -1,4 +1,4 @@
use ratatui::{layout, prelude::{Buffer, Constraint, Direction, Rect}, widgets::{Clear, Widget}};
use ratatui::{layout, prelude::{Buffer, Constraint, Direction, Rect}, style::{Color, Style}, widgets::{Block, Clear, Widget}};
use super::Side;
use crate::ui::Ctx;
@ -32,7 +32,7 @@ impl Widget for Which<'_> {
height,
};
let chunks = layout::Layout::default()
let chunks = layout::Layout::new()
.direction(Direction::Horizontal)
.constraints(
[Constraint::Ratio(1, 3), Constraint::Ratio(1, 3), Constraint::Ratio(1, 3)].as_ref(),
@ -40,6 +40,7 @@ impl Widget for Which<'_> {
.split(area);
Clear.render(area, buf);
Block::new().style(Style::new().bg(Color::Rgb(47, 51, 73))).render(area, buf);
Side::new(which.times, cands.0).render(chunks[0], buf);
Side::new(which.times, cands.1).render(chunks[1], buf);
Side::new(which.times, cands.2).render(chunks[2], buf);

View File

@ -1,4 +1,4 @@
use ratatui::{prelude::{Buffer, Rect}, style::{Color, Style, Stylize}, text::{Line, Span}, widgets::{Block, List, ListItem, Padding, Widget}};
use ratatui::{prelude::{Buffer, Rect}, style::{Color, Style}, text::{Line, Span}, widgets::{Block, List, ListItem, Padding, Widget}};
use crate::config::keymap::Control;
@ -22,28 +22,25 @@ impl Widget for Side<'_> {
// Keys
let keys = c.on[self.times..].iter().map(ToString::to_string).collect::<Vec<_>>();
spans.push(Span::raw(" ".repeat(10usize.saturating_sub(keys.join("").len()))));
spans.push(Span::styled(keys[0].clone(), Style::default().fg(Color::LightCyan)));
spans.push(Span::styled(keys[0].clone(), Style::new().fg(Color::LightCyan)));
spans.extend(
keys
.iter()
.skip(1)
.map(|k| Span::styled(k.to_string(), Style::default().fg(Color::DarkGray))),
.map(|k| Span::styled(k.to_string(), Style::new().fg(Color::DarkGray))),
);
// Separator
spans.push(Span::styled("".to_string(), Style::default().fg(Color::DarkGray)));
spans.push(Span::styled("".to_string(), Style::new().fg(Color::DarkGray)));
// Exec
let exec = c.exec.iter().map(ToString::to_string).collect::<Vec<_>>().join("; ");
spans.push(Span::styled(exec, Style::default().fg(Color::Magenta)));
spans.push(Span::styled(exec, Style::new().fg(Color::Magenta)));
ListItem::new(Line::from(spans))
})
.collect::<Vec<_>>();
List::new(items)
.block(Block::new().padding(Padding::new(0, 1, 1, 1)))
.bg(Color::Rgb(47, 51, 73))
.render(area, buf);
List::new(items).block(Block::new().padding(Padding::new(0, 1, 1, 1))).render(area, buf);
}
}