This commit is contained in:
sxyazi 2024-08-15 21:29:03 +08:00
parent 4ad1479217
commit 1ba7c60a01
No known key found for this signature in database
7 changed files with 42 additions and 44 deletions

View file

@ -44,9 +44,9 @@ impl Actions {
writeln!(s, "\nVariables")?; writeln!(s, "\nVariables")?;
writeln!(s, " SHELL : {:?}", env::var_os("SHELL"))?; writeln!(s, " SHELL : {:?}", env::var_os("SHELL"))?;
writeln!(s, " EDITOR : {:?}", env::var_os("EDITOR"))?; 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_FILE_ONE : {:?}", env::var_os("YAZI_FILE_ONE"))?;
writeln!(s, " YAZI_CONFIG_HOME : {:?}", env::var_os("YAZI_CONFIG_HOME"))?; 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!(s, "\nText Opener")?;
writeln!( writeln!(
@ -56,9 +56,11 @@ impl Actions {
)?; )?;
writeln!(s, " block : {:?}", yazi_config::OPEN.block_opener("bulk.txt", "text/plain"))?; writeln!(s, " block : {:?}", yazi_config::OPEN.block_opener("bulk.txt", "text/plain"))?;
writeln!(s, "\ntmux")?; writeln!(s, "\nMultiplexers")?;
writeln!(s, " TMUX : {:?}", *yazi_adapter::TMUX)?; writeln!(s, " TMUX : {:?}", *yazi_adapter::TMUX)?;
writeln!(s, " Version: {}", Self::process_output("tmux", "-V"))?; 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!(s, "\nDependencies")?;
writeln!( writeln!(
@ -89,15 +91,19 @@ impl Actions {
} }
fn process_output(name: impl AsRef<OsStr>, arg: impl AsRef<OsStr>) -> String { 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() => { Ok(out) if out.status.success() => {
let line = let line =
String::from_utf8_lossy(&out.stdout).trim().lines().next().unwrap_or_default().to_owned(); String::from_utf8_lossy(&out.stdout).trim().lines().next().unwrap_or_default().to_owned();
Regex::new(r"\d+\.\d+(\.\d+-\d+|\.\d+|\b)") if name.as_ref() == "ya" {
.unwrap() line.trim_start_matches("Ya ").to_owned()
.find(&line) } else {
.map(|m| m.as_str().to_owned()) Regex::new(r"\d+\.\d+(\.\d+-\d+|\.\d+|\b)")
.unwrap_or(line) .unwrap()
.find(&line)
.map(|m| m.as_str().to_owned())
.unwrap_or(line)
}
} }
Ok(out) => format!("{:?}, {:?}", out.status, String::from_utf8_lossy(&out.stderr)), Ok(out) => format!("{:?}, {:?}", out.status, String::from_utf8_lossy(&out.stderr)),
Err(e) => format!("{e}"), Err(e) => format!("{e}"),

View file

@ -1,4 +1,3 @@
use yazi_dds::Pubsub;
use yazi_shared::{event::{Cmd, Data}, render}; use yazi_shared::{event::{Cmd, Data}, render};
use crate::manager::Tabs; use crate::manager::Tabs;
@ -29,8 +28,5 @@ impl Tabs {
self.set_idx(idx); self.set_idx(idx);
render!(); render!();
// Publish through DDS
Pubsub::pub_from_tab_switch(self.active().idx);
} }
} }

View file

@ -1,6 +1,7 @@
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use yazi_boot::BOOT; use yazi_boot::BOOT;
use yazi_dds::Pubsub;
use yazi_proxy::ManagerProxy; use yazi_proxy::ManagerProxy;
use yazi_shared::fs::Url; use yazi_shared::fs::Url;
@ -47,7 +48,7 @@ impl Tabs {
return; 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) { if let Some(active) = self.items.get_mut(self.cursor) {
active.preview.reset_image(); active.preview.reset_image();
} }
@ -55,6 +56,7 @@ impl Tabs {
self.cursor = idx; self.cursor = idx;
ManagerProxy::refresh(); ManagerProxy::refresh();
ManagerProxy::peek(true); ManagerProxy::peek(true);
Pubsub::pub_from_tab(idx);
} }
} }

View file

@ -2,7 +2,7 @@ use anyhow::{bail, Result};
use mlua::{ExternalResult, IntoLua, Lua, Value}; use mlua::{ExternalResult, IntoLua, Lua, Value};
use serde::Serialize; use serde::Serialize;
use super::{BodyBulk, BodyBye, BodyCd, BodyCustom, BodyDelete, BodyHey, BodyHi, BodyHover, BodyMove, BodyRename, BodyTabSwitch, BodyTrash, BodyYank}; use super::{BodyBulk, BodyBye, BodyCd, BodyCustom, BodyDelete, BodyHey, BodyHi, BodyHover, BodyMove, BodyRename, BodyTab, BodyTrash, BodyYank};
use crate::Payload; use crate::Payload;
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
@ -13,7 +13,7 @@ pub enum Body<'a> {
Bye(BodyBye), Bye(BodyBye),
Cd(BodyCd<'a>), Cd(BodyCd<'a>),
Hover(BodyHover<'a>), Hover(BodyHover<'a>),
TabSwitch(BodyTabSwitch), Tab(BodyTab),
Rename(BodyRename<'a>), Rename(BodyRename<'a>),
Bulk(BodyBulk<'a>), Bulk(BodyBulk<'a>),
Yank(BodyYank<'a>), Yank(BodyYank<'a>),
@ -31,7 +31,7 @@ impl Body<'static> {
"bye" => Self::Bye(serde_json::from_str(body)?), "bye" => Self::Bye(serde_json::from_str(body)?),
"cd" => Self::Cd(serde_json::from_str(body)?), "cd" => Self::Cd(serde_json::from_str(body)?),
"hover" => Self::Hover(serde_json::from_str(body)?), "hover" => Self::Hover(serde_json::from_str(body)?),
"tab-switch" => Self::TabSwitch(serde_json::from_str(body)?), "tab" => Self::Tab(serde_json::from_str(body)?),
"rename" => Self::Rename(serde_json::from_str(body)?), "rename" => Self::Rename(serde_json::from_str(body)?),
"bulk" => Self::Bulk(serde_json::from_str(body)?), "bulk" => Self::Bulk(serde_json::from_str(body)?),
"@yank" => Self::Yank(serde_json::from_str(body)?), "@yank" => Self::Yank(serde_json::from_str(body)?),
@ -55,7 +55,7 @@ impl Body<'static> {
| "bye" | "bye"
| "cd" | "cd"
| "hover" | "hover"
| "tab-switch" | "tab"
| "rename" | "rename"
| "bulk" | "bulk"
| "@yank" | "@yank"
@ -87,7 +87,7 @@ impl<'a> Body<'a> {
Self::Bye(_) => "bye", Self::Bye(_) => "bye",
Self::Cd(_) => "cd", Self::Cd(_) => "cd",
Self::Hover(_) => "hover", Self::Hover(_) => "hover",
Self::TabSwitch(_) => "tab-switch", Self::Tab(_) => "tab",
Self::Rename(_) => "rename", Self::Rename(_) => "rename",
Self::Bulk(_) => "bulk", Self::Bulk(_) => "bulk",
Self::Yank(_) => "@yank", Self::Yank(_) => "@yank",
@ -115,7 +115,7 @@ impl IntoLua<'_> for Body<'static> {
Self::Bye(b) => b.into_lua(lua), Self::Bye(b) => b.into_lua(lua),
Self::Cd(b) => b.into_lua(lua), Self::Cd(b) => b.into_lua(lua),
Self::Hover(b) => b.into_lua(lua), Self::Hover(b) => b.into_lua(lua),
Self::TabSwitch(b) => b.into_lua(lua), Self::Tab(b) => b.into_lua(lua),
Self::Rename(b) => b.into_lua(lua), Self::Rename(b) => b.into_lua(lua),
Self::Bulk(b) => b.into_lua(lua), Self::Bulk(b) => b.into_lua(lua),
Self::Yank(b) => b.into_lua(lua), Self::Yank(b) => b.into_lua(lua),

View file

@ -4,27 +4,21 @@ use serde::{Deserialize, Serialize};
use super::Body; use super::Body;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct BodyTabSwitch { pub struct BodyTab {
/// The index of the tab pub idx: usize,
pub tab: usize,
} }
impl<'a> BodyTabSwitch { impl BodyTab {
#[inline] #[inline]
pub fn borrowed(tab: usize) -> Body<'a> { Self { tab }.into() } pub fn owned(idx: usize) -> Body<'static> { Self { idx }.into() }
} }
impl BodyTabSwitch { impl<'a> From<BodyTab> for Body<'a> {
#[inline] fn from(value: BodyTab) -> Self { Self::Tab(value) }
pub fn dummy(tab: usize) -> Body<'static> { Self { tab }.into() }
} }
impl<'a> From<BodyTabSwitch> for Body<'a> { impl IntoLua<'_> for BodyTab {
fn from(value: BodyTabSwitch) -> Self { Self::TabSwitch(value) }
}
impl IntoLua<'_> for BodyTabSwitch {
fn into_lua(self, lua: &Lua) -> mlua::Result<Value> { fn into_lua(self, lua: &Lua) -> mlua::Result<Value> {
lua.create_table_from([("tab", self.tab)])?.into_lua(lua) lua.create_table_from([("idx", self.idx)])?.into_lua(lua)
} }
} }

View file

@ -82,7 +82,7 @@ impl Display for Payload<'_> {
Body::Bye(b) => serde_json::to_string(b), Body::Bye(b) => serde_json::to_string(b),
Body::Cd(b) => serde_json::to_string(b), Body::Cd(b) => serde_json::to_string(b),
Body::Hover(b) => serde_json::to_string(b), Body::Hover(b) => serde_json::to_string(b),
Body::TabSwitch(b) => serde_json::to_string(b), Body::Tab(b) => serde_json::to_string(b),
Body::Rename(b) => serde_json::to_string(b), Body::Rename(b) => serde_json::to_string(b),
Body::Bulk(b) => serde_json::to_string(b), Body::Bulk(b) => serde_json::to_string(b),
Body::Yank(b) => serde_json::to_string(b), Body::Yank(b) => serde_json::to_string(b),

View file

@ -5,7 +5,7 @@ use parking_lot::RwLock;
use yazi_boot::BOOT; use yazi_boot::BOOT;
use yazi_shared::{fs::Url, RoCell}; use yazi_shared::{fs::Url, RoCell};
use crate::{body::{Body, BodyBulk, BodyCd, BodyDelete, BodyHi, BodyHover, BodyMove, BodyMoveItem, BodyRename, BodyTabSwitch, 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>>>>> = pub static LOCAL: RoCell<RwLock<HashMap<String, HashMap<String, Function<'static>>>>> =
RoCell::new(); RoCell::new();
@ -112,15 +112,15 @@ impl Pubsub {
} }
} }
pub fn pub_from_tab_switch(tab: usize) { pub fn pub_from_tab(idx: usize) {
if LOCAL.read().contains_key("tab-switch") { if LOCAL.read().contains_key("tab") {
Self::pub_(BodyTabSwitch::dummy(tab)); Self::pub_(BodyTab::owned(idx));
} }
if PEERS.read().values().any(|p| p.able("tab-switch")) { if PEERS.read().values().any(|p| p.able("tab")) {
Client::push(BodyTabSwitch::borrowed(tab)); Client::push(BodyTab::owned(idx));
} }
if BOOT.local_events.contains("tab-switch") { if BOOT.local_events.contains("tab") {
BodyTabSwitch::borrowed(tab).with_receiver(*ID).flush(); BodyTab::owned(idx).with_receiver(*ID).flush();
} }
} }