James Walker
468788594f
All checks were successful
continuous-integration/drone/push Build is passing
Close #12
41 lines
806 B
Go
41 lines
806 B
Go
package tmux
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
type Window struct {
|
|
Name string `yaml:"name"`
|
|
Root string `yaml:"root,omitempty"`
|
|
Commands []string `yaml:"commands,omitempty"`
|
|
ID string `yaml:"-"`
|
|
Panes []Pane `yaml:"panes,omitempty"`
|
|
}
|
|
|
|
func (w *Window) Create(tmux *Tmux) {
|
|
tmux.Run("new-window", "-t", w.ID, "-n", w.Name, "-c", w.Root)
|
|
|
|
for i, pane := range w.Panes {
|
|
if i > 0 {
|
|
err := tmux.SplitWindow(w.ID, pane.Type, w.Root)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
if len(pane.Commands) > 0 {
|
|
tmux.SendKeys(w.ID, strings.Join(pane.Commands, ";"))
|
|
}
|
|
}
|
|
}
|
|
|
|
func (w *Window) SendCommands(tmux *Tmux) {
|
|
if len(w.Commands) > 0 {
|
|
tmux.SendKeys(w.ID, strings.Join(w.Commands, ";"))
|
|
}
|
|
}
|
|
|
|
func (w *Window) Focus(tmux *Tmux) {
|
|
tmux.Run("select-window", "-t", w.ID)
|
|
}
|