This commit is contained in:
sxyazi 2023-11-28 02:19:05 +08:00
parent a4629adc30
commit de3623bbb9
No known key found for this signature in database
99 changed files with 185 additions and 192 deletions

View file

@ -1,7 +1,7 @@
use std::borrow::Cow; use std::borrow::Cow;
use serde::Deserialize; use serde::Deserialize;
use yazi_shared::Exec; use yazi_shared::event::Exec;
use super::Key; use super::Key;

View file

@ -2,7 +2,7 @@ use std::fmt;
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use serde::{de::{self, Visitor}, Deserializer}; use serde::{de::{self, Visitor}, Deserializer};
use yazi_shared::Exec; use yazi_shared::event::Exec;
pub(super) fn exec_deserialize<'de, D>(deserializer: D) -> Result<Vec<Exec>, D::Error> pub(super) fn exec_deserialize<'de, D>(deserializer: D) -> Result<Vec<Exec>, D::Error>
where where

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::completion::Completion; use crate::completion::Completion;

View file

@ -1,6 +1,6 @@
use yazi_shared::{Exec, Layer}; use yazi_shared::{emit, event::Exec, Layer};
use crate::{completion::Completion, emit, input::Input}; use crate::{completion::Completion, input::Input};
pub struct Opt { pub struct Opt {
submit: bool, submit: bool,

View file

@ -1,6 +1,6 @@
use std::{mem, ops::ControlFlow}; use std::{mem, ops::ControlFlow};
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::completion::Completion; use crate::completion::Completion;

View file

@ -1,9 +1,9 @@
use std::{mem, path::{MAIN_SEPARATOR, MAIN_SEPARATOR_STR}}; use std::{mem, path::{MAIN_SEPARATOR, MAIN_SEPARATOR_STR}};
use tokio::fs; use tokio::fs;
use yazi_shared::{Exec, Layer}; use yazi_shared::{emit, event::Exec, Layer};
use crate::{completion::Completion, emit}; use crate::completion::Completion;
pub struct Opt<'a> { pub struct Opt<'a> {
word: &'a str, word: &'a str,

View file

@ -1,9 +1,9 @@
use ratatui::prelude::Rect; use ratatui::prelude::Rect;
use tokio::sync::oneshot; use tokio::sync::oneshot;
use yazi_config::popup::{Origin, Position}; use yazi_config::popup::{Origin, Position};
use yazi_shared::{Exec, Layer}; use yazi_shared::{emit, event::Exec, Layer};
use crate::{completion::Completion, emit, help::Help, input::Input, manager::Manager, select::Select, tasks::Tasks, which::Which}; use crate::{completion::Completion, help::Help, input::Input, manager::Manager, select::Select, tasks::Tasks, which::Which};
pub struct Ctx { pub struct Ctx {
pub manager: Manager, pub manager: Manager,

View file

@ -2,9 +2,7 @@ use std::process::Stdio;
use anyhow::Result; use anyhow::Result;
use tokio::{io::{AsyncBufReadExt, BufReader}, process::Command, sync::mpsc::{self, UnboundedReceiver}}; use tokio::{io::{AsyncBufReadExt, BufReader}, process::Command, sync::mpsc::{self, UnboundedReceiver}};
use yazi_shared::fs::Url; use yazi_shared::{files::File, fs::Url};
use crate::files::File;
pub struct FdOpt { pub struct FdOpt {
pub cwd: Url, pub cwd: Url,

View file

@ -2,9 +2,7 @@ use std::process::Stdio;
use anyhow::Result; use anyhow::Result;
use tokio::{io::{AsyncBufReadExt, BufReader}, process::Command, sync::mpsc::{self, UnboundedReceiver}}; use tokio::{io::{AsyncBufReadExt, BufReader}, process::Command, sync::mpsc::{self, UnboundedReceiver}};
use yazi_shared::fs::Url; use yazi_shared::{files::File, fs::Url};
use crate::files::File;
pub struct RgOpt { pub struct RgOpt {
pub cwd: Url, pub cwd: Url,

View file

@ -3,9 +3,9 @@ use std::{collections::{BTreeMap, BTreeSet}, mem, ops::Deref, sync::atomic::Orde
use anyhow::Result; use anyhow::Result;
use tokio::{fs, select, sync::mpsc::{self, UnboundedReceiver}}; use tokio::{fs, select, sync::mpsc::{self, UnboundedReceiver}};
use yazi_config::{manager::SortBy, MANAGER}; use yazi_config::{manager::SortBy, MANAGER};
use yazi_shared::fs::Url; use yazi_shared::{files::{File, FILES_TICKET}, fs::Url};
use super::{File, FilesSorter, FILES_TICKET}; use super::FilesSorter;
pub struct Files { pub struct Files {
items: Vec<File>, items: Vec<File>,

View file

@ -1,9 +1,5 @@
mod file;
mod files; mod files;
mod op;
mod sorter; mod sorter;
pub use file::*;
pub use files::*; pub use files::*;
pub use op::*;
pub use sorter::*; pub use sorter::*;

View file

@ -1,9 +1,7 @@
use std::{cmp::Ordering, collections::BTreeMap, mem}; use std::{cmp::Ordering, collections::BTreeMap, mem};
use yazi_config::manager::SortBy; use yazi_config::manager::SortBy;
use yazi_shared::{fs::Url, natsort}; use yazi_shared::{files::File, fs::Url, natsort};
use super::File;
#[derive(Clone, Copy, Default, PartialEq)] #[derive(Clone, Copy, Default, PartialEq)]
pub struct FilesSorter { pub struct FilesSorter {

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::help::Help; use crate::help::Help;

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::help::Help; use crate::help::Help;

View file

@ -1,5 +1,5 @@
use yazi_config::popup::{Offset, Origin, Position}; use yazi_config::popup::{Offset, Origin, Position};
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::{help::Help, input::Input}; use crate::{help::Help, input::Input};

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::input::Input; use crate::input::Input;

View file

@ -1,4 +1,4 @@
use yazi_shared::{CharKind, Exec}; use yazi_shared::{event::Exec, CharKind};
use crate::input::Input; use crate::input::Input;

View file

@ -1,4 +1,4 @@
use yazi_shared::{Exec, InputError}; use yazi_shared::{event::Exec, InputError};
use crate::{completion::Completion, input::Input}; use crate::{completion::Completion, input::Input};

View file

@ -1,8 +1,8 @@
use std::path::MAIN_SEPARATOR; use std::path::MAIN_SEPARATOR;
use yazi_shared::{Exec, Layer}; use yazi_shared::{emit, event::Exec, Layer};
use crate::{emit, input::Input}; use crate::input::Input;
pub struct Opt<'a> { pub struct Opt<'a> {
word: &'a str, word: &'a str,

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::input::{op::InputOp, Input}; use crate::input::{op::InputOp, Input};

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::{completion::Completion, input::{op::InputOp, Input, InputMode}}; use crate::{completion::Completion, input::{op::InputOp, Input, InputMode}};

View file

@ -1,4 +1,4 @@
use yazi_shared::{CharKind, Exec}; use yazi_shared::{event::Exec, CharKind};
use crate::input::{op::InputOp, Input}; use crate::input::{op::InputOp, Input};

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::input::{op::InputOp, Input, InputMode}; use crate::input::{op::InputOp, Input, InputMode};

View file

@ -1,6 +1,6 @@
use std::ops::RangeBounds; use std::ops::RangeBounds;
use yazi_shared::{CharKind, Exec}; use yazi_shared::{event::Exec, CharKind};
use crate::input::Input; use crate::input::Input;

View file

@ -1,5 +1,5 @@
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::input::{op::InputOp, snap::InputSnap, Input}; use crate::input::{op::InputOp, snap::InputSnap, Input};

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::{external, input::{op::InputOp, Input}}; use crate::{external, input::{op::InputOp, Input}};

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::input::Input; use crate::input::Input;

View file

@ -1,9 +1,9 @@
use anyhow::anyhow; use anyhow::anyhow;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use yazi_config::popup::InputCfg; use yazi_config::popup::InputCfg;
use yazi_shared::{Exec, InputError, Layer}; use yazi_shared::{emit, event::Exec, InputError, Layer};
use crate::{emit, input::Input}; use crate::input::Input;
pub struct Opt { pub struct Opt {
cfg: InputCfg, cfg: InputCfg,

View file

@ -1,5 +1,5 @@
use yazi_config::keymap::Key; use yazi_config::keymap::Key;
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::input::{Input, InputMode}; use crate::input::{Input, InputMode};

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::input::{Input, InputMode}; use crate::input::{Input, InputMode};

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::input::{op::InputOp, Input, InputMode}; use crate::input::{op::InputOp, Input, InputMode};

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::input::{op::InputOp, Input}; use crate::input::{op::InputOp, Input};

View file

@ -9,7 +9,6 @@
mod blocker; mod blocker;
pub mod completion; pub mod completion;
mod context; mod context;
mod event;
pub mod external; pub mod external;
pub mod files; pub mod files;
pub mod help; pub mod help;
@ -25,7 +24,6 @@ pub mod which;
pub use blocker::*; pub use blocker::*;
pub use context::*; pub use context::*;
pub use event::*;
pub use highlighter::*; pub use highlighter::*;
pub use step::*; pub use step::*;

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::{manager::Manager, tasks::Tasks}; use crate::{manager::Manager, tasks::Tasks};

View file

@ -2,9 +2,9 @@ use std::path::{PathBuf, MAIN_SEPARATOR};
use tokio::fs; use tokio::fs;
use yazi_config::popup::InputCfg; use yazi_config::popup::InputCfg;
use yazi_shared::{fs::Url, Exec}; use yazi_shared::{emit, event::Exec, files::{File, FilesOp}, fs::Url};
use crate::{emit, files::{File, FilesOp}, input::Input, manager::Manager}; use crate::{input::Input, manager::Manager};
pub struct Opt { pub struct Opt {
force: bool, force: bool,

View file

@ -1,9 +1,8 @@
use std::collections::BTreeSet; use std::collections::BTreeSet;
use yazi_shared::Exec; use yazi_shared::{emit, event::Exec, fs::Url, Layer};
use yazi_shared::{fs::Url, Layer};
use crate::{emit, manager::Manager}; use crate::manager::Manager;
pub struct Opt { pub struct Opt {
url: Option<Url>, url: Option<Url>,

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::{manager::Manager, tasks::Tasks}; use crate::{manager::Manager, tasks::Tasks};

View file

@ -1,7 +1,7 @@
use std::ffi::OsString; use std::ffi::OsString;
use yazi_config::{popup::SelectCfg, OPEN}; use yazi_config::{popup::SelectCfg, OPEN};
use yazi_shared::{Exec, MIME_DIR}; use yazi_shared::{event::Exec, MIME_DIR};
use crate::{external, manager::Manager, select::Select, tasks::Tasks}; use crate::{external, manager::Manager, select::Select, tasks::Tasks};

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::{manager::Manager, tasks::Tasks}; use crate::{manager::Manager, tasks::Tasks};

View file

@ -1,7 +1,7 @@
use yazi_config::MANAGER; use yazi_config::MANAGER;
use yazi_shared::{fs::Url, Exec, Layer, MIME_DIR}; use yazi_shared::{emit, event::Exec, fs::Url, Layer, MIME_DIR};
use crate::{emit, manager::Manager}; use crate::manager::Manager;
#[derive(Debug)] #[derive(Debug)]
pub struct Opt { pub struct Opt {

View file

@ -1,7 +1,7 @@
use yazi_config::popup::InputCfg; use yazi_config::popup::InputCfg;
use yazi_shared::Exec; use yazi_shared::{emit, event::Exec};
use crate::{emit, input::Input, manager::Manager, tasks::Tasks}; use crate::{input::Input, manager::Manager, tasks::Tasks};
#[derive(Default)] #[derive(Default)]
pub struct Opt { pub struct Opt {

View file

@ -1,9 +1,8 @@
use std::env; use std::env;
use yazi_shared::Exec; use yazi_shared::{emit, event::Exec, Layer};
use yazi_shared::Layer;
use crate::{emit, manager::Manager}; use crate::manager::Manager;
pub struct Opt; pub struct Opt;

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::{manager::Manager, tasks::Tasks}; use crate::{manager::Manager, tasks::Tasks};

View file

@ -3,9 +3,9 @@ use std::{collections::BTreeMap, ffi::OsStr, io::{stdout, BufWriter, Write}, pat
use anyhow::{anyhow, bail, Result}; use anyhow::{anyhow, bail, Result};
use tokio::{fs::{self, OpenOptions}, io::{stdin, AsyncReadExt, AsyncWriteExt}}; use tokio::{fs::{self, OpenOptions}, io::{stdin, AsyncReadExt, AsyncWriteExt}};
use yazi_config::{popup::InputCfg, OPEN, PREVIEW}; use yazi_config::{popup::InputCfg, OPEN, PREVIEW};
use yazi_shared::{fs::{max_common_root, Url}, term::Term, Defer, Exec}; use yazi_shared::{emit, event::Exec, files::{File, FilesOp}, fs::{max_common_root, Url}, term::Term, Defer};
use crate::{emit, external::{self, ShellOpt}, files::{File, FilesOp}, input::Input, manager::Manager, Ctx, BLOCKER}; use crate::{external::{self, ShellOpt}, input::Input, manager::Manager, Ctx, BLOCKER};
pub struct Opt { pub struct Opt {
force: bool, force: bool,

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::{manager::Manager, Ctx}; use crate::{manager::Manager, Ctx};

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::manager::Tabs; use crate::manager::Tabs;

View file

@ -1,5 +1,4 @@
use yazi_shared::Exec; use yazi_shared::{event::Exec, fs::Url};
use yazi_shared::fs::Url;
use crate::{manager::Tabs, tab::Tab}; use crate::{manager::Tabs, tab::Tab};

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::manager::Tabs; use crate::manager::Tabs;

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::manager::Tabs; use crate::manager::Tabs;

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::manager::Manager; use crate::manager::Manager;

View file

@ -1,9 +1,9 @@
use std::collections::{BTreeMap, HashMap, HashSet}; use std::collections::{BTreeMap, HashMap, HashSet};
use yazi_shared::fs::Url; use yazi_shared::{files::{File, FilesOp}, fs::Url};
use super::{Tabs, Watcher}; use super::{Tabs, Watcher};
use crate::{files::{File, FilesOp}, tab::{Folder, Tab}, tasks::Tasks}; use crate::{tab::{Folder, Tab}, tasks::Tasks};
pub struct Manager { pub struct Manager {
pub tabs: Tabs, pub tabs: Tabs,

View file

@ -5,9 +5,9 @@ use notify::{event::{MetadataKind, ModifyKind}, EventKind, RecommendedWatcher, R
use parking_lot::RwLock; use parking_lot::RwLock;
use tokio::{fs, pin, sync::mpsc::{self, UnboundedReceiver}}; use tokio::{fs, pin, sync::mpsc::{self, UnboundedReceiver}};
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt}; use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
use yazi_shared::fs::Url; use yazi_shared::{emit, files::{File, FilesOp}, fs::Url};
use crate::{emit, external, files::{File, Files, FilesOp}}; use crate::{external, files::Files};
pub struct Watcher { pub struct Watcher {
watcher: RecommendedWatcher, watcher: RecommendedWatcher,

View file

@ -4,10 +4,10 @@ use tokio::{pin, task::JoinHandle};
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt}; use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
use yazi_adaptor::ADAPTOR; use yazi_adaptor::ADAPTOR;
use yazi_config::MANAGER; use yazi_config::MANAGER;
use yazi_shared::{fs::{Cha, Url}, MimeKind, PeekError}; use yazi_shared::{emit, event::{PreviewData, PreviewLock}, files::FilesOp, fs::{Cha, Url}, MimeKind, PeekError};
use super::Provider; use super::Provider;
use crate::{emit, files::{Files, FilesOp}, manager::Manager, Highlighter}; use crate::{files::Files, manager::Manager, Highlighter};
#[derive(Default)] #[derive(Default)]
pub struct Preview { pub struct Preview {
@ -17,20 +17,6 @@ pub struct Preview {
handle: Option<JoinHandle<()>>, handle: Option<JoinHandle<()>>,
} }
pub struct PreviewLock {
pub url: Url,
pub cha: Option<Cha>,
pub skip: usize,
pub data: PreviewData,
}
#[derive(Debug)]
pub enum PreviewData {
Folder,
Text(String),
Image,
}
impl Preview { impl Preview {
pub fn go(&mut self, url: &Url, cha: Cha, mime: &str) { pub fn go(&mut self, url: &Url, cha: Cha, mime: &str) {
if self.content_unchanged(url, &cha) { if self.content_unchanged(url, &cha) {
@ -152,11 +138,3 @@ impl Preview {
} }
} }
} }
impl PreviewLock {
#[inline]
pub fn is_image(&self) -> bool { matches!(self.data, PreviewData::Image) }
#[inline]
pub fn is_folder(&self) -> bool { matches!(self.data, PreviewData::Folder) }
}

View file

@ -3,9 +3,8 @@ use std::path::Path;
use tokio::fs; use tokio::fs;
use yazi_adaptor::ADAPTOR; use yazi_adaptor::ADAPTOR;
use yazi_config::{MANAGER, PREVIEW}; use yazi_config::{MANAGER, PREVIEW};
use yazi_shared::{MimeKind, PeekError}; use yazi_shared::{event::PreviewData, MimeKind, PeekError};
use super::PreviewData;
use crate::{external, Highlighter}; use crate::{external, Highlighter};
pub(super) struct Provider; pub(super) struct Provider;

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::select::Select; use crate::select::Select;

View file

@ -1,5 +1,5 @@
use anyhow::anyhow; use anyhow::anyhow;
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::select::Select; use crate::select::Select;

View file

@ -1,9 +1,9 @@
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use tokio::sync::oneshot; use tokio::sync::oneshot;
use yazi_config::popup::SelectCfg; use yazi_config::popup::SelectCfg;
use yazi_shared::{term::Term, Exec, Layer}; use yazi_shared::{emit, event::Exec, term::Term, Layer};
use crate::{emit, select::Select}; use crate::select::Select;
pub struct Opt { pub struct Opt {
cfg: SelectCfg, cfg: SelectCfg,

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::{manager::Manager, tab::Tab, Step}; use crate::{manager::Manager, tab::Tab, Step};

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::tab::Tab; use crate::tab::Tab;

View file

@ -3,9 +3,9 @@ use std::{mem, time::Duration};
use tokio::{fs, pin}; use tokio::{fs, pin};
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt}; use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
use yazi_config::popup::InputCfg; use yazi_config::popup::InputCfg;
use yazi_shared::{fs::{expand_path, Url}, Debounce, Exec, InputError, Layer}; use yazi_shared::{emit, event::Exec, fs::{expand_path, Url}, Debounce, InputError, Layer};
use crate::{completion::Completion, emit, input::Input, manager::Manager, tab::Tab}; use crate::{completion::Completion, input::Input, manager::Manager, tab::Tab};
pub struct Opt { pub struct Opt {
target: Url, target: Url,

View file

@ -1,6 +1,6 @@
use std::ffi::{OsStr, OsString}; use std::ffi::{OsStr, OsString};
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::{external, tab::Tab}; use crate::{external, tab::Tab};

View file

@ -1,6 +1,6 @@
use std::mem; use std::mem;
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::{manager::Manager, tab::Tab}; use crate::{manager::Manager, tab::Tab};

View file

@ -1,5 +1,5 @@
use bitflags::bitflags; use bitflags::bitflags;
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::tab::{Mode, Tab}; use crate::tab::{Mode, Tab};

View file

@ -3,9 +3,9 @@ use std::time::Duration;
use tokio::pin; use tokio::pin;
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt}; use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
use yazi_config::popup::InputCfg; use yazi_config::popup::InputCfg;
use yazi_shared::{Debounce, Exec, InputError, Layer}; use yazi_shared::{emit, event::Exec, Debounce, InputError, Layer};
use crate::{emit, input::Input, tab::{Finder, FinderCase, Tab}}; use crate::{input::Input, tab::{Finder, FinderCase, Tab}};
pub struct Opt<'a> { pub struct Opt<'a> {
query: Option<&'a str>, query: Option<&'a str>,

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::{manager::Manager, tab::Tab}; use crate::{manager::Manager, tab::Tab};

View file

@ -1,4 +1,4 @@
use yazi_shared::{fs::ends_with_slash, Defer, Exec}; use yazi_shared::{event::Exec, fs::ends_with_slash, Defer};
use crate::{external::{self, FzfOpt, ZoxideOpt}, tab::Tab, Ctx, BLOCKER}; use crate::{external::{self, FzfOpt, ZoxideOpt}, tab::Tab, Ctx, BLOCKER};

View file

@ -1,6 +1,6 @@
use std::mem; use std::mem;
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::{manager::Manager, tab::Tab}; use crate::{manager::Manager, tab::Tab};

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::tab::Tab; use crate::tab::Tab;

View file

@ -1,7 +1,6 @@
use yazi_shared::Exec; use yazi_shared::{emit, event::Exec, files::{File, FilesOp}, fs::{expand_path, Url}, Layer};
use yazi_shared::{fs::{expand_path, Url}, Layer};
use crate::{emit, files::{File, FilesOp}, manager::Manager, tab::Tab}; use crate::{manager::Manager, tab::Tab};
pub struct Opt { pub struct Opt {
target: Url, target: Url,

View file

@ -4,9 +4,9 @@ use anyhow::bail;
use tokio::pin; use tokio::pin;
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt}; use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
use yazi_config::popup::InputCfg; use yazi_config::popup::InputCfg;
use yazi_shared::Exec; use yazi_shared::{emit, event::Exec, files::FilesOp};
use crate::{emit, external, files::FilesOp, input::Input, manager::Manager, tab::Tab}; use crate::{external, input::Input, manager::Manager, tab::Tab};
pub struct Opt { pub struct Opt {
pub type_: OptType, pub type_: OptType,

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::tab::Tab; use crate::tab::Tab;

View file

@ -1,5 +1,5 @@
use yazi_config::{open::Opener, popup::InputCfg}; use yazi_config::{open::Opener, popup::InputCfg};
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::{input::Input, tab::Tab, tasks::Tasks}; use crate::{input::Input, tab::Tab, tasks::Tasks};

View file

@ -1,7 +1,7 @@
use std::str::FromStr; use std::str::FromStr;
use yazi_config::manager::SortBy; use yazi_config::manager::SortBy;
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::tab::Tab; use crate::tab::Tab;

View file

@ -1,6 +1,6 @@
use std::collections::BTreeSet; use std::collections::BTreeSet;
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::tab::{Mode, Tab}; use crate::tab::{Mode, Tab};

View file

@ -1,8 +1,8 @@
use ratatui::layout::Rect; use ratatui::layout::Rect;
use yazi_config::MANAGER; use yazi_config::MANAGER;
use yazi_shared::fs::Url; use yazi_shared::{emit, files::{File, FilesOp}, fs::Url};
use crate::{emit, files::{File, Files, FilesOp}, Step}; use crate::{files::Files, Step};
#[derive(Default)] #[derive(Default)]
pub struct Folder { pub struct Folder {

View file

@ -2,10 +2,10 @@ use std::{borrow::Cow, collections::BTreeMap};
use anyhow::Result; use anyhow::Result;
use tokio::task::JoinHandle; use tokio::task::JoinHandle;
use yazi_shared::fs::Url; use yazi_shared::{event::PreviewLock, files::File, fs::Url};
use super::{Backstack, Config, Finder, Folder, Mode}; use super::{Backstack, Config, Finder, Folder, Mode};
use crate::{files::File, preview::{Preview, PreviewLock}}; use crate::preview::Preview;
pub struct Tab { pub struct Tab {
pub mode: Mode, pub mode: Mode,

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::tasks::Tasks; use crate::tasks::Tasks;

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::tasks::Tasks; use crate::tasks::Tasks;

View file

@ -2,7 +2,7 @@ use std::io::{stdout, Write};
use crossterm::terminal::{disable_raw_mode, enable_raw_mode}; use crossterm::terminal::{disable_raw_mode, enable_raw_mode};
use tokio::{io::{stdin, AsyncReadExt}, select, sync::mpsc, time}; use tokio::{io::{stdin, AsyncReadExt}, select, sync::mpsc, time};
use yazi_shared::{term::Term, Defer, Exec}; use yazi_shared::{event::Exec, term::Term, Defer};
use crate::{tasks::Tasks, Ctx, BLOCKER}; use crate::{tasks::Tasks, Ctx, BLOCKER};

View file

@ -2,9 +2,9 @@ use std::ffi::OsString;
use anyhow::anyhow; use anyhow::anyhow;
use yazi_config::{open::Opener, BOOT}; use yazi_config::{open::Opener, BOOT};
use yazi_shared::{Exec, Layer}; use yazi_shared::{emit, event::Exec, Layer};
use crate::{emit, tasks::Tasks}; use crate::tasks::Tasks;
pub struct Opt { pub struct Opt {
targets: Vec<(OsString, String)>, targets: Vec<(OsString, String)>,

View file

@ -1,4 +1,4 @@
use yazi_shared::Exec; use yazi_shared::event::Exec;
use crate::tasks::Tasks; use crate::tasks::Tasks;

View file

@ -1,7 +1,7 @@
use anyhow::anyhow; use anyhow::anyhow;
use yazi_shared::{Exec, Layer}; use yazi_shared::{emit, event::Exec, Layer};
use crate::{emit, tasks::{Tasks, TasksProgress}}; use crate::tasks::{Tasks, TasksProgress};
pub struct Opt { pub struct Opt {
progress: TasksProgress, progress: TasksProgress,

View file

@ -3,10 +3,10 @@ use std::{collections::{BTreeMap, HashMap, HashSet}, ffi::OsStr, path::Path, syn
use serde::Serialize; use serde::Serialize;
use tracing::debug; use tracing::debug;
use yazi_config::{manager::SortBy, open::Opener, popup::InputCfg, OPEN}; use yazi_config::{manager::SortBy, open::Opener, popup::InputCfg, OPEN};
use yazi_shared::{fs::Url, term::Term, MimeKind}; use yazi_shared::{files::File, fs::Url, term::Term, MimeKind};
use super::{running::Running, task::TaskSummary, Scheduler, TASKS_PADDING, TASKS_PERCENT}; use super::{running::Running, task::TaskSummary, Scheduler, TASKS_PADDING, TASKS_PERCENT};
use crate::{files::{File, Files}, input::Input}; use crate::{files::Files, input::Input};
pub struct Tasks { pub struct Tasks {
pub(super) scheduler: Arc<Scheduler>, pub(super) scheduler: Arc<Scheduler>,

View file

@ -5,9 +5,9 @@ use parking_lot::Mutex;
use tokio::{fs, sync::mpsc}; use tokio::{fs, sync::mpsc};
use yazi_adaptor::Image; use yazi_adaptor::Image;
use yazi_config::PREVIEW; use yazi_config::PREVIEW;
use yazi_shared::{fs::{calculate_size, Url}, Throttle}; use yazi_shared::{emit, files::FilesOp, fs::{calculate_size, Url}, Throttle};
use crate::{emit, external, files::FilesOp, tasks::TaskOp}; use crate::{external, tasks::TaskOp};
pub(crate) struct Precache { pub(crate) struct Precache {
tx: async_channel::Sender<PrecacheOp>, tx: async_channel::Sender<PrecacheOp>,

View file

@ -1,9 +1,7 @@
use std::mem; use std::mem;
use yazi_config::{keymap::{Control, Key}, KEYMAP}; use yazi_config::{keymap::{Control, Key}, KEYMAP};
use yazi_shared::Layer; use yazi_shared::{emit, Layer};
use crate::emit;
pub struct Which { pub struct Which {
layer: Layer, layer: Layer,

View file

@ -4,8 +4,8 @@ use anyhow::{Ok, Result};
use crossterm::event::KeyEvent; use crossterm::event::KeyEvent;
use ratatui::{backend::Backend, prelude::Rect}; use ratatui::{backend::Backend, prelude::Rect};
use yazi_config::{keymap::Key, BOOT}; use yazi_config::{keymap::Key, BOOT};
use yazi_core::{emit, files::FilesOp, input::InputMode, preview::COLLISION, Ctx, Event}; use yazi_core::{input::InputMode, preview::COLLISION, Ctx};
use yazi_shared::{term::Term, Exec, Layer}; use yazi_shared::{emit, event::{Event, Exec}, files::FilesOp, term::Term, Layer};
use crate::{Executor, Logs, Panic, Root, Signals}; use crate::{Executor, Logs, Panic, Root, Signals};

View file

@ -1,7 +1,7 @@
use anyhow::Result; use anyhow::Result;
use tokio::sync::oneshot; use tokio::sync::oneshot;
use yazi_core::{emit, manager::Manager}; use yazi_core::manager::Manager;
use yazi_shared::{term::Term, Exec}; use yazi_shared::{emit, event::Exec, term::Term};
use crate::app::App; use crate::app::App;

View file

@ -1,6 +1,6 @@
use yazi_config::{keymap::{Control, Key}, KEYMAP}; use yazi_config::{keymap::{Control, Key}, KEYMAP};
use yazi_core::input::InputMode; use yazi_core::input::InputMode;
use yazi_shared::{Exec, Layer}; use yazi_shared::{event::Exec, Layer};
use crate::app::App; use crate::app::App;

View file

@ -2,7 +2,7 @@ use anyhow::Result;
use crossterm::event::{Event as CrosstermEvent, EventStream, KeyEvent, KeyEventKind}; use crossterm::event::{Event as CrosstermEvent, EventStream, KeyEvent, KeyEventKind};
use futures::StreamExt; use futures::StreamExt;
use tokio::{select, sync::{mpsc::{self, UnboundedReceiver, UnboundedSender}, oneshot}, task::JoinHandle}; use tokio::{select, sync::{mpsc::{self, UnboundedReceiver, UnboundedSender}, oneshot}, task::JoinHandle};
use yazi_core::Event; use yazi_shared::event::Event;
pub(super) struct Signals { pub(super) struct Signals {
tx: UnboundedSender<Event>, tx: UnboundedSender<Event>,

View file

@ -104,7 +104,7 @@ impl<'a, 'b> Active<'a, 'b> {
fn file( fn file(
&self, &self,
idx: usize, idx: usize,
inner: &'a yazi_core::files::File, inner: &'a yazi_shared::files::File,
folder: &'a yazi_core::tab::Folder, folder: &'a yazi_core::tab::Folder,
) -> mlua::Result<AnyUserData<'a>> { ) -> mlua::Result<AnyUserData<'a>> {
let ud = self.scope.create_any_userdata_ref(inner)?; let ud = self.scope.create_any_userdata_ref(inner)?;

View file

@ -6,10 +6,10 @@ use yazi_config::THEME;
use super::{Range, Url}; use super::{Range, Url};
use crate::{layout::Style, LUA}; use crate::{layout::Style, LUA};
pub struct File(yazi_core::files::File); pub struct File(yazi_shared::files::File);
impl From<&yazi_core::files::File> for File { impl From<&yazi_shared::files::File> for File {
fn from(value: &yazi_core::files::File) -> Self { Self(value.clone()) } fn from(value: &yazi_shared::files::File) -> Self { Self(value.clone()) }
} }
impl UserData for File { impl UserData for File {
@ -47,7 +47,7 @@ impl Files {
}); });
})?; })?;
LUA.register_userdata_type::<yazi_core::files::File>(|reg| { LUA.register_userdata_type::<yazi_shared::files::File>(|reg| {
reg.add_field_method_get("url", |_, me| Ok(Url::from(&me.url))); reg.add_field_method_get("url", |_, me| Ok(Url::from(&me.url)));
reg.add_field_method_get("link_to", |_, me| Ok(me.link_to().map(Url::from))); reg.add_field_method_get("link_to", |_, me| Ok(me.link_to().map(Url::from)));
reg.add_field_method_get("is_link", |_, me| Ok(me.is_link())); reg.add_field_method_get("is_link", |_, me| Ok(me.is_link()));
@ -87,7 +87,7 @@ impl Files {
Ok(me.url.file_name().map(|n| n.to_string_lossy().to_string())) Ok(me.url.file_name().map(|n| n.to_string_lossy().to_string()))
}); });
reg.add_function("size", |_, me: AnyUserData| { reg.add_function("size", |_, me: AnyUserData| {
let file = me.borrow::<yazi_core::files::File>()?; let file = me.borrow::<yazi_shared::files::File>()?;
if !file.is_dir() { if !file.is_dir() {
return Ok(Some(file.len)); return Ok(Some(file.len));
} }
@ -97,7 +97,7 @@ impl Files {
}); });
reg.add_function("mime", |_, me: AnyUserData| { reg.add_function("mime", |_, me: AnyUserData| {
let manager = me.named_user_value::<UserDataRef<yazi_core::manager::Manager>>("manager")?; let manager = me.named_user_value::<UserDataRef<yazi_core::manager::Manager>>("manager")?;
let file = me.borrow::<yazi_core::files::File>()?; let file = me.borrow::<yazi_shared::files::File>()?;
Ok(manager.mimetype.get(&file.url).cloned()) Ok(manager.mimetype.get(&file.url).cloned())
}); });
reg.add_function("prefix", |_, me: AnyUserData| { reg.add_function("prefix", |_, me: AnyUserData| {
@ -106,7 +106,7 @@ impl Files {
return Ok(None); return Ok(None);
} }
let file = me.borrow::<yazi_core::files::File>()?; let file = me.borrow::<yazi_shared::files::File>()?;
let mut p = file.url.strip_prefix(&folder.cwd).unwrap_or(&file.url).components(); let mut p = file.url.strip_prefix(&folder.cwd).unwrap_or(&file.url).components();
p.next_back(); p.next_back();
Ok(Some(p.as_path().to_string_lossy().to_string())) Ok(Some(p.as_path().to_string_lossy().to_string()))
@ -122,7 +122,7 @@ impl Files {
}); });
reg.add_function("style", |_, me: AnyUserData| { reg.add_function("style", |_, me: AnyUserData| {
let manager = me.named_user_value::<UserDataRef<yazi_core::manager::Manager>>("manager")?; let manager = me.named_user_value::<UserDataRef<yazi_core::manager::Manager>>("manager")?;
let file = me.borrow::<yazi_core::files::File>()?; let file = me.borrow::<yazi_shared::files::File>()?;
let mime = manager.mimetype.get(&file.url); let mime = manager.mimetype.get(&file.url);
Ok( Ok(
THEME THEME
@ -134,12 +134,12 @@ impl Files {
}); });
reg.add_function("is_hovered", |_, me: AnyUserData| { reg.add_function("is_hovered", |_, me: AnyUserData| {
let folder = me.named_user_value::<UserDataRef<yazi_core::tab::Folder>>("folder")?; let folder = me.named_user_value::<UserDataRef<yazi_core::tab::Folder>>("folder")?;
let file = me.borrow::<yazi_core::files::File>()?; let file = me.borrow::<yazi_shared::files::File>()?;
Ok(matches!(folder.hovered(), Some(f) if f.url == file.url)) Ok(matches!(folder.hovered(), Some(f) if f.url == file.url))
}); });
reg.add_function("is_yanked", |_, me: AnyUserData| { reg.add_function("is_yanked", |_, me: AnyUserData| {
let manager = me.named_user_value::<UserDataRef<yazi_core::manager::Manager>>("manager")?; let manager = me.named_user_value::<UserDataRef<yazi_core::manager::Manager>>("manager")?;
let file = me.borrow::<yazi_core::files::File>()?; let file = me.borrow::<yazi_shared::files::File>()?;
Ok(if !manager.yanked.1.contains(&file.url) { Ok(if !manager.yanked.1.contains(&file.url) {
0u8 0u8
} else if manager.yanked.0 { } else if manager.yanked.0 {
@ -151,7 +151,7 @@ impl Files {
reg.add_function("is_selected", |_, me: AnyUserData| { reg.add_function("is_selected", |_, me: AnyUserData| {
let manager = me.named_user_value::<UserDataRef<yazi_core::manager::Manager>>("manager")?; let manager = me.named_user_value::<UserDataRef<yazi_core::manager::Manager>>("manager")?;
let folder = me.named_user_value::<UserDataRef<yazi_core::tab::Folder>>("folder")?; let folder = me.named_user_value::<UserDataRef<yazi_core::tab::Folder>>("folder")?;
let file = me.borrow::<yazi_core::files::File>()?; let file = me.borrow::<yazi_shared::files::File>()?;
let selected = folder.files.is_selected(&file.url); let selected = folder.files.is_selected(&file.url);
Ok(if !manager.active().mode.is_visual() { Ok(if !manager.active().mode.is_visual() {
@ -167,7 +167,7 @@ impl Files {
return Ok(None); return Ok(None);
}; };
let file = me.borrow::<yazi_core::files::File>()?; let file = me.borrow::<yazi_shared::files::File>()?;
if let Some(idx) = finder.matched_idx(&file.url) { if let Some(idx) = finder.matched_idx(&file.url) {
return Some( return Some(
lua.create_sequence_from([idx.into_lua(lua)?, finder.matched().len().into_lua(lua)?]), lua.create_sequence_from([idx.into_lua(lua)?, finder.matched().len().into_lua(lua)?]),
@ -182,7 +182,7 @@ impl Files {
return Ok(None); return Ok(None);
}; };
let file = me.borrow::<yazi_core::files::File>()?; let file = me.borrow::<yazi_shared::files::File>()?;
let Some(h) = file.name().and_then(|n| finder.highlighted(n)) else { let Some(h) = file.name().and_then(|n| finder.highlighted(n)) else {
return Ok(None); return Ok(None);
}; };

View file

@ -1,6 +1,7 @@
use ansi_to_tui::IntoText; use ansi_to_tui::IntoText;
use ratatui::{buffer::Buffer, layout::Rect, widgets::{Paragraph, Widget}}; use ratatui::{buffer::Buffer, layout::Rect, widgets::{Paragraph, Widget}};
use yazi_core::{preview::PreviewData, Ctx}; use yazi_core::Ctx;
use yazi_shared::event::PreviewData;
use super::Folder; use super::Folder;

View file

@ -2,10 +2,9 @@ use std::collections::BTreeMap;
use crossterm::event::KeyEvent; use crossterm::event::KeyEvent;
use tokio::sync::{mpsc::UnboundedSender, oneshot}; use tokio::sync::{mpsc::UnboundedSender, oneshot};
use yazi_shared::{fs::Url, term::Term, Exec, Layer, RoCell};
use super::files::FilesOp; use super::Exec;
use crate::preview::PreviewLock; use crate::{files::FilesOp, fs::{Cha, Url}, term::Term, Layer, RoCell};
static TX: RoCell<UnboundedSender<Event>> = RoCell::new(); static TX: RoCell<UnboundedSender<Event>> = RoCell::new();
@ -40,39 +39,62 @@ impl Event {
#[macro_export] #[macro_export]
macro_rules! emit { macro_rules! emit {
(Quit($no_cwd_file:expr)) => { (Quit($no_cwd_file:expr)) => {
$crate::Event::Quit($no_cwd_file).emit(); $crate::event::Event::Quit($no_cwd_file).emit();
}; };
(Key($key:expr)) => { (Key($key:expr)) => {
$crate::Event::Key($key).emit(); $crate::event::Event::Key($key).emit();
}; };
(Render) => { (Render) => {
$crate::Event::Render(format!("{}:{}", file!(), line!())).emit(); $crate::event::Event::Render(format!("{}:{}", file!(), line!())).emit();
}; };
(Resize($cols:expr, $rows:expr)) => { (Resize($cols:expr, $rows:expr)) => {
$crate::Event::Resize($cols, $rows).emit(); $crate::event::Event::Resize($cols, $rows).emit();
}; };
(Call($exec:expr, $layer:expr)) => { (Call($exec:expr, $layer:expr)) => {
$crate::Event::Call($exec, $layer).emit(); $crate::event::Event::Call($exec, $layer).emit();
}; };
(Files($op:expr)) => { (Files($op:expr)) => {
$crate::Event::Files($op).emit(); $crate::event::Event::Files($op).emit();
}; };
(Pages($page:expr)) => { (Pages($page:expr)) => {
$crate::Event::Pages($page).emit(); $crate::event::Event::Pages($page).emit();
}; };
(Mimetype($mimes:expr)) => { (Mimetype($mimes:expr)) => {
$crate::Event::Mimetype($mimes).emit(); $crate::event::Event::Mimetype($mimes).emit();
}; };
(Preview($lock:expr)) => { (Preview($lock:expr)) => {
$crate::Event::Preview($lock).emit(); $crate::event::Event::Preview($lock).emit();
}; };
(Open($targets:expr, $opener:expr)) => { (Open($targets:expr, $opener:expr)) => {
$crate::Event::Open($targets, $opener).emit(); $crate::event::Event::Open($targets, $opener).emit();
}; };
($event:ident) => { ($event:ident) => {
$crate::Event::$event.emit(); $crate::event::Event::$event.emit();
}; };
} }
// TODO: remove this
pub struct PreviewLock {
pub url: Url,
pub cha: Option<Cha>,
pub skip: usize,
pub data: PreviewData,
}
#[derive(Debug)]
pub enum PreviewData {
Folder,
Text(String),
Image,
}
impl PreviewLock {
#[inline]
pub fn is_image(&self) -> bool { matches!(self.data, PreviewData::Image) }
#[inline]
pub fn is_folder(&self) -> bool { matches!(self.data, PreviewData::Folder) }
}

View file

@ -0,0 +1,7 @@
#![allow(clippy::module_inception)]
mod event;
mod exec;
pub use event::*;
pub use exec::*;

View file

@ -2,7 +2,8 @@ use std::{borrow::Cow, collections::BTreeMap, ffi::OsStr, fs::Metadata, ops::Der
use anyhow::Result; use anyhow::Result;
use tokio::fs; use tokio::fs;
use yazi_shared::fs::{Cha, ChaKind, Url};
use crate::fs::{Cha, ChaKind, Url};
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
pub struct File { pub struct File {

View file

@ -0,0 +1,5 @@
mod file;
mod op;
pub use file::*;
pub use op::*;

View file

@ -1,11 +1,9 @@
use std::{collections::{BTreeMap, BTreeSet}, sync::atomic::{AtomicU64, Ordering}}; use std::{collections::{BTreeMap, BTreeSet}, sync::atomic::{AtomicU64, Ordering}};
use yazi_shared::fs::Url;
use super::File; use super::File;
use crate::emit; use crate::{emit, fs::Url};
pub(super) static FILES_TICKET: AtomicU64 = AtomicU64::new(0); pub static FILES_TICKET: AtomicU64 = AtomicU64::new(0);
#[derive(Debug)] #[derive(Debug)]
pub enum FilesOp { pub enum FilesOp {

View file

@ -5,7 +5,8 @@ mod debounce;
mod defer; mod defer;
mod env; mod env;
mod errors; mod errors;
mod event; pub mod event;
pub mod files;
pub mod fs; pub mod fs;
mod layer; mod layer;
mod mime; mod mime;
@ -20,7 +21,6 @@ pub use debounce::*;
pub use defer::*; pub use defer::*;
pub use env::*; pub use env::*;
pub use errors::*; pub use errors::*;
pub use event::*;
pub use layer::*; pub use layer::*;
pub use mime::*; pub use mime::*;
pub use natsort::*; pub use natsort::*;