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

Conversation

Angelk90
Copy link
Contributor

@Angelk90 Angelk90 commented Dec 13, 2024

Closes #12807

Before After
Screenshot 2025-01-09 at 2 14 15 PM Screenshot 2025-01-09 at 2 13 34 PM

Release Notes:

  • Added the process ID (PID) to terminal tab tooltips.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Dec 13, 2024
@Angelk90
Copy link
Contributor Author

@danilo-leal : Do you think it is possible to create a customizable tooltip to be used for the terminal tab and not only, like the one you created for git blame #17517?

With the fields title, details where the details would be an array, for each detail a separation is made, the final part customizable.

Screenshot 2024-12-13 alle 13 03 34

image

@maxdeviant maxdeviant changed the title Tooltip terminal tabs show the Process ID Add process ID to terminal tab tooltips Dec 13, 2024
@Angelk90
Copy link
Contributor Author

@danilo-leal , @maxdeviant : I was thinking of using a similar code to create a custom tooltip but I don't know how I can use it inside :

File:
crates/terminal_view/src/terminal_view.rs

Code:

fn tab_tooltip_text(&self, cx: &AppContext) -> Option<SharedString> {
...
}

Use:

let details = Details {
            details: vec![
                vec![
                    "Process ID (PID): 3000".to_string(),
                    "Command line: /bin/zsh '-il'".to_string(),
                ],
                vec![
                    "Shell integration activated".to_string(),
                ],
                vec![
                    "The following extensions have contributed to this terminal's environment:".to_string(),
                    "JavaScript Debugger: Enables Node.js auto attach debugging in \"onlyWithFlag\" mode".to_string(),
                    "Git: Enables the following features: git auth provider".to_string(),
                ],
            ],
        };
    
let entry_tooltip = create_entry_tooltip(Some("Tooltip Title".to_string()), Some(details));

/crates/editor/src/entry_tooltip.rs

use gpui::{
    ParentElement, Render, ScrollHandle,
    StatefulInteractiveElement,
};
use ui::{prelude::*, tooltip_container};
pub struct Details {
    pub details: Vec<Vec<String>>,
}
pub struct EntryTooltip {
    title: Option<String>,
    details: Option<Details>,
    scroll_handle: ScrollHandle,
}

impl EntryTooltip {
    pub fn new(
        title: Option<String>,
        details: Option<Details>,
    ) -> Self {
        Self {
            title,
            details,
            scroll_handle: ScrollHandle::new(),
        }
    }
}

pub fn create_entry_tooltip(
    title: Option<String>,
    details: Option<Details>,
) -> EntryTooltip {
    EntryTooltip::new(title, details)
}

impl Render for EntryTooltip {
    fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
        let title = self
            .title
            .clone()
            .unwrap_or_else(|| "<no title>".to_string());

        let message = self.details.as_ref().map_or(vec![], |details| {
            details.details.iter().flat_map(|section| {
                section.iter().map(|line| {
                    div()
                        .child(line.clone())
                        .py_1()
                }).collect::<Vec<_>>()
            }).collect::<Vec<_>>()
        });

        let message_element = v_flex().children(message);

        tooltip_container(cx, move |this, cx| {
            this.occlude()
                .on_mouse_move(|_, cx| cx.stop_propagation())
                .child(
                    v_flex()
                        .w(gpui::rems(30.))
                        .gap_4()
                        .child(
                            h_flex()
                                .pb_1p5()
                                .gap_x_2()
                                .overflow_x_hidden()
                                .flex_wrap()
                                .child(title)
                                .border_b_1()
                                .border_color(cx.theme().colors().border_variant),
                        )
                        .child(
                            div()
                                .id("inline-message")
                                .occlude()
                                .child(message_element)
                                .overflow_y_scroll()
                                .track_scroll(&self.scroll_handle),
                        )
                )
        })
    }
}

@Angelk90
Copy link
Contributor Author

@danilo-leal , @maxdeviant : I was thinking of using a tooltip, obviously with the right information to show this is a test of the tooltip, what do you think?

Screenshot 2024-12-14 alle 22 16 50

@Angelk90
Copy link
Contributor Author

@maxdeviant : Are there any changes to be made?

@danilo-leal
Copy link
Contributor

Hey @Angelk90! Thanks for the PR! Just to understand, this last screenshot you sent is something you haven't committed yet? Meaning, the creation of a custom tooltip for this terminal use case. I think it makes sense. We have more autonomy with the design that way, rather than using - for dividers and whatnot!

@Angelk90
Copy link
Contributor Author

Angelk90 commented Jan 7, 2025

@danilo-leal : It's currently like this:
image

I wanted to create a custom tooltip, but I don't know how to use it inside the terminal.
can you help me, you can modify the code as you want.

@danilo-leal
Copy link
Contributor

Quick status update here as I do have working code for this, but it involved adding a new method (tab_tooltip_content) to the Item trait, which feels worth its separate/standalone PR. Will try to break it up before continuing with the terminal-specific content over here.

Screenshot 2025-01-07 at 11 41 12 PM

@Angelk90
Copy link
Contributor Author

Angelk90 commented Jan 8, 2025

@danilo-leal : Great, the idea of ​​the tooltip is that it could be used in different places.

The idea of ​​the tooltip that I had in mind was to divide it into three parts:

  1. Title
  2. Body of the message, which would be an array of text arrays, in this text there could be code that could be of markdown type for example use of `.
    For each element of the array have a separation.
  3. Final part, could contain buttons or informational messages

See image below:
Screenshot 2025-01-08 alle 09 21 49

github-merge-queue bot pushed a commit that referenced this pull request Jan 9, 2025
This PR is an alternate version of
#22850, but now using a
similar approach to the existing `tab_content` and `tab_content_text`,
where `tab_tooltip_content` refers to the existing `tab_tooltip_text` if
there's no custom tooltip content/trait defined, meaning it will
simplify render the text/string content in this case.

This is all motivated by
#21955, as we want to pull off
the ability to add custom content to a terminal tab tooltip.

Release Notes:

- N/A
@Angelk90
Copy link
Contributor Author

Angelk90 commented Jan 9, 2025

@danilo-leal : I sent you a private message on Discord.

@danilo-leal danilo-leal added this pull request to the merge queue Jan 9, 2025
Merged via the queue into zed-industries:main with commit 35d3d29 Jan 9, 2025
14 checks passed
@Angelk90 Angelk90 deleted the terminal-pid branch January 9, 2025 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Terminal tab tooltip with PID for process
3 participants