Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add process ID to terminal tab tooltips #21955

Merged
merged 21 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
17 changes: 16 additions & 1 deletion crates/terminal/src/pty_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use windows::Win32::{Foundation::HANDLE, System::Threading::GetProcessId};

use sysinfo::{Pid, Process, ProcessRefreshKind, RefreshKind, System, UpdateKind};

struct ProcessIdGetter {
pub struct ProcessIdGetter {
handle: i32,
fallback_pid: u32,
}
Expand All @@ -31,6 +31,11 @@ impl ProcessIdGetter {
}
Some(Pid::from_u32(pid as u32))
}

// Add a getter for the `fallback_pid` field
Angelk90 marked this conversation as resolved.
Show resolved Hide resolved
pub fn fallback_pid(&self) -> u32 {
self.fallback_pid
}
}

#[cfg(windows)]
Expand Down Expand Up @@ -62,6 +67,11 @@ impl ProcessIdGetter {
}
Some(Pid::from_u32(pid))
}

// Add a getter for the `fallback_pid` field
pub fn fallback_pid(&self) -> u32 {
self.fallback_pid
}
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -142,4 +152,9 @@ impl PtyProcessInfo {
}
has_changed
}

// Getter for `pid_getter`
pub fn get_pid_getter(&self) -> &ProcessIdGetter {
&self.pid_getter
}
}
23 changes: 21 additions & 2 deletions crates/terminal_view/src/terminal_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,8 +1027,27 @@ impl Item for TerminalView {
type Event = ItemEvent;

fn tab_tooltip_text(&self, cx: &AppContext) -> Option<SharedString> {
Some(self.terminal().read(cx).title(false).into())
}
let terminal = self.terminal().read(cx);
let title = terminal.title(false);

let pid_getter = terminal.pty_info.get_pid_getter();
let pid_text = pid_getter.fallback_pid();

let pid_info = if pid_text != 0 {
format!("Process ID (PID): {}", pid_text)
} else {
String::from("No Process ID available")
};

let tooltip_text = format!(
"{}\n{}\n{}",
title,
"-".repeat(30),
pid_info
);

Some(tooltip_text.into())
}

fn tab_content(&self, params: TabContentParams, cx: &WindowContext) -> AnyElement {
let terminal = self.terminal().read(cx);
Expand Down