mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
d2963b23a9
commit
669d3e796c
16 changed files with 56 additions and 56 deletions
|
|
@ -51,9 +51,4 @@ impl Ctx {
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn image_layer(&self) -> bool {
|
|
||||||
!self.which.visible && !self.help.visible && !self.tasks.visible
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,12 @@
|
||||||
use crate::manager::Manager;
|
use crate::manager::Manager;
|
||||||
|
|
||||||
impl Manager {
|
impl Manager {
|
||||||
pub fn peek(&mut self, sequent: bool, show_image: bool) -> bool {
|
pub fn peek(&mut self, sequent: bool) -> bool {
|
||||||
let Some(hovered) = self.hovered().cloned() else {
|
let Some(hovered) = self.hovered().cloned() else {
|
||||||
return self.active_mut().preview.reset(|_| true);
|
return self.active_mut().preview.reset(|_| true);
|
||||||
};
|
};
|
||||||
|
|
||||||
let url = &hovered.url;
|
let url = &hovered.url;
|
||||||
if !show_image {
|
|
||||||
self.active_mut().preview.reset(|l| l.is_image());
|
|
||||||
}
|
|
||||||
|
|
||||||
if hovered.is_dir() {
|
if hovered.is_dir() {
|
||||||
let position = self.active().history(url).map(|f| (f.offset, f.files.len()));
|
let position = self.active().history(url).map(|f| (f.offset, f.files.len()));
|
||||||
self.active_mut().preview.folder(url, position, sequent);
|
self.active_mut().preview.folder(url, position, sequent);
|
||||||
|
|
@ -22,9 +18,9 @@ impl Manager {
|
||||||
};
|
};
|
||||||
|
|
||||||
if sequent {
|
if sequent {
|
||||||
self.active_mut().preview.sequent(url, &mime, show_image);
|
self.active_mut().preview.sequent(url, &mime);
|
||||||
} else {
|
} else {
|
||||||
self.active_mut().preview.go(url, &mime, show_image);
|
self.active_mut().preview.go(url, &mime);
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,9 @@ pub enum PreviewData {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Preview {
|
impl Preview {
|
||||||
pub fn go(&mut self, url: &Url, mime: &str, show_image: bool) {
|
pub fn go(&mut self, url: &Url, mime: &str) {
|
||||||
let kind = MimeKind::new(mime);
|
let kind = MimeKind::new(mime);
|
||||||
if !show_image && kind.show_as_image() {
|
if self.same(url, mime) {
|
||||||
return;
|
|
||||||
} else if self.same(url, mime) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,11 +102,9 @@ impl Preview {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sequent(&mut self, url: &Url, mime: &str, show_image: bool) {
|
pub fn sequent(&mut self, url: &Url, mime: &str) {
|
||||||
let kind = MimeKind::new(mime);
|
let kind = MimeKind::new(mime);
|
||||||
if !show_image && kind.show_as_image() {
|
if self.same(url, mime) {
|
||||||
return;
|
|
||||||
} else if self.same(url, mime) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ impl App {
|
||||||
|
|
||||||
self.cx.manager.current_mut().set_page(true);
|
self.cx.manager.current_mut().set_page(true);
|
||||||
self.cx.manager.active_mut().preview.reset(|_| true);
|
self.cx.manager.active_mut().preview.reset(|_| true);
|
||||||
self.cx.manager.peek(true, self.cx.image_layer());
|
self.cx.manager.peek(true);
|
||||||
emit!(Render);
|
emit!(Render);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,9 +163,9 @@ impl App {
|
||||||
Event::Peek(sequent) => {
|
Event::Peek(sequent) => {
|
||||||
if let Some((max, url)) = sequent {
|
if let Some((max, url)) = sequent {
|
||||||
manager.active_mut().update_peek(max, url);
|
manager.active_mut().update_peek(max, url);
|
||||||
self.cx.manager.peek(true, self.cx.image_layer());
|
self.cx.manager.peek(true);
|
||||||
} else {
|
} else {
|
||||||
self.cx.manager.peek(false, self.cx.image_layer());
|
self.cx.manager.peek(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Preview(lock) => {
|
Event::Preview(lock) => {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ use ratatui::{buffer::Buffer, layout::Rect, widgets::{Block, BorderType, Borders
|
||||||
use yazi_config::{popup::{Offset, Position}, THEME};
|
use yazi_config::{popup::{Offset, Position}, THEME};
|
||||||
use yazi_core::Ctx;
|
use yazi_core::Ctx;
|
||||||
|
|
||||||
|
use crate::widgets;
|
||||||
|
|
||||||
pub(crate) struct Completion<'a> {
|
pub(crate) struct Completion<'a> {
|
||||||
cx: &'a Ctx,
|
cx: &'a Ctx,
|
||||||
}
|
}
|
||||||
|
|
@ -53,7 +55,7 @@ impl<'a> Widget for Completion<'a> {
|
||||||
area.height = rect.height.saturating_sub(area.y).min(area.height);
|
area.height = rect.height.saturating_sub(area.y).min(area.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
Clear.render(area, buf);
|
widgets::Clear.render(area, buf);
|
||||||
List::new(items)
|
List::new(items)
|
||||||
.block(
|
.block(
|
||||||
Block::new()
|
Block::new()
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ impl<'a> Executor<'a> {
|
||||||
b"peek" => {
|
b"peek" => {
|
||||||
let step = exec.args.first().and_then(|s| s.parse().ok()).unwrap_or(0);
|
let step = exec.args.first().and_then(|s| s.parse().ok()).unwrap_or(0);
|
||||||
self.cx.manager.active_mut().preview.arrow(step);
|
self.cx.manager.active_mut().preview.arrow(step);
|
||||||
self.cx.manager.peek(true, self.cx.image_layer())
|
self.cx.manager.peek(true)
|
||||||
}
|
}
|
||||||
// Tasks
|
// Tasks
|
||||||
b"tasks_show" => self.cx.tasks.toggle(()),
|
b"tasks_show" => self.cx.tasks.toggle(()),
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
use ratatui::{buffer::Buffer, layout::{self, Rect}, prelude::{Constraint, Direction}, widgets::{Clear, Paragraph, Widget}};
|
use ratatui::{buffer::Buffer, layout::{self, Rect}, prelude::{Constraint, Direction}, widgets::{Paragraph, Widget}};
|
||||||
use yazi_config::THEME;
|
use yazi_config::THEME;
|
||||||
use yazi_core::Ctx;
|
use yazi_core::Ctx;
|
||||||
|
|
||||||
use super::Bindings;
|
use super::Bindings;
|
||||||
|
use crate::widgets;
|
||||||
|
|
||||||
pub(crate) struct Layout<'a> {
|
pub(crate) struct Layout<'a> {
|
||||||
cx: &'a Ctx,
|
cx: &'a Ctx,
|
||||||
|
|
@ -19,7 +20,7 @@ impl<'a> Widget for Layout<'a> {
|
||||||
.constraints([Constraint::Min(0), Constraint::Length(1)])
|
.constraints([Constraint::Min(0), Constraint::Length(1)])
|
||||||
.split(area);
|
.split(area);
|
||||||
|
|
||||||
Clear.render(area, buf);
|
widgets::Clear.render(area, buf);
|
||||||
|
|
||||||
let help = &self.cx.help;
|
let help = &self.cx.help;
|
||||||
Paragraph::new(help.keyword().unwrap_or_else(|| format!("{}.help", help.layer)))
|
Paragraph::new(help.keyword().unwrap_or_else(|| format!("{}.help", help.layer)))
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
|
||||||
use ansi_to_tui::IntoText;
|
use ansi_to_tui::IntoText;
|
||||||
use ratatui::{buffer::Buffer, layout::Rect, text::{Line, Text}, widgets::{Block, BorderType, Borders, Clear, Paragraph, Widget}};
|
use ratatui::{buffer::Buffer, layout::Rect, text::{Line, Text}, widgets::{Block, BorderType, Borders, Paragraph, Widget}};
|
||||||
use yazi_config::THEME;
|
use yazi_config::THEME;
|
||||||
use yazi_core::{input::InputMode, Ctx};
|
use yazi_core::{input::InputMode, Ctx};
|
||||||
use yazi_shared::Term;
|
use yazi_shared::Term;
|
||||||
|
|
||||||
|
use crate::widgets;
|
||||||
|
|
||||||
pub(crate) struct Input<'a> {
|
pub(crate) struct Input<'a> {
|
||||||
cx: &'a Ctx,
|
cx: &'a Ctx,
|
||||||
}
|
}
|
||||||
|
|
@ -25,7 +27,7 @@ impl<'a> Widget for Input<'a> {
|
||||||
Text::from(input.value())
|
Text::from(input.value())
|
||||||
};
|
};
|
||||||
|
|
||||||
Clear.render(area, buf);
|
widgets::Clear.render(area, buf);
|
||||||
Paragraph::new(value)
|
Paragraph::new(value)
|
||||||
.block(
|
.block(
|
||||||
Block::new()
|
Block::new()
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ mod select;
|
||||||
mod signals;
|
mod signals;
|
||||||
mod tasks;
|
mod tasks;
|
||||||
mod which;
|
mod which;
|
||||||
|
mod widgets;
|
||||||
|
|
||||||
use app::*;
|
use app::*;
|
||||||
use executor::*;
|
use executor::*;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
use ratatui::{buffer::Buffer, layout::Rect, widgets::{Block, BorderType, Borders, Clear, List, ListItem, Widget}};
|
use ratatui::{buffer::Buffer, layout::Rect, widgets::{Block, BorderType, Borders, List, ListItem, Widget}};
|
||||||
use yazi_config::THEME;
|
use yazi_config::THEME;
|
||||||
use yazi_core::Ctx;
|
use yazi_core::Ctx;
|
||||||
|
|
||||||
|
use crate::widgets;
|
||||||
|
|
||||||
pub(crate) struct Select<'a> {
|
pub(crate) struct Select<'a> {
|
||||||
cx: &'a Ctx,
|
cx: &'a Ctx,
|
||||||
}
|
}
|
||||||
|
|
@ -28,7 +30,7 @@ impl<'a> Widget for Select<'a> {
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
Clear.render(area, buf);
|
widgets::Clear.render(area, buf);
|
||||||
List::new(items)
|
List::new(items)
|
||||||
.block(
|
.block(
|
||||||
Block::new()
|
Block::new()
|
||||||
|
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
use ratatui::{buffer::Buffer, layout::Rect, widgets::{self, Widget}};
|
|
||||||
|
|
||||||
pub(super) struct Clear;
|
|
||||||
|
|
||||||
impl Widget for Clear {
|
|
||||||
fn render(self, mut area: Rect, buf: &mut Buffer) {
|
|
||||||
if area.x > 0 {
|
|
||||||
area.x -= 1;
|
|
||||||
area.width += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if area.y > 0 {
|
|
||||||
area.y -= 1;
|
|
||||||
area.height += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
widgets::Clear.render(area, buf)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -2,7 +2,7 @@ use ratatui::{buffer::Buffer, layout::{self, Alignment, Constraint, Direction, R
|
||||||
use yazi_config::THEME;
|
use yazi_config::THEME;
|
||||||
use yazi_core::{tasks::TASKS_PERCENT, Ctx};
|
use yazi_core::{tasks::TASKS_PERCENT, Ctx};
|
||||||
|
|
||||||
use super::Clear;
|
use crate::widgets;
|
||||||
|
|
||||||
pub(crate) struct Layout<'a> {
|
pub(crate) struct Layout<'a> {
|
||||||
cx: &'a Ctx,
|
cx: &'a Ctx,
|
||||||
|
|
@ -36,7 +36,7 @@ impl<'a> Widget for Layout<'a> {
|
||||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||||
let area = Self::area(area);
|
let area = Self::area(area);
|
||||||
|
|
||||||
Clear.render(area, buf);
|
widgets::Clear.render(area, buf);
|
||||||
let block = Block::new()
|
let block = Block::new()
|
||||||
.title({
|
.title({
|
||||||
let mut line = Line::from("Tasks");
|
let mut line = Line::from("Tasks");
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
mod clear;
|
|
||||||
mod layout;
|
mod layout;
|
||||||
|
|
||||||
use clear::*;
|
|
||||||
pub(super) use layout::*;
|
pub(super) use layout::*;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
use ratatui::{layout, prelude::{Buffer, Constraint, Direction, Rect}, widgets::{Block, Clear, Widget}};
|
use ratatui::{layout, prelude::{Buffer, Constraint, Direction, Rect}, widgets::{Block, Widget}};
|
||||||
use yazi_config::THEME;
|
use yazi_config::THEME;
|
||||||
use yazi_core::Ctx;
|
use yazi_core::Ctx;
|
||||||
|
|
||||||
use super::Side;
|
use super::Side;
|
||||||
|
use crate::widgets;
|
||||||
|
|
||||||
pub(crate) struct Which<'a> {
|
pub(crate) struct Which<'a> {
|
||||||
cx: &'a Ctx,
|
cx: &'a Ctx,
|
||||||
|
|
@ -38,7 +39,7 @@ impl Widget for Which<'_> {
|
||||||
.constraints([Constraint::Ratio(1, 3), Constraint::Ratio(1, 3), Constraint::Ratio(1, 3)])
|
.constraints([Constraint::Ratio(1, 3), Constraint::Ratio(1, 3), Constraint::Ratio(1, 3)])
|
||||||
.split(area);
|
.split(area);
|
||||||
|
|
||||||
Clear.render(area, buf);
|
widgets::Clear.render(area, buf);
|
||||||
Block::new().style(THEME.which.mask.into()).render(area, buf);
|
Block::new().style(THEME.which.mask.into()).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);
|
||||||
|
|
|
||||||
22
yazi-fm/src/widgets/clear.rs
Normal file
22
yazi-fm/src/widgets/clear.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
use std::io::{stdout, BufWriter, Write};
|
||||||
|
|
||||||
|
use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget};
|
||||||
|
use yazi_shared::Term;
|
||||||
|
|
||||||
|
pub(crate) struct Clear;
|
||||||
|
|
||||||
|
impl Widget for Clear {
|
||||||
|
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||||
|
// let stdout = BufWriter::new(stdout().lock());
|
||||||
|
// let s = " ".repeat(area.width as usize);
|
||||||
|
// _ = Term::move_lock(stdout, (0, 0), |stdout| {
|
||||||
|
// for y in area.top()..area.bottom() {
|
||||||
|
// Term::move_to(stdout, area.x, y)?;
|
||||||
|
// stdout.write_all(s.as_bytes())?;
|
||||||
|
// }
|
||||||
|
// Ok(())
|
||||||
|
// });
|
||||||
|
|
||||||
|
ratatui::widgets::Clear.render(area, buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
3
yazi-fm/src/widgets/mod.rs
Normal file
3
yazi-fm/src/widgets/mod.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
mod clear;
|
||||||
|
|
||||||
|
pub(super) use clear::*;
|
||||||
Loading…
Add table
Reference in a new issue