tmux-python / tmuxp

🖥️ Session manager for tmux, build on libtmux.
https://tmuxp.git-pull.com/
MIT License
4.1k stars 233 forks source link

WorkspaceBuilder creates "main-horizontal" layout with a very thin main pane #667

Open cblegare opened 3 years ago

cblegare commented 3 years ago

Step 1: Provide a summary of your problem

I am trying to use tmuxp.workspacebuilder.WorkspaceBuilder with a simple main-horizontal 3-panes scenario and the created result has the main pane of 1 line high.

Step 2: Provide tmuxp details

➜ tmuxp debug-info
-------------------------
environment:
        dist: Linux-5.4.0-65-generic-x86_64-with-glibc2.29
        arch: x86_64
        uname: Linux; exfo7255; 5.4.0-65-generic
        version: #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021
-------------------------
python version: 3.8.7 (default, Feb  2 2021, 16:09:27)  [GCC 9.3.0]
system PATH: <REDACTED>/.venv/bin:<REDACTED>
tmux version: 3.0
libtmux version: 0.8.5
tmuxp version: 1.7.2
tmux path: /usr/bin/tmux
tmuxp path:<REDACTED>/.venv/lib/python3.8/site-packages/tmuxp/__init__.py
shell: /usr/bin/zsh
-------------------------
tmux sessions:
        myproject: 1 windows (created Thu Feb 18 20:48:37 2021) (attached)

tmux windows:
        0: mainwindow* (3 panes) [189x53] [layout 0ecd,189x53,0,0[189x1,0,0,81,189x51,0,2{93x51,0,2,82,95x51,94,2,83}]] @37 (active)

tmux panes:
        0: [189x1] [history 14/2000, 9178 bytes] %81
        1: [93x51] [history 13/2000, 6476 bytes] %82 (active)
        2: [95x51] [history 14/2000, 6613 bytes] %83

tmux global options:
        activity-action other
        assume-paste-time 1
        base-index 0
        bell-action none
        default-command
        default-shell /usr/bin/zsh
        default-size 80x24
        destroy-unattached off
        detach-on-destroy on
        display-panes-active-colour red
        display-panes-colour blue
        display-panes-time 1000
        display-time 750
        history-limit 2000
        key-table root
        lock-after-time 0
        lock-command "lock -np"
        message-command-style fg=yellow,bg=black
        message-style fg=black,bg=yellow
        mouse on
        prefix C-a
        prefix2 None
        renumber-windows off
        repeat-time 500
        set-titles off
        set-titles-string "#S:#I:#W - \"#T\" #{session_alerts}"
        silence-action other
        status on
        status-bg green
        status-fg black
        status-format[0] "#[align=left range=left #{status-left-style}]#{T;=/#{status-left-length}:status-left}#[norange default]#[list=on align=#{status-justify}]#[list=left-marker]<#[list=right-marker]>#[list=on]#{W:#[range=window|#{window_index} #{window-status-style}#{?#{&&:#{window_last_flag},#{!=:#{window-status-last-style},default}}, #{window-status-last-style},}#{?#{&&:#{window_bell_flag},#{!=:#{window-status-bell-style},default}}, #{window-status-bell-style},#{?#{&&:#{||:#{window_activity_flag},#{window_silence_flag}},#{!=:#{window-status-activity-style},default}}, #{window-status-activity-style},}}]#{T:window-status-format}#[norange default]#{?window_end_flag,,#{window-status-separator}},#[range=window|#{window_index} list=focus #{?#{!=:#{window-status-current-style},default},#{window-status-current-style},#{window-status-style}}#{?#{&&:#{window_last_flag},#{!=:#{window-status-last-style},default}}, #{window-status-last-style},}#{?#{&&:#{window_bell_flag},#{!=:#{window-status-bell-style},default}}, #{window-status-bell-style},#{?#{&&:#{||:#{window_activity_flag},#{window_silence_flag}},#{!=:#{window-status-activity-style},default}}, #{window-status-activity-style},}}]#{T:window-status-current-format}#[norange list=on default]#{?window_end_flag,,#{window-status-separator}}}#[nolist align=right range=right #{status-right-style}]#{T;=/#{status-right-length}:status-right}#[norange default]"
        status-format[1] "#[align=centre]#{P:#{?pane_active,#[reverse],}#{pane_index}[#{pane_width}x#{pane_height}]#[default] }"
        status-interval 15
        status-justify left
        status-keys vi
        status-left "[#S] "
        status-left-length 10
        status-left-style default
        status-position bottom
        status-right "#{?window_bigger,[#{window_offset_x}#,#{window_offset_y}] ,}\"#{=21:pane_title}\" %H:%M %d-%b-%y"
        status-right-length 40
        status-right-style default
        status-style fg=black,bg=green
        update-environment[0] DISPLAY
        update-environment[1] KRB5CCNAME
        update-environment[2] SSH_ASKPASS
        update-environment[3] SSH_AUTH_SOCK
        update-environment[4] SSH_AGENT_PID
        update-environment[5] SSH_CONNECTION
        update-environment[6] WINDOWID
        update-environment[7] XAUTHORITY
        visual-activity off
        visual-bell off
        visual-silence off
        word-separators " "

tmux window options:
        aggressive-resize off
        allow-rename off
        alternate-screen on
        automatic-rename on
        automatic-rename-format "#{?pane_in_mode,[tmux],#{pane_current_command}}#{?pane_dead,[dead],}"
        clock-mode-colour blue
        clock-mode-style 24
        main-pane-height 24
        main-pane-width 80
        mode-keys vi
        mode-style fg=black,bg=yellow
        monitor-activity off
        monitor-bell on
        monitor-silence 0
        other-pane-height 0
        other-pane-width 0
        pane-active-border-style fg=green
        pane-base-index 0
        pane-border-format "#{?pane_active,#[reverse],}#{pane_index}#[default] \"#{pane_title}\""
        pane-border-status off
        pane-border-style default
        remain-on-exit off
        synchronize-panes off
        window-active-style default
        window-size smallest
        window-style default
        window-status-activity-style reverse
        window-status-bell-style reverse
        window-status-current-format "#I:#W#{?window_flags,#{window_flags}, }"
        window-status-current-style default
        window-status-format "#I:#W#{?window_flags,#{window_flags}, }"
        window-status-last-style default
        window-status-separator " "
        window-status-style default
        wrap-search on
        xterm-keys on

Step 3: Describe the problem:

Steps to reproduce:

Run the following script

import tmuxp.workspacebuilder
import tmuxp.config
import libtmux.server
import libtmux.exc

tmuxp_config = {}  # see below

builder = tmuxp.workspacebuilder.WorkspaceBuilder(
    tmuxp.config.trickle(
        tmuxp.config.expand(tmuxp_config, ".")
    ),
    server=libtmux.server.Server()
)
try:
    builder.build()
except libtmux.exc.TmuxSessionExists:
    builder.build(builder.session)
builder.session.attach_session()
for plugin in builder.plugins:
    plugin.before_script(builder.session)

Observed Results:

Three panes are nicely, but the main (top) one has only one line of heigth

Expected Results:

Panes created with configured size.

Relevant Code:

tmuxp_config = {
    "session_name": "myproject",
    "start_directory": ".",
    "shell_command_before": [],
    "windows": [
        {
            "window_name": "mainwindow",
            "focus": True,
            ### this "abstract" layout reproduces the issue
            "layout": "main-horizontal",
            ### This "specific" layout does not reproduces the issue
            # "layout": "3951,189x53,0,0[189x35,0,0,51,189x17,0,36{94x17,0,36,52,94x17,95,36,53}]"
            "options": {
                "main-pane-height": 35
            },
            "panes": [
                "pane",
                "pane",
                "pane"
            ]
        }
    ]
}
illarionvk commented 3 years ago

I experience the same issue when tmuxp is invoked in the CLI with the YAML config file.

YAML config file contents

session_name: primary
start_directory: ~/dev/
windows:
  - window_name: window_one
    focus: true
    layout: main-horizontal
    options:
      main-pane-height: 42
    panes:
      - 'pane'
      - 'pane'
      - 'pane'
  - window_name: window_two
    layout: main-horizontal
    options:
      main-pane-height: 42
    panes:
      - 'pane'
      - 'pane'
      - 'pane'
  - window_name: window_three
    layout: main-horizontal
    options:
      main-pane-height: 42
    panes:
      - 'pane'
      - 'pane'
      - 'pane'

tmuxp debug info

-------------------------
environment:
    dist: macOS-10.15.7-x86_64-i386-64bit
    arch: x86_64
    uname: [REDACTED]
    version: Darwin Kernel Version 19.6.0: Mon Apr 12 20:57:45 PDT 2021; root:xnu-6153.141.28.1~1/RELEASE_X86_64
-------------------------
python version: 3.9.5 (default, May  4 2021, 03:33:11)  [Clang 12.0.0 (clang-1200.0.32.29)]
system PATH: [REDACTED]
tmux version: 3.2
libtmux version: 0.8.5
tmuxp version: 1.7.2
tmux path: /usr/local/bin/tmux
tmuxp path: /usr/local/lib/python3.9/site-packages/tmuxp/__init__.py
shell: /bin/zsh
categulario commented 3 years ago

I'm experiencing the same issue with this config

-------------------------
environment:
    dist: Linux-5.10.70-1-MANJARO-x86_64-with-glibc2.33
    arch: x86_64
    uname: [redacted]
    version: #1 SMP PREEMPT Thu Sep 30 15:29:01 UTC 2021
-------------------------
python version: 3.9.7 (default, Aug 31 2021, 13:28:12)  [GCC 11.1.0]
system PATH: [redacted]
tmux version: 3.2
libtmux version: 0.10.1
tmuxp version: 1.9.2
tmux path: /usr/bin/tmux
tmuxp path: /usr/lib/python3.9/site-packages/tmuxp/__init__.py
shell: /bin/bash
-------------------------

and this yaml:

session_name: some
start_directory: ./
windows:
  - focus: 'true'
    layout: main-horizontal
    options:
      main-pane-height: 35
    panes:
    - pane
    - pane
    - pane
    window_name: foo
varac commented 2 years ago

Same here, any fix expected soon ?

tony commented 2 years ago

@varac I added labels to this and noted PRs are welcome. Any contributions with tests that makes tmuxp more robust is always something we're open to

In future releases we will radically improve layouts as well.

tony commented 2 years ago

I updated from Focal (20.04), with tmux 3.0a to Jammy (22.04) with tmux 3.2a and now im getting this behavior on certain config.

I did not get this on tmux 3.0a on focal

On another system, it works fine: Ubuntu 21.10 (impish), tmux 3.1c

tony commented 2 years ago

It's most likely related to set_layout_hook()

Some more info on the window layout behavior before attaching: https://github.com/tmuxinator/tmuxinator/issues/651#issuecomment-500321664

tony commented 2 years ago

@varac @illarionvk @cblegare @categulario @mikedfunk

v1.13.1 is live with a fix, via @nvasilas from #793

PyPI, GitHub Tag

pip install tmuxp==1.13.1

Any better now?

P.S. You may need to kill your tmux server or try on a fresh one by passing something like tmuxp ./workspacefile.yaml -L OtherTmuxServer

categulario commented 2 years ago

It works! the panes now are of a decent size. Although in my case they are not of the expected size. They're definitely useful, but short in size for some reason.

Captura desde 2022-08-22 12-49-57

nvasilas commented 2 years ago

@categulario What's your config file? Did you select the main-horizontal layout. If that's the case then it looks ok to me.

categulario commented 2 years ago

Maybe that's the expected behavior. I don't actually know because I haven't seen it working before (:

In any case I confirm that it works for me in the given release

El lun., 22 de agosto de 2022 22:53, nvasilas @.***> escribió:

@categulario https://github.com/categulario What's your config file? Did you select the main-horizontal layout. If that's the case then it looks ok to me.

— Reply to this email directly, view it on GitHub https://github.com/tmux-python/tmuxp/issues/667#issuecomment-1222473843, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGBBZE4NBPCAFPZI73EUFDV2OH7TANCNFSM4X3RL3WA . You are receiving this because you were mentioned.Message ID: @.***>

tony commented 2 years ago

My next change at v1.13.2 will probably bring this issue back, if so ping me.

It works! the panes now are of a decent size. Although in my case they are not of the expected size. They're definitely useful, but short in size for some reason.

I think we will need to rewind for a real fix to this. I will think of something.

rr326 commented 2 years ago

@Tony FYI think this issue is live again ("if so, ping me.)

tmuxp 1.15.0, litmus 0.15.3
macOS 12.5.1

Also, mine is layout: main-vertical but same idea of a too small pane.

Question - is there a workaround? Manually, after the window loads, I can do tmux select-layout and it snaps to the correct position. It there a way I can add that to my tmuxp.yaml so it happens automatically?

tony commented 2 years ago

@rr326

I don't have a workaround - yet, sorry - but do ask for assistance from community in helping with that.

815 is an issue to follow where I intend on devising a robust solution for workspaces that work at scale and is tested

P.S. And of course, if I devise a workaround in the mean time I will add it here and notify you and the thread

rr326 commented 2 years ago

@Tony I'll download the source and see if I can contribute. I'm solid at python but I suspect there is a lot of os / shell magic here that will baffle me. I'll take a look and see if I can contribute.

tony commented 2 years ago

@rr326 The codebase of tmuxp and libtmux will improve over the coming months. If it seems like too big of task today it will be better later

rr326 commented 2 years ago

@tony I guess I should wait then - no need to do a bunch of hard work when easy is on the way. I'll try to remember to check back.

theutz commented 1 year ago

FWIW, I had some success setting the main-pane-width to a percentage in order to workaround this issue for the main-vertical layout.

session_name: meh
windows:
  - layout: main-vertical
    options:
      main-pane-width: '40%'
    panes:
      - pane
      - pane
tony commented 7 months ago

@theutz @pedrosena @fbnfgc @rr326 @categulario @nvasilas @varac @illarionvk @cblegare @mikedfunk

There is a PR at #926 testing a fix for this longstanding issue. I am in need of testers for this and would be very grateful for your time 🙏.

If you try ~these instructions~ pip install --user --pre --no-cache 'tmuxp>=1.46.0a0' (with 1.46.0a0+), does this help?

tony commented 7 months ago

If you try v1.46.0 (docs, changes, release, PyPI), is anything better?

Instructions:

pip install --user --upgrade tmuxp

tmuxp -V should show at least 1.46.0.

categulario commented 7 months ago

hey @tony! I just tested 1.36 (broken behavior) and then upgraded to 1.46 and it was fixed! with the very same config I put in the comments before.

Thanks for the amazing work

tony commented 7 months ago

Yes! Thank you for checking, glad this seems to be working!

categulario commented 7 months ago

this will simplify my configs so much!