mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
c3446cd941
commit
d0b6810cb3
16 changed files with 57 additions and 57 deletions
|
|
@ -70,9 +70,4 @@ impl Ctx {
|
|||
}
|
||||
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;
|
||||
|
||||
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 {
|
||||
return self.active_mut().preview.reset(|_| true);
|
||||
};
|
||||
|
||||
let url = &hovered.url;
|
||||
if !show_image {
|
||||
self.active_mut().preview.reset(|l| l.is_image());
|
||||
}
|
||||
|
||||
if hovered.is_dir() {
|
||||
let position = self.active().history(url).map(|f| (f.offset, f.files.len()));
|
||||
self.active_mut().preview.folder(url, position, sequent);
|
||||
|
|
@ -22,9 +18,9 @@ impl Manager {
|
|||
};
|
||||
|
||||
if sequent {
|
||||
self.active_mut().preview.sequent(url, &mime, show_image);
|
||||
self.active_mut().preview.sequent(url, &mime);
|
||||
} else {
|
||||
self.active_mut().preview.go(url, &mime, show_image);
|
||||
self.active_mut().preview.go(url, &mime);
|
||||
}
|
||||
false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,11 +32,9 @@ pub enum PreviewData {
|
|||
}
|
||||
|
||||
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);
|
||||
if !show_image && kind.show_as_image() {
|
||||
return;
|
||||
} else if self.same(url, mime) {
|
||||
if self.same(url, mime) {
|
||||
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);
|
||||
if !show_image && kind.show_as_image() {
|
||||
return;
|
||||
} else if self.same(url, mime) {
|
||||
if self.same(url, mime) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ impl App {
|
|||
|
||||
self.cx.manager.current_mut().set_page(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);
|
||||
}
|
||||
|
||||
|
|
@ -163,9 +163,9 @@ impl App {
|
|||
Event::Peek(sequent) => {
|
||||
if let Some((max, url)) = sequent {
|
||||
manager.active_mut().update_peek(max, url);
|
||||
self.cx.manager.peek(true, self.cx.image_layer());
|
||||
self.cx.manager.peek(true);
|
||||
} else {
|
||||
self.cx.manager.peek(false, self.cx.image_layer());
|
||||
self.cx.manager.peek(false);
|
||||
}
|
||||
}
|
||||
Event::Preview(lock) => {
|
||||
|
|
|
|||
|
|
@ -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_core::{Ctx, Position};
|
||||
|
||||
use crate::widgets;
|
||||
|
||||
pub(crate) struct Completion<'a> {
|
||||
cx: &'a Ctx,
|
||||
}
|
||||
|
|
@ -54,7 +56,7 @@ impl<'a> Widget for Completion<'a> {
|
|||
area.height = rect.height.saturating_sub(area.y).min(area.height);
|
||||
}
|
||||
|
||||
Clear.render(area, buf);
|
||||
widgets::Clear.render(area, buf);
|
||||
List::new(items)
|
||||
.block(
|
||||
Block::new()
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ impl<'a> Executor<'a> {
|
|||
b"peek" => {
|
||||
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.peek(true, self.cx.image_layer())
|
||||
self.cx.manager.peek(true)
|
||||
}
|
||||
// Tasks
|
||||
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_core::Ctx;
|
||||
|
||||
use super::Bindings;
|
||||
use crate::widgets;
|
||||
|
||||
pub(crate) struct Layout<'a> {
|
||||
cx: &'a Ctx,
|
||||
|
|
@ -19,7 +20,7 @@ impl<'a> Widget for Layout<'a> {
|
|||
.constraints([Constraint::Min(0), Constraint::Length(1)])
|
||||
.split(area);
|
||||
|
||||
Clear.render(area, buf);
|
||||
widgets::Clear.render(area, buf);
|
||||
|
||||
let help = &self.cx.help;
|
||||
Paragraph::new(help.keyword().unwrap_or_else(|| format!("{}.help", help.layer)))
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
use std::ops::Range;
|
||||
|
||||
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_core::{input::InputMode, Ctx};
|
||||
use yazi_shared::Term;
|
||||
|
||||
use crate::widgets;
|
||||
|
||||
pub(crate) struct Input<'a> {
|
||||
cx: &'a Ctx,
|
||||
}
|
||||
|
|
@ -25,7 +27,7 @@ impl<'a> Widget for Input<'a> {
|
|||
Text::from(input.value())
|
||||
};
|
||||
|
||||
Clear.render(area, buf);
|
||||
widgets::Clear.render(area, buf);
|
||||
Paragraph::new(value)
|
||||
.block(
|
||||
Block::new()
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ mod select;
|
|||
mod signals;
|
||||
mod tasks;
|
||||
mod which;
|
||||
mod widgets;
|
||||
|
||||
use app::*;
|
||||
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_core::Ctx;
|
||||
|
||||
use crate::widgets;
|
||||
|
||||
pub(crate) struct Select<'a> {
|
||||
cx: &'a Ctx,
|
||||
}
|
||||
|
|
@ -28,7 +30,7 @@ impl<'a> Widget for Select<'a> {
|
|||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Clear.render(area, buf);
|
||||
widgets::Clear.render(area, buf);
|
||||
List::new(items)
|
||||
.block(
|
||||
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_core::{tasks::TASKS_PERCENT, Ctx};
|
||||
|
||||
use super::Clear;
|
||||
use crate::widgets;
|
||||
|
||||
pub(crate) struct Layout<'a> {
|
||||
cx: &'a Ctx,
|
||||
|
|
@ -36,7 +36,7 @@ impl<'a> Widget for Layout<'a> {
|
|||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
let area = Self::area(area);
|
||||
|
||||
Clear.render(area, buf);
|
||||
widgets::Clear.render(area, buf);
|
||||
let block = Block::new()
|
||||
.title({
|
||||
let mut line = Line::from("Tasks");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
mod clear;
|
||||
mod layout;
|
||||
|
||||
use clear::*;
|
||||
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_core::Ctx;
|
||||
|
||||
use super::Side;
|
||||
use crate::widgets;
|
||||
|
||||
pub(crate) struct Which<'a> {
|
||||
cx: &'a Ctx,
|
||||
|
|
@ -38,7 +39,7 @@ impl Widget for Which<'_> {
|
|||
.constraints([Constraint::Ratio(1, 3), Constraint::Ratio(1, 3), Constraint::Ratio(1, 3)])
|
||||
.split(area);
|
||||
|
||||
Clear.render(area, buf);
|
||||
widgets::Clear.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.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