Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
# copy_target_env = "e"
# copy_target_env_diff = "d"
# copy_target_argv = "a"
# copy_target_argv_joined = "w"
# copy_target_filename = "n"
# copy_target_syscall_result = "r"
# copy_target_line = "l"
Expand Down
12 changes: 12 additions & 0 deletions crates/tracexec-core/src/cli/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ pub struct TuiKeyBindingsConfig {
pub copy_target_env: Option<KeyList>,
pub copy_target_env_diff: Option<KeyList>,
pub copy_target_argv: Option<KeyList>,
pub copy_target_argv_joined: Option<KeyList>,
pub copy_target_filename: Option<KeyList>,
pub copy_target_syscall_result: Option<KeyList>,
pub copy_target_line: Option<KeyList>,
Expand Down Expand Up @@ -322,6 +323,7 @@ pub struct TuiKeyBindings {
pub copy_target_env: KeyList,
pub copy_target_env_diff: KeyList,
pub copy_target_argv: KeyList,
pub copy_target_argv_joined: KeyList,
pub copy_target_filename: KeyList,
pub copy_target_syscall_result: KeyList,
pub copy_target_line: KeyList,
Expand Down Expand Up @@ -426,6 +428,7 @@ impl Default for TuiKeyBindings {
copy_target_env: KeyList(vec![KeyBinding::char('e')]),
copy_target_env_diff: KeyList(vec![KeyBinding::char('d')]),
copy_target_argv: KeyList(vec![KeyBinding::char('a')]),
copy_target_argv_joined: KeyList(vec![KeyBinding::char('w')]),
copy_target_filename: KeyList(vec![KeyBinding::char('n')]),
copy_target_syscall_result: KeyList(vec![KeyBinding::char('r')]),
copy_target_line: KeyList(vec![KeyBinding::char('l')]),
Expand Down Expand Up @@ -548,6 +551,7 @@ impl TuiKeyBindings {
copy_target_env,
copy_target_env_diff,
copy_target_argv,
copy_target_argv_joined,
copy_target_filename,
copy_target_syscall_result,
copy_target_line,
Expand Down Expand Up @@ -800,4 +804,12 @@ mod tests {
.keys;
assert_eq!(list.0.len(), 2);
}

#[test]
fn test_configure_whitespace_joined_argv_copy_target() {
let config: TuiKeyBindingsConfig = toml::from_str(r#"copy_target_argv_joined = "x""#).unwrap();
let keys = TuiKeyBindings::from_config(Some(Box::new(config)));

assert_eq!(keys.copy_target_argv_joined.0, vec![KeyBinding::char('x')]);
}
}
5 changes: 5 additions & 0 deletions crates/tracexec-core/src/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub enum CopyTarget {
CommandlineWithFds(SupportedShell),
Env,
Argv,
ArgvJoined,
Filename,
SyscallResult,
EnvDiff,
Expand Down Expand Up @@ -371,6 +372,10 @@ pub fn text_for_copy<'a>(
result.into()
}
CopyTarget::Argv => TracerEventDetails::argv_to_string(&event.argv).into(),
CopyTarget::ArgvJoined => match event.argv.as_ref() {
Ok(argv) => argv.iter().map(AsRef::as_ref).join(" ").into(),
Err(_) => "[failed to read argv]".into(),
},
CopyTarget::Filename => Cow::Borrowed(event.filename.as_ref()),
CopyTarget::SyscallResult => event.result.to_string().into(),
CopyTarget::Line => panic!("CopyTarget::Line requires a presentation formatter"),
Expand Down
7 changes: 7 additions & 0 deletions crates/tracexec-tui/src/copy_popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ const COPY_TARGETS: &[CopyTargetConfig] = &[
list_label: "(A)rguments",
help_label: "Argv",
},
CopyTargetConfig {
target: CopyTarget::ArgvJoined,
default_key: 'w',
list_label: "Arguments joined by (W)hitespace",
help_label: "Whitespace-joined argv",
},
CopyTargetConfig {
target: CopyTarget::Filename,
default_key: 'n',
Expand Down Expand Up @@ -245,6 +251,7 @@ fn copy_target_binding(
CopyTarget::Env => &keys.copy_target_env,
CopyTarget::EnvDiff => &keys.copy_target_env_diff,
CopyTarget::Argv => &keys.copy_target_argv,
CopyTarget::ArgvJoined => &keys.copy_target_argv_joined,
CopyTarget::Filename => &keys.copy_target_filename,
CopyTarget::SyscallResult => &keys.copy_target_syscall_result,
CopyTarget::Line => &keys.copy_target_line,
Expand Down
18 changes: 18 additions & 0 deletions crates/tracexec-tui/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,15 @@ mod tests {
)
.contains("hello world")
);
assert_eq!(
event.text_for_copy(
&baseline,
CopyTarget::ArgvJoined,
&modifier,
RuntimeModifier::default()
),
"custom-argv0 hello world"
);
assert_eq!(
event.text_for_copy(
&baseline,
Expand Down Expand Up @@ -726,6 +735,15 @@ mod tests {
)
.contains("failed to read argv")
);
assert_eq!(
failing.text_for_copy(
&baseline,
CopyTarget::ArgvJoined,
&modifier,
RuntimeModifier::default()
),
"[failed to read argv]"
);
assert!(
failing
.text_for_copy(
Expand Down
Loading