mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: log tmux call execution time to logs
This commit is contained in:
parent
68cd02816d
commit
821296f5ac
4 changed files with 44 additions and 14 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use tracing::warn;
|
use tracing::debug;
|
||||||
use yazi_shared::env_exists;
|
use yazi_shared::env_exists;
|
||||||
|
|
||||||
use crate::Mux;
|
use crate::Mux;
|
||||||
|
|
@ -63,7 +63,7 @@ impl Brand {
|
||||||
"xterm-ghostty" => return Some(B::Ghostty),
|
"xterm-ghostty" => return Some(B::Ghostty),
|
||||||
"rio" => return Some(B::Rio),
|
"rio" => return Some(B::Rio),
|
||||||
"rxvt-unicode-256color" => return Some(B::Urxvt),
|
"rxvt-unicode-256color" => return Some(B::Urxvt),
|
||||||
_ => warn!("[Adapter] Unknown TERM: {term}"),
|
_ => {}
|
||||||
}
|
}
|
||||||
match program.as_str() {
|
match program.as_str() {
|
||||||
"iTerm.app" => return Some(B::Iterm2),
|
"iTerm.app" => return Some(B::Iterm2),
|
||||||
|
|
@ -76,11 +76,11 @@ impl Brand {
|
||||||
"Hyper" => return Some(B::Hyper),
|
"Hyper" => return Some(B::Hyper),
|
||||||
"mintty" => return Some(B::Mintty),
|
"mintty" => return Some(B::Mintty),
|
||||||
"Apple_Terminal" => return Some(B::Apple),
|
"Apple_Terminal" => return Some(B::Apple),
|
||||||
_ => warn!("[Adapter] Unknown TERM_PROGRAM: {program}"),
|
_ => {}
|
||||||
}
|
}
|
||||||
match vars.into_iter().find(|&(s, _)| env_exists(s)) {
|
if let Some((var, brand)) = vars.into_iter().find(|&(s, _)| env_exists(s)) {
|
||||||
Some((_, brand)) => return Some(brand),
|
debug!("Detected special environment variable: {var}");
|
||||||
None => warn!("[Adapter] No special environment variables detected"),
|
return Some(brand);
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
use yazi_macro::time;
|
||||||
|
|
||||||
use crate::{CLOSE, ESCAPE, Emulator, START, TMUX};
|
use crate::{CLOSE, ESCAPE, Emulator, START, TMUX};
|
||||||
|
|
||||||
|
|
@ -18,14 +19,18 @@ impl Mux {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tmux_passthrough() {
|
pub fn tmux_passthrough() {
|
||||||
let child = std::process::Command::new("tmux")
|
let output = time!(
|
||||||
|
"Running `tmux set -p allow-passthrough on`",
|
||||||
|
std::process::Command::new("tmux")
|
||||||
.args(["set", "-p", "allow-passthrough", "on"])
|
.args(["set", "-p", "allow-passthrough", "on"])
|
||||||
.stdin(std::process::Stdio::null())
|
.stdin(std::process::Stdio::null())
|
||||||
.stdout(std::process::Stdio::null())
|
.stdout(std::process::Stdio::null())
|
||||||
.stderr(std::process::Stdio::piped())
|
.stderr(std::process::Stdio::piped())
|
||||||
.spawn();
|
.spawn()
|
||||||
|
.and_then(|c| c.wait_with_output())
|
||||||
|
);
|
||||||
|
|
||||||
match child.and_then(|c| c.wait_with_output()) {
|
match output {
|
||||||
Ok(o) if o.status.success() => {}
|
Ok(o) if o.status.success() => {}
|
||||||
Ok(o) => {
|
Ok(o) => {
|
||||||
error!(
|
error!(
|
||||||
|
|
@ -68,9 +73,14 @@ impl Mux {
|
||||||
if !TMUX.get() {
|
if !TMUX.get() {
|
||||||
return (term, program);
|
return (term, program);
|
||||||
}
|
}
|
||||||
let Ok(output) = std::process::Command::new("tmux").arg("show-environment").output() else {
|
|
||||||
|
let Ok(output) = time!(
|
||||||
|
"Running `tmux show-environment`",
|
||||||
|
std::process::Command::new("tmux").arg("show-environment").output()
|
||||||
|
) else {
|
||||||
return (term, program);
|
return (term, program);
|
||||||
};
|
};
|
||||||
|
|
||||||
for line in String::from_utf8_lossy(&output.stdout).lines() {
|
for line in String::from_utf8_lossy(&output.stdout).lines() {
|
||||||
if let Some((k, v)) = line.trim().split_once('=') {
|
if let Some((k, v)) = line.trim().split_once('=') {
|
||||||
match k {
|
match k {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
mod asset;
|
mod asset;
|
||||||
mod event;
|
mod event;
|
||||||
|
mod log;
|
||||||
mod module;
|
mod module;
|
||||||
mod platform;
|
mod platform;
|
||||||
mod stdio;
|
mod stdio;
|
||||||
|
|
|
||||||
19
yazi-macro/src/log.rs
Normal file
19
yazi-macro/src/log.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! time {
|
||||||
|
($expr:expr) => {
|
||||||
|
time!($expr, stringify!($expr))
|
||||||
|
};
|
||||||
|
($label:expr, $expr:expr) => {
|
||||||
|
time!($expr, "{}", $label)
|
||||||
|
};
|
||||||
|
($expr:expr, $fmt:expr, $($args:tt)*) => {{
|
||||||
|
if tracing::enabled!(tracing::Level::DEBUG) {
|
||||||
|
let start = std::time::Instant::now();
|
||||||
|
let result = $expr;
|
||||||
|
tracing::debug!("{} took {:?}", format_args!($fmt, $($args)*), start.elapsed());
|
||||||
|
result
|
||||||
|
} else {
|
||||||
|
$expr
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue