mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
feat: new tab DDS event on tab switch (#1474)
Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
parent
fc304ca043
commit
77d1817771
7 changed files with 65 additions and 13 deletions
|
|
@ -44,9 +44,9 @@ impl Actions {
|
|||
writeln!(s, "\nVariables")?;
|
||||
writeln!(s, " SHELL : {:?}", env::var_os("SHELL"))?;
|
||||
writeln!(s, " EDITOR : {:?}", env::var_os("EDITOR"))?;
|
||||
writeln!(s, " VISUAL : {:?}", env::var_os("VISUAL"))?;
|
||||
writeln!(s, " YAZI_FILE_ONE : {:?}", env::var_os("YAZI_FILE_ONE"))?;
|
||||
writeln!(s, " YAZI_CONFIG_HOME : {:?}", env::var_os("YAZI_CONFIG_HOME"))?;
|
||||
writeln!(s, " ZELLIJ_SESSION_NAME: {:?}", env::var_os("ZELLIJ_SESSION_NAME"))?;
|
||||
|
||||
writeln!(s, "\nText Opener")?;
|
||||
writeln!(
|
||||
|
|
@ -56,9 +56,11 @@ impl Actions {
|
|||
)?;
|
||||
writeln!(s, " block : {:?}", yazi_config::OPEN.block_opener("bulk.txt", "text/plain"))?;
|
||||
|
||||
writeln!(s, "\ntmux")?;
|
||||
writeln!(s, " TMUX : {:?}", *yazi_adapter::TMUX)?;
|
||||
writeln!(s, " Version: {}", Self::process_output("tmux", "-V"))?;
|
||||
writeln!(s, "\nMultiplexers")?;
|
||||
writeln!(s, " TMUX : {:?}", *yazi_adapter::TMUX)?;
|
||||
writeln!(s, " tmux version : {}", Self::process_output("tmux", "-V"))?;
|
||||
writeln!(s, " ZELLIJ_SESSION_NAME: {:?}", env::var_os("ZELLIJ_SESSION_NAME"))?;
|
||||
writeln!(s, " Zellij version : {}", Self::process_output("zellij", "--version"))?;
|
||||
|
||||
writeln!(s, "\nDependencies")?;
|
||||
writeln!(
|
||||
|
|
@ -89,15 +91,19 @@ impl Actions {
|
|||
}
|
||||
|
||||
fn process_output(name: impl AsRef<OsStr>, arg: impl AsRef<OsStr>) -> String {
|
||||
match std::process::Command::new(name.as_ref()).arg(arg).output() {
|
||||
match std::process::Command::new(&name).arg(arg).output() {
|
||||
Ok(out) if out.status.success() => {
|
||||
let line =
|
||||
String::from_utf8_lossy(&out.stdout).trim().lines().next().unwrap_or_default().to_owned();
|
||||
Regex::new(r"\d+\.\d+(\.\d+-\d+|\.\d+|\b)")
|
||||
.unwrap()
|
||||
.find(&line)
|
||||
.map(|m| m.as_str().to_owned())
|
||||
.unwrap_or(line)
|
||||
if name.as_ref() == "ya" {
|
||||
line.trim_start_matches("Ya ").to_owned()
|
||||
} else {
|
||||
Regex::new(r"\d+\.\d+(\.\d+-\d+|\.\d+|\b)")
|
||||
.unwrap()
|
||||
.find(&line)
|
||||
.map(|m| m.as_str().to_owned())
|
||||
.unwrap_or(line)
|
||||
}
|
||||
}
|
||||
Ok(out) => format!("{:?}, {:?}", out.status, String::from_utf8_lossy(&out.stderr)),
|
||||
Err(e) => format!("{e}"),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use yazi_boot::BOOT;
|
||||
use yazi_dds::Pubsub;
|
||||
use yazi_proxy::ManagerProxy;
|
||||
use yazi_shared::fs::Url;
|
||||
|
||||
|
|
@ -47,7 +48,7 @@ impl Tabs {
|
|||
return;
|
||||
}
|
||||
|
||||
// Reset the preview of the previous active tab
|
||||
// Reset the preview of the last active tab
|
||||
if let Some(active) = self.items.get_mut(self.cursor) {
|
||||
active.preview.reset_image();
|
||||
}
|
||||
|
|
@ -55,6 +56,7 @@ impl Tabs {
|
|||
self.cursor = idx;
|
||||
ManagerProxy::refresh();
|
||||
ManagerProxy::peek(true);
|
||||
Pubsub::pub_from_tab(idx);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use anyhow::{bail, Result};
|
|||
use mlua::{ExternalResult, IntoLua, Lua, Value};
|
||||
use serde::Serialize;
|
||||
|
||||
use super::{BodyBulk, BodyBye, BodyCd, BodyCustom, BodyDelete, BodyHey, BodyHi, BodyHover, BodyMove, BodyRename, BodyTrash, BodyYank};
|
||||
use super::{BodyBulk, BodyBye, BodyCd, BodyCustom, BodyDelete, BodyHey, BodyHi, BodyHover, BodyMove, BodyRename, BodyTab, BodyTrash, BodyYank};
|
||||
use crate::Payload;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
|
|
@ -13,6 +13,7 @@ pub enum Body<'a> {
|
|||
Bye(BodyBye),
|
||||
Cd(BodyCd<'a>),
|
||||
Hover(BodyHover<'a>),
|
||||
Tab(BodyTab),
|
||||
Rename(BodyRename<'a>),
|
||||
Bulk(BodyBulk<'a>),
|
||||
Yank(BodyYank<'a>),
|
||||
|
|
@ -30,6 +31,7 @@ impl Body<'static> {
|
|||
"bye" => Self::Bye(serde_json::from_str(body)?),
|
||||
"cd" => Self::Cd(serde_json::from_str(body)?),
|
||||
"hover" => Self::Hover(serde_json::from_str(body)?),
|
||||
"tab" => Self::Tab(serde_json::from_str(body)?),
|
||||
"rename" => Self::Rename(serde_json::from_str(body)?),
|
||||
"bulk" => Self::Bulk(serde_json::from_str(body)?),
|
||||
"@yank" => Self::Yank(serde_json::from_str(body)?),
|
||||
|
|
@ -53,6 +55,7 @@ impl Body<'static> {
|
|||
| "bye"
|
||||
| "cd"
|
||||
| "hover"
|
||||
| "tab"
|
||||
| "rename"
|
||||
| "bulk"
|
||||
| "@yank"
|
||||
|
|
@ -84,6 +87,7 @@ impl<'a> Body<'a> {
|
|||
Self::Bye(_) => "bye",
|
||||
Self::Cd(_) => "cd",
|
||||
Self::Hover(_) => "hover",
|
||||
Self::Tab(_) => "tab",
|
||||
Self::Rename(_) => "rename",
|
||||
Self::Bulk(_) => "bulk",
|
||||
Self::Yank(_) => "@yank",
|
||||
|
|
@ -111,6 +115,7 @@ impl IntoLua<'_> for Body<'static> {
|
|||
Self::Bye(b) => b.into_lua(lua),
|
||||
Self::Cd(b) => b.into_lua(lua),
|
||||
Self::Hover(b) => b.into_lua(lua),
|
||||
Self::Tab(b) => b.into_lua(lua),
|
||||
Self::Rename(b) => b.into_lua(lua),
|
||||
Self::Bulk(b) => b.into_lua(lua),
|
||||
Self::Yank(b) => b.into_lua(lua),
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ mod hi;
|
|||
mod hover;
|
||||
mod move_;
|
||||
mod rename;
|
||||
mod tab;
|
||||
mod trash;
|
||||
mod yank;
|
||||
|
||||
|
|
@ -25,5 +26,6 @@ pub use hi::*;
|
|||
pub use hover::*;
|
||||
pub use move_::*;
|
||||
pub use rename::*;
|
||||
pub use tab::*;
|
||||
pub use trash::*;
|
||||
pub use yank::*;
|
||||
|
|
|
|||
24
yazi-dds/src/body/tab.rs
Normal file
24
yazi-dds/src/body/tab.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
use mlua::{IntoLua, Lua, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::Body;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct BodyTab {
|
||||
pub idx: usize,
|
||||
}
|
||||
|
||||
impl BodyTab {
|
||||
#[inline]
|
||||
pub fn owned(idx: usize) -> Body<'static> { Self { idx }.into() }
|
||||
}
|
||||
|
||||
impl<'a> From<BodyTab> for Body<'a> {
|
||||
fn from(value: BodyTab) -> Self { Self::Tab(value) }
|
||||
}
|
||||
|
||||
impl IntoLua<'_> for BodyTab {
|
||||
fn into_lua(self, lua: &Lua) -> mlua::Result<Value> {
|
||||
lua.create_table_from([("idx", self.idx)])?.into_lua(lua)
|
||||
}
|
||||
}
|
||||
|
|
@ -82,6 +82,7 @@ impl Display for Payload<'_> {
|
|||
Body::Bye(b) => serde_json::to_string(b),
|
||||
Body::Cd(b) => serde_json::to_string(b),
|
||||
Body::Hover(b) => serde_json::to_string(b),
|
||||
Body::Tab(b) => serde_json::to_string(b),
|
||||
Body::Rename(b) => serde_json::to_string(b),
|
||||
Body::Bulk(b) => serde_json::to_string(b),
|
||||
Body::Yank(b) => serde_json::to_string(b),
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use parking_lot::RwLock;
|
|||
use yazi_boot::BOOT;
|
||||
use yazi_shared::{fs::Url, RoCell};
|
||||
|
||||
use crate::{body::{Body, BodyBulk, BodyCd, BodyDelete, BodyHi, BodyHover, BodyMove, BodyMoveItem, BodyRename, BodyTrash, BodyYank}, Client, ID, PEERS};
|
||||
use crate::{body::{Body, BodyBulk, BodyCd, BodyDelete, BodyHi, BodyHover, BodyMove, BodyMoveItem, BodyRename, BodyTab, BodyTrash, BodyYank}, Client, ID, PEERS};
|
||||
|
||||
pub static LOCAL: RoCell<RwLock<HashMap<String, HashMap<String, Function<'static>>>>> =
|
||||
RoCell::new();
|
||||
|
|
@ -112,6 +112,18 @@ impl Pubsub {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn pub_from_tab(idx: usize) {
|
||||
if LOCAL.read().contains_key("tab") {
|
||||
Self::pub_(BodyTab::owned(idx));
|
||||
}
|
||||
if PEERS.read().values().any(|p| p.able("tab")) {
|
||||
Client::push(BodyTab::owned(idx));
|
||||
}
|
||||
if BOOT.local_events.contains("tab") {
|
||||
BodyTab::owned(idx).with_receiver(*ID).flush();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pub_from_rename(tab: usize, from: &Url, to: &Url) {
|
||||
if LOCAL.read().contains_key("rename") {
|
||||
Self::pub_(BodyRename::dummy(tab, from, to));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue