diff --git a/bin/bwopencode b/bin/bwopencode index 77f1911..db29d37 100755 --- a/bin/bwopencode +++ b/bin/bwopencode @@ -41,6 +41,9 @@ # - Namespace tools: masked (nsenter, unshare, chroot) # - Keyring tools: masked (keyctl) # - SSH/GPG agent env vars: stripped +# - Zellij env vars (ZELLIJ, ZELLIJ_SESSION_NAME, ZELLIJ_PANE_ID): passed; +# inside Zellij OPENTUI_FORCE_WCWIDTH=1 is also set so the TUI's column +# counts match Zellij's (a user-set OPENTUI_FORCE_WCWIDTH wins) # - ~/.bashrc and other shell rc files: not mounted # # Usage: diff --git a/bin/bwopencode2 b/bin/bwopencode2 index af42e87..7d4c179 100755 --- a/bin/bwopencode2 +++ b/bin/bwopencode2 @@ -66,6 +66,9 @@ # - Namespace tools: masked (nsenter, unshare, chroot) # - Keyring tools: masked (keyctl) # - SSH/GPG agent env vars: stripped +# - Zellij env vars (ZELLIJ, ZELLIJ_SESSION_NAME, ZELLIJ_PANE_ID): passed; +# inside Zellij OPENTUI_FORCE_WCWIDTH=1 is also set so the TUI's column +# counts match Zellij's (a user-set OPENTUI_FORCE_WCWIDTH wins) # - ~/.bashrc and other shell rc files: not mounted # # Sandbox-escape guard: OpenCode 2 normally talks to a shared background diff --git a/lib/bwrap_sandbox_lib.sh b/lib/bwrap_sandbox_lib.sh index 6366971..d8a00be 100644 --- a/lib/bwrap_sandbox_lib.sh +++ b/lib/bwrap_sandbox_lib.sh @@ -2601,6 +2601,22 @@ build_env_vars() { pass_through_if_set COLORTERM pass_through_if_set TERM_PROGRAM + # Zellij: these only identify the session (no socket is mounted), so + # OpenTUI can tell it runs inside Zellij. Zellij drops zero-width + # code points (emoji variation selectors, ZWJ) and has no grapheme width + # mode, so OpenTUI's default width counting drifts from Zellij's and the + # screen is left garbled until a resize. Count each code point on its + # own (OPENTUI_FORCE_WCWIDTH, which OpenTUI only tests for presence) + # unless the user set it themselves. + pass_through_if_set ZELLIJ + pass_through_if_set ZELLIJ_SESSION_NAME + pass_through_if_set ZELLIJ_PANE_ID + if [[ -n "${OPENTUI_FORCE_WCWIDTH+x}" ]]; then + SANDBOX_ENV+=("OPENTUI_FORCE_WCWIDTH=${OPENTUI_FORCE_WCWIDTH}") + elif [[ -n "${ZELLIJ:-}" ]]; then + SANDBOX_ENV+=("OPENTUI_FORCE_WCWIDTH=1") + fi + # Locale pass_through_if_set LANG pass_through_if_set LC_ALL