Skip to content
Myr

zellij.go

This file

Path

src/zellij.go

83 lines · 2.9 KiB · Go

Last changed by

Separate floating pane border label from pane titleJunegunn Choibefore adoption50e6c02

History of this file

Take it

Support zellij floating pane via --popup (new name for --tmux) (#4145)Junegunn Choibefore adoption6f17d49

lines 1–3why, one step back
1package fzf
23import (

Separate floating pane border label from pane titleJunegunn Choibefore adoption50e6c02

line 4why, one step back
4 "fmt"

Support zellij floating pane via --popup (new name for --tmux) (#4145)Junegunn Choibefore adoption6f17d49

lines 5–7why, one step back
5 "os/exec"
6)7

Separate floating pane border label from pane titleJunegunn Choibefore adoption50e6c02

lines 8–17why, one step back
8const zellijBorderLabelEnv = internalEnvPrefix + "ZELLIJ_LABEL_PANE"
910// Errors are ignored. The pane may be gone11func setZellijBorderLabel(pane string, label string) {12 // Strip ANSI sequences fzf would otherwise render itself13 label, _, _ = extractColor(label, nil, nil)14 // '--' so that a label starting with a hyphen is not parsed as a flag15 exec.Command("zellij", "action", "rename-pane", "-p", pane, "--", label).Run()16}17

Support zellij floating pane via --popup (new name for --tmux) (#4145)Junegunn Choibefore adoption6f17d49

line 18why, one step back
18func runZellij(args []string, opts *Options) (int, error) {

Default to native border for Zellij floating pane (#4854)Junegunn Choibefore adoptione54f11c

lines 19–25why, one step back
19 // Use the native Zellij border by default, consistent with tmux, so that
20 // the pane can be moved and resized with the mouse. Set before21 // popupArgStr so that it does not inject an fzf border. fzf draws its own22 // border instead when a border style is explicitly specified.23 if nativeBorder(opts) {24 opts.Tmux.border = true25 }

Support zellij floating pane via --popup (new name for --tmux) (#4145)Junegunn Choibefore adoption6f17d49

lines 26–31why, one step back
26 argStr, dir := popupArgStr(args, opts)
2728 zellijArgs := []string{29 "run", "--floating", "--close-on-exit", "--block-until-exit",30 "--cwd", dir,31 }

Separate floating pane border label from pane titleJunegunn Choibefore adoption50e6c02

line 32why, one step back
32 ownsLabel := false

Set --border-label as the title of the tmux floating pane (#4853)Junegunn Choibefore adoption77e6394

line 33why, one step back
33 if !opts.Tmux.border {

Support zellij floating pane via --popup (new name for --tmux) (#4145)Junegunn Choibefore adoption6f17d49

line 34why, one step back
34 zellijArgs = append(zellijArgs, "--borderless", "true")

Default to native border for Zellij floating pane (#4854)Junegunn Choibefore adoptione54f11c

lines 35–45why, one step back
35 } else {
36 // Set --border-label as the name of the pane, displayed on the37 // native border. The label is left to fzf when it draws its own38 // border with the label on it (border-native with an explicit39 // --border style). Empty otherwise, to override the default name40 // (the running command). Passed as a single argument in the41 // --name=label form; the detached form fails to parse when the42 // label starts with a hyphen. No escaping is needed beyond43 // stripping ANSI sequences fzf would otherwise render itself.44 // --border-label-pos is ignored.45 label := ""

Separate floating pane border label from pane titleJunegunn Choibefore adoption50e6c02

lines 46–47why, one step back
46 ownsLabel = noBorderSpecified(opts)
47 if ownsLabel {

Default to native border for Zellij floating pane (#4854)Junegunn Choibefore adoptione54f11c

lines 48–50why, one step back
48 label, _, _ = extractColor(opts.BorderLabel.label, nil, nil)
49 }50 zellijArgs = append(zellijArgs, "--name="+label)

Support zellij floating pane via --popup (new name for --tmux) (#4145)Junegunn Choibefore adoption6f17d49

lines 51–72why, one step back
51 }
52 switch opts.Tmux.position {53 case posUp:54 zellijArgs = append(zellijArgs, "-y", "0")55 case posDown:56 zellijArgs = append(zellijArgs, "-y", "9999")57 case posLeft:58 zellijArgs = append(zellijArgs, "-x", "0")59 case posRight:60 zellijArgs = append(zellijArgs, "-x", "9999")61 case posCenter:62 // Zellij centers floating panes by default63 }64 zellijArgs = append(zellijArgs, "--width", opts.Tmux.width.String())65 zellijArgs = append(zellijArgs, "--height", opts.Tmux.height.String())66 zellijArgs = append(zellijArgs, "--")6768 return runProxy(argStr, func(temp string, needBash bool) (*exec.Cmd, error) {69 sh, err := sh(needBash)70 if err != nil {71 return nil, err72 }

Separate floating pane border label from pane titleJunegunn Choibefore adoption50e6c02

lines 73–80why, one step back
73 if ownsLabel {
74 // 'zellij run' cannot set the new pane's environment, so the75 // command exports it itself. exec avoids a lingering shell76 zellijArgs = append(zellijArgs, sh, "-c", fmt.Sprintf(`export %s="$ZELLIJ_PANE_ID"; exec %s %s`,77 zellijBorderLabelEnv, escapeSingleQuote(sh), escapeSingleQuote(temp)))78 } else {79 zellijArgs = append(zellijArgs, sh, temp)80 }

Support zellij floating pane via --popup (new name for --tmux) (#4145)Junegunn Choibefore adoption6f17d49

lines 81–83why, one step back
81 return exec.Command("zellij", zellijArgs...), nil
82 }, opts, true)83}