Add support for `layout` in windows (#7)

master
Ivan 3 years ago committed by GitHub
parent f85d2fcb98
commit 880c448a05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -80,6 +80,7 @@ windows:
- name: code
root: blog # a relative path to root
manual: true # you can start this window only manually, using the -w arg
layout: main-vertical
commands:
- docker-compose start
panes:
@ -91,6 +92,7 @@ windows:
- name: infrastructure
root: ~/Developer/blog/my-microservices
layout: tiled
panes:
- type: horizontal
root: .
@ -114,6 +116,7 @@ stop:
windows:
- name: code
layout: main-horizontal
commands:
- vim app/dependencies.php
panes:

@ -14,7 +14,8 @@ type Window struct {
BeforeStart []string `yaml:"before_start"`
Panes []Pane `yaml:"panes"`
Commands []string `yaml:"commands"`
Manual bool
Layout string `yaml:"layout"`
Manual bool `yaml:"manual"`
}
type Config struct {

@ -119,6 +119,16 @@ func (smug Smug) Start(config Config, windows []string) error {
return err
}
}
layout := w.Layout
if layout == "" {
layout = EvenHorizontal
}
_, err = smug.tmux.SelectLayout(ses+w.Name, layout)
if err != nil {
return err
}
}
if len(windows) == 0 {

@ -41,10 +41,17 @@ var testTable = []struct {
{
Name: "win1",
Manual: false,
Layout: "main-horizontal",
Panes: []Pane{
Pane{
Type: "horizontal",
},
},
},
{
Name: "win2",
Manual: true,
Layout: "tiled",
},
},
Stop: []string{
@ -56,6 +63,8 @@ var testTable = []struct {
"tmux has-session -t ses",
"tmux new -Pd -s ses",
"tmux neww -Pd -t ses: -n win1 -c root",
"tmux split-window -Pd -t ses: -c root -h",
"tmux select-layout -t ses:win1 main-horizontal",
"tmux kill-window -t ses:0",
"tmux move-window -r",
"tmux attach -t ses:0",
@ -86,6 +95,7 @@ var testTable = []struct {
"tmux has-session -t ses",
"tmux new -Pd -s ses",
"tmux neww -Pd -t ses: -n win2 -c root",
"tmux select-layout -t ses:win2 even-horizontal",
},
[]string{
"tmux kill-window -t ses:win2",

@ -10,6 +10,14 @@ const (
HSplit = "horizontal"
)
const (
EvenHorizontal = "even-horizontal"
EvenVertical = "even-vertical"
MainHorizontal = "main-horizontal"
MainVertical = "main-vertical"
Tiled = "tiled"
)
type Tmux struct {
commander Commander
}
@ -98,6 +106,11 @@ func (tmux Tmux) SplitWindow(target string, splitType string, root string, comma
return pane, nil
}
func (tmux Tmux) SelectLayout(target string, layoutType string) (string, error) {
cmd := exec.Command("tmux", "select-layout", "-t", target, layoutType)
return tmux.commander.Exec(cmd)
}
func (tmux Tmux) StopSession(target string) (string, error) {
cmd := exec.Command("tmux", "kill-session", "-t", target)
return tmux.commander.Exec(cmd)

Loading…
Cancel
Save