workon/tmux/window.go

41 lines
806 B
Go
Raw Permalink Normal View History

2020-04-13 22:06:09 -04:00
package tmux
import (
"strings"
)
type Window struct {
Name string `yaml:"name"`
2020-07-30 22:13:27 -04:00
Root string `yaml:"root,omitempty"`
Commands []string `yaml:"commands,omitempty"`
2020-04-13 22:06:09 -04:00
ID string `yaml:"-"`
Panes []Pane `yaml:"panes,omitempty"`
2020-04-13 22:06:09 -04:00
}
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, ";"))
}
}
2020-04-13 22:06:09 -04:00
}
func (w *Window) SendCommands(tmux *Tmux) {
if len(w.Commands) > 0 {
tmux.SendKeys(w.ID, strings.Join(w.Commands, ";"))
2020-04-13 22:06:09 -04:00
}
}
func (w *Window) Focus(tmux *Tmux) {
tmux.Run("select-window", "-t", w.ID)
}