2

Add a clickable button to status bar · Issue #3652 · tmux/tmux · GitHub

 8 months ago
source link: https://github.com/tmux/tmux/issues/3652
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Comments

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!

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.

Member

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

Author

@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 reacted with thumbs up emoji

@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

Member

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 reacted with heart emoji

@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 reacted with thumbs up emoji

Author

@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 reacted with thumbs up emoji

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

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.

MarioRicalde reacted with eyes emoji

Member

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.

MarioRicalde reacted with heart emoji

Member

nicm

commented

Aug 15, 2023

edited

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.

Member

nicm

commented

Aug 15, 2023

edited

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).

MarioRicalde, niutech, and faustind reacted with heart emoji

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.

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

Member

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 and MarioRicalde reacted with thumbs up emoji

Author

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

@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?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK