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 a clickable button to status bar #3652

Closed
niutech opened this issue Aug 1, 2023 · 22 comments
Closed

Add a clickable button to status bar #3652

niutech opened this issue Aug 1, 2023 · 22 comments

Comments

@niutech
Copy link

niutech commented Aug 1, 2023

How to add a + button to the status bar, which will create a new window on mouse click (provided that the mouse mode is on)? And how to add an X button to each window in the windows list, which will close the window on mouse click?

Thanks!

@MarioRicalde
Copy link

This is an interesting proposal, mostly because you can create custom user experiences that are more accessible. For example, in a mobile environment such as a phone or tablet, you could in theory create a completely tactile experience with an Application such as Termux.

In the aforementioned application, I just touch to navigate between windows in Tmux.

@nicm
Copy link
Member

nicm commented Aug 7, 2023

You could change MouseDown1StatusLeft to create a new window instead of using the right-click menu but you can't add arbitrary buttons.

@nicm nicm closed this as completed Aug 7, 2023
@niutech
Copy link
Author

niutech commented Aug 7, 2023

@nicm I know I can't add buttons now, that's why I filed this issue. Please allow us to do it, probably using a plugin.

@MarioRicalde
Copy link

MarioRicalde commented Aug 9, 2023

@nicm couldn't this be considered a feature request, and something that can be added to https://github.com/tmux/tmux/wiki/Contributing ? There seems to be an instance at least (sixel) where you start with a hard no, and then you soften up to the idea.

Is there another preferred channel to discuss suggestions like this one? I was thinking of having a simpel "+" next to the current Window "tab", to adda a new one ( useful when mouse support is on ).

By the way, as a fun fact: I see #1613 which had some ongoing conversations and was locked, then unlocked by tmux just to be auto locked again.

Shouldn't issues referenced in https://github.com/tmux/tmux/wiki/Contributing remain open for follow-up?

Update: What an interesting read: csdvrx#1

@nicm
Copy link
Member

nicm commented Aug 9, 2023

It could be added to contributing but it isn't much of a feature request. What would it look like in practice? How would the buttons be configured? etc

I did not say no to this in any way.

@MarioRicalde
Copy link

MarioRicalde commented Aug 9, 2023

@nicm thank you for clarifying, to get started here is a suggestion for the "New Window" button, that showing how it looks in unstyled and styled tmux.

In terms of configurations, it could be a declaration inside "status-left", similar to how you can add #S. That would allow to style the background of the clickable element.

window-status-current-format could be used (or equivalent) when pressing the button.

proposals

@niutech
Copy link
Author

niutech commented Aug 11, 2023

@MarioRicalde This is how I'd imagine this, thanks for the mock-up.

@nicm Is it at least possible to get the character under the mouse cursor in the MouseDown1Status event? That way we could check if char == '+' and then open a new window.

@MarioRicalde
Copy link

@nicm is there anything else I can do to help in terms of visuals?

@faustind
Copy link

Clicking + to add a new window could be achieved if mouse_word was available in the status bar. The idea would be to listen to MouseUp1StatusDefault and then add create a new window when mouse_word equals "+".

PR #3641 tries to allow mouse_word in the status bar. I use it to make sessions clickable in the status bar.

@nicm
Copy link
Member

nicm commented Aug 15, 2023

I could imagine how it would look already :-). I need to think about how it would work... I think we should extend the range operator so you can define custom ranges.

@nicm nicm reopened this Aug 15, 2023
@nicm
Copy link
Member

nicm commented Aug 15, 2023

Update: What an interesting read: csdvrx#1

The problem with SIXEL (and to a lesser extent images in general) is that it doesn't always work that well, there aren't that many terminals that support it, and it is a significant amount of work that I don't personally care about very much, so it needs someone who does to move it forward and generate a bit of enthusiasm. So far nobody has taken that on and stuck with it.

If you want to get involved, @topcat001 has been working on it recently and the branch works for simple use cases - see https://github.com/orgs/tmux/discussions/3565. I think if we got a slighly nicer placeholder (even just a box with SIXEL in the middle) it could probably be merged... the other main issues (resize, copy mode) seem a bit annoying, but since I shan't be using it, if they don't annoy people who will use it then maybe they don't matter.

@nicm
Copy link
Member

nicm commented Aug 15, 2023

Please try this: tmux-new-ranges.diff.txt

This adds three new range types: pane, session and user. pane and session work like window except they use the pane or session ID (%0 or $0; window uses the window index in the current session). For user the argument may be any string up to 15 characters.

It also adds two new format variables: mouse_status_line and mouse_status_range. mouse_status_line is the status line on which the mouse event occurred. mouse_status_range is the type of the range (left, right, pane, etc) except for user ranges where it is the argument string.

Here is an example which adds two new status lines, one with a couple of user ranges and one with the sessions:

set -g status 3
set -g status-format[1] '#[range=user|foo]foo#[range=user|bar]bar#[norange]'
set -g status-format[2] '#{S:#[range=session|#{session_id}]#{session_name}#[norange] }'
bind -Troot MouseDown1Status if -F '#{==:#{mouse_status_range},session}' {
        switch-client
} {
        if -F '#{==:#{mouse_status_range},window}' {
                select-window
        } {
                display -d0 '#{mouse_status_line} #{mouse_status_range}'
        }
}

And an example which adds an X to kill a window:

set -g window-status-format '#I:#W#{?window_flags,#{window_flags}, }#[range=user|kill#{window_id}](X)#[norange]'
set -g window-status-current-format '#{E:window-status-format}'
bind -Troot MouseDown1Status if -F '#{==:#{mouse_status_range},window}' {
        select-window
} {
        if -F '#{m/r:^kill,#{mouse_status_range}}' {
                run -C 'kill-window -t#{s/^kill//:mouse_status_range}'
        }
}

Adding a [+] to create a window will be similar; either add it to status-format[0] or to window-status-format with an appropriate check to only display it for the first window.

There are a few bits of further work:

  • These need to be added to tmux.1;

  • I think perhaps to make this easier, we should add a couple of options which appear in the default status-format[0] before and after the window list (status-before-windows and status-after-windows) so it is not necessary to redefine the whole of status-format[0] just to make a small addition in those positions;

  • I would be open to changing the default status-format[1] or [2] to use these (maybe one with sessions and one with some custom buttons?). I don't think we should change the appearance of the default status-format[0].

@faustind please review and test also since this will work instead of your mouse_word change (see first example above).

@topcat001
Copy link
Contributor

I'll merge a small update with a filled in placeholder soon to the sixel branch. The branch is very basic and there is lots to do, but I'm using it for work right now to display graphs. The sixel features are behind a configure flag.

@faustind
Copy link

Thank you @nicm
For the sessions, it works nicer with the ranges than with just mouse_word: I like that I can even click on the style surrounding a session and it will work as my intuition expects.

Screen.Recording.2023-08-17.at.22.52.25.mov

@nicm
Copy link
Member

nicm commented Aug 17, 2023

Great, this has been working for me also, so I have applied it now. It will be in GitHub later on when it syncs. Let me know if you see any problems. Thanks!

@niutech
Copy link
Author

niutech commented Aug 20, 2023

Thanks @nicm! I've appended [+] to the window list like this:

set -g window-status-format '#W#{?window_end_flag,#[range=user|new][+]#[norange],}'
bind -Troot MouseDown1Status if -F '#{==:#{mouse_status_range},window}' {
    select-window
} {
    if -F '#{==:#{mouse_status_range},new}' {
        new-window
    }
}

UPDATE: I'm using it in my project Carbonyl Terminal:

Carbonyl Terminal using tmux

@0-issue
Copy link

0-issue commented Aug 22, 2023

@topcat001

I'll merge a small update with a filled in placeholder soon to the sixel branch. The branch is very basic and there is lots to do, but I'm using it for work right now to display graphs. The sixel features are behind a configure flag.

I tried cat'ing a sixel image with master tmux branch that enabled sixel support (configured with --enable-sixel). It doesn't work inside tmux, but does outside in iTerm2, WezTerm. Is there a config option that needs to be set too?

@topcat001
Copy link
Contributor

topcat001 commented Aug 23, 2023

@amanvm only --enable-sixel should be necessary. Even if your terminal does not support SIXEL, it should still show a text placeholder. I tested with xterm (with and without SIXEL support) locally on Arch Linux. I'll check on my mac later.

Are you sure you restarted the server? :)

@0-issue
Copy link

0-issue commented Aug 23, 2023

@topcat001 Yes I did restart the server, it doesn't work. I have a aarch64 macOS, but tested it on ArchLinux VM too. What I see is that cat doesn't work. lsix does produce a tiny few cursor wide result, but never bigger than that. cat works outside in iTerm2 and other terminals. Here's a screenshot, and test files (monkey.zip). I have created an issue: #3668 (comment).

Screenshot 2023-08-22 at 10 56 20 PM

cat works outside tmux in iTerm2, as can be seen in the image below:
Screenshot 2023-08-22 at 11 05 08 PM

@niutech
Copy link
Author

niutech commented Aug 23, 2023

@amanvm This issue is about clickable buttons, not sixel support.

@MarioRicalde
Copy link

MarioRicalde commented Aug 24, 2023

Thanks @nicm! I've appended [+] to the window list like this:

set -g window-status-format '#W#{?window_end_flag,#[range=user|new][+]#[norange],}'
bind -Troot MouseDown1Status if -F '#{==:#{mouse_status_range},window}' {
    select-window
} {
    if -F '#{==:#{mouse_status_range},new}' {
        new-window
    }
}

UPDATE: I'm using it in my project Carbonyl Terminal:

Carbonyl Terminal using tmux

Perfection.

@nicm thank you so much it's amazing, huge for certain clicker users.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

6 participants