mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
refactor: use new instead of default
This commit is contained in:
parent
a8a5ab7f8c
commit
2df2671f3c
10 changed files with 30 additions and 32 deletions
|
|
@ -60,7 +60,7 @@ impl Watcher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
notify::Config::default(),
|
Default::default(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ impl<'a> Layout<'a> {
|
||||||
|
|
||||||
impl<'a> Widget for Layout<'a> {
|
impl<'a> Widget for Layout<'a> {
|
||||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||||
let chunks = layout::Layout::default()
|
let chunks = layout::Layout::new()
|
||||||
.direction(Direction::Horizontal)
|
.direction(Direction::Horizontal)
|
||||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
||||||
.split(area);
|
.split(area);
|
||||||
|
|
@ -25,7 +25,7 @@ impl<'a> Widget for Layout<'a> {
|
||||||
format!("{}", readable_home(¤t.cwd))
|
format!("{}", readable_home(¤t.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);
|
Tabs::new(self.cx).render(chunks[1], buf);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,21 +19,21 @@ impl<'a> Widget for Input<'a> {
|
||||||
Clear.render(area, buf);
|
Clear.render(area, buf);
|
||||||
Paragraph::new(input.value())
|
Paragraph::new(input.value())
|
||||||
.block(
|
.block(
|
||||||
Block::default()
|
Block::new()
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.border_type(BorderType::Rounded)
|
.border_type(BorderType::Rounded)
|
||||||
.border_style(Style::default().fg(Color::Blue))
|
.border_style(Style::new().fg(Color::Blue))
|
||||||
.title({
|
.title({
|
||||||
let mut line = Line::from(input.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
|
line
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.style(Style::default().fg(Color::White))
|
.style(Style::new().fg(Color::White))
|
||||||
.render(area, buf);
|
.render(area, buf);
|
||||||
|
|
||||||
if let Some(selected) = input.selected() {
|
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() {
|
let _ = match input.mode() {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ impl<'a> Widget for Layout<'a> {
|
||||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||||
let manager = &self.cx.manager;
|
let manager = &self.cx.manager;
|
||||||
|
|
||||||
let chunks = layout::Layout::default()
|
let chunks = layout::Layout::new()
|
||||||
.direction(Direction::Horizontal)
|
.direction(Direction::Horizontal)
|
||||||
.constraints(
|
.constraints(
|
||||||
[
|
[
|
||||||
|
|
@ -28,7 +28,7 @@ impl<'a> Widget for Layout<'a> {
|
||||||
.split(area);
|
.split(area);
|
||||||
|
|
||||||
// Parent
|
// 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() {
|
if let Some(ref parent) = manager.parent() {
|
||||||
Folder::new(self.cx, parent).render(block.inner(chunks[0]), buf);
|
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);
|
.render(chunks[1], buf);
|
||||||
|
|
||||||
// Preview
|
// 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);
|
Preview::new(self.cx).render(block.inner(chunks[2]), buf);
|
||||||
block.render(chunks[2], buf);
|
block.render(chunks[2], buf);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ impl<'a> Root<'a> {
|
||||||
|
|
||||||
impl<'a> Widget for Root<'a> {
|
impl<'a> Widget for Root<'a> {
|
||||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||||
let chunks = Layout::default()
|
let chunks = Layout::new()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([Constraint::Length(1), Constraint::Min(0), Constraint::Length(1)].as_ref())
|
.constraints([Constraint::Length(1), Constraint::Min(0), Constraint::Length(1)].as_ref())
|
||||||
.split(area);
|
.split(area);
|
||||||
|
|
|
||||||
|
|
@ -24,18 +24,18 @@ impl<'a> Widget for Select<'a> {
|
||||||
return ListItem::new(format!(" {}", v));
|
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<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
Clear.render(area, buf);
|
Clear.render(area, buf);
|
||||||
List::new(items)
|
List::new(items)
|
||||||
.block(
|
.block(
|
||||||
Block::default()
|
Block::new()
|
||||||
.title(select.title())
|
.title(select.title())
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.border_type(BorderType::Rounded)
|
.border_type(BorderType::Rounded)
|
||||||
.border_style(Style::default().fg(Color::Blue)),
|
.border_style(Style::new().fg(Color::Blue)),
|
||||||
)
|
)
|
||||||
.render(area, buf);
|
.render(area, buf);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ impl<'a> Layout<'a> {
|
||||||
|
|
||||||
impl<'a> Widget for Layout<'a> {
|
impl<'a> Widget for Layout<'a> {
|
||||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||||
let chunks = layout::Layout::default()
|
let chunks = layout::Layout::new()
|
||||||
.direction(Direction::Horizontal)
|
.direction(Direction::Horizontal)
|
||||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
||||||
.split(area);
|
.split(area);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ impl<'a> Layout<'a> {
|
||||||
pub fn new(cx: &'a Ctx) -> Self { Self { cx } }
|
pub fn new(cx: &'a Ctx) -> Self { Self { cx } }
|
||||||
|
|
||||||
pub fn area(area: Rect) -> Rect {
|
pub fn area(area: Rect) -> Rect {
|
||||||
let chunk = layout::Layout::default()
|
let chunk = layout::Layout::new()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints(
|
.constraints(
|
||||||
[
|
[
|
||||||
|
|
@ -23,7 +23,7 @@ impl<'a> Layout<'a> {
|
||||||
)
|
)
|
||||||
.split(area)[1];
|
.split(area)[1];
|
||||||
|
|
||||||
let chunk = layout::Layout::default()
|
let chunk = layout::Layout::new()
|
||||||
.direction(Direction::Horizontal)
|
.direction(Direction::Horizontal)
|
||||||
.constraints(
|
.constraints(
|
||||||
[
|
[
|
||||||
|
|
@ -44,13 +44,13 @@ impl<'a> Widget for Layout<'a> {
|
||||||
let area = Self::area(area);
|
let area = Self::area(area);
|
||||||
|
|
||||||
Clear.render(area, buf);
|
Clear.render(area, buf);
|
||||||
let block = Block::default()
|
let block = Block::new()
|
||||||
.title("Tasks")
|
.title("Tasks")
|
||||||
.title_alignment(Alignment::Center)
|
.title_alignment(Alignment::Center)
|
||||||
.padding(Padding::new(0, 0, 1, 1))
|
.padding(Padding::new(0, 0, 1, 1))
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.border_type(BorderType::Rounded)
|
.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);
|
block.clone().render(area, buf);
|
||||||
|
|
||||||
let tasks = &self.cx.tasks;
|
let tasks = &self.cx.tasks;
|
||||||
|
|
@ -61,7 +61,7 @@ impl<'a> Widget for Layout<'a> {
|
||||||
.map(|(i, v)| {
|
.map(|(i, v)| {
|
||||||
let mut item = ListItem::new(v.name.clone());
|
let mut item = ListItem::new(v.name.clone());
|
||||||
if i == tasks.cursor {
|
if i == tasks.cursor {
|
||||||
item = item.style(Style::default().add_modifier(Modifier::UNDERLINED));
|
item = item.style(Style::new().add_modifier(Modifier::UNDERLINED));
|
||||||
}
|
}
|
||||||
item
|
item
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -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 super::Side;
|
||||||
use crate::ui::Ctx;
|
use crate::ui::Ctx;
|
||||||
|
|
@ -32,7 +32,7 @@ impl Widget for Which<'_> {
|
||||||
height,
|
height,
|
||||||
};
|
};
|
||||||
|
|
||||||
let chunks = layout::Layout::default()
|
let chunks = layout::Layout::new()
|
||||||
.direction(Direction::Horizontal)
|
.direction(Direction::Horizontal)
|
||||||
.constraints(
|
.constraints(
|
||||||
[Constraint::Ratio(1, 3), Constraint::Ratio(1, 3), Constraint::Ratio(1, 3)].as_ref(),
|
[Constraint::Ratio(1, 3), Constraint::Ratio(1, 3), Constraint::Ratio(1, 3)].as_ref(),
|
||||||
|
|
@ -40,6 +40,7 @@ impl Widget for Which<'_> {
|
||||||
.split(area);
|
.split(area);
|
||||||
|
|
||||||
Clear.render(area, buf);
|
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.0).render(chunks[0], buf);
|
||||||
Side::new(which.times, cands.1).render(chunks[1], buf);
|
Side::new(which.times, cands.1).render(chunks[1], buf);
|
||||||
Side::new(which.times, cands.2).render(chunks[2], buf);
|
Side::new(which.times, cands.2).render(chunks[2], buf);
|
||||||
|
|
|
||||||
|
|
@ -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;
|
use crate::config::keymap::Control;
|
||||||
|
|
||||||
|
|
@ -22,28 +22,25 @@ impl Widget for Side<'_> {
|
||||||
// Keys
|
// Keys
|
||||||
let keys = c.on[self.times..].iter().map(ToString::to_string).collect::<Vec<_>>();
|
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::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(
|
spans.extend(
|
||||||
keys
|
keys
|
||||||
.iter()
|
.iter()
|
||||||
.skip(1)
|
.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
|
// Separator
|
||||||
spans.push(Span::styled(" ".to_string(), Style::default().fg(Color::DarkGray)));
|
spans.push(Span::styled(" ".to_string(), Style::new().fg(Color::DarkGray)));
|
||||||
|
|
||||||
// Exec
|
// Exec
|
||||||
let exec = c.exec.iter().map(ToString::to_string).collect::<Vec<_>>().join("; ");
|
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))
|
ListItem::new(Line::from(spans))
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
List::new(items)
|
List::new(items).block(Block::new().padding(Padding::new(0, 1, 1, 1))).render(area, buf);
|
||||||
.block(Block::new().padding(Padding::new(0, 1, 1, 1)))
|
|
||||||
.bg(Color::Rgb(47, 51, 73))
|
|
||||||
.render(area, buf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue