-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
90 lines (78 loc) · 1.46 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"github.com/wricardo/gomux"
)
func main() {
bytes, err := ioutil.ReadAll(os.Stdin)
var s Session
err = json.Unmarshal(bytes, &s)
if err != nil {
log.Fatal(err)
}
s.CreateSession(os.Stdout)
}
type Session struct {
Name string
Directory string
Windows []Window
}
func (s Session) CreateSession(writer io.Writer) {
params := gomux.SessionAttr{
Name: s.Name,
Directory: s.Directory,
}
gomux.KillSession(s.Name, writer)
gs := gomux.NewSessionAttr(params, writer)
for _, w := range s.Windows {
w.CreateWindow(gs)
}
}
type Window struct {
Name string
Pane *Pane
Directory string
}
func (w Window) CreateWindow(s *gomux.Session) {
attr := gomux.WindowAttr{
Name: w.Name,
Directory: w.Directory,
}
w1 := s.AddWindowAttr(attr)
w1p0 := w1.Pane(0)
if w.Pane != nil {
w.Pane.pane = w1p0
w.Pane.ExecCommand()
w.Pane.SplitPane()
}
}
type Pane struct {
pane *gomux.Pane
Command string
Directory string
SplitType string
Split []*Pane
}
func (p Pane) ExecCommand() {
p.pane.Exec(p.Command)
}
func (p Pane) SplitPane() {
for _, split := range p.Split {
attr := gomux.SplitAttr{
Directory: p.Directory,
}
if split.SplitType == "horizontal" {
split.pane = p.pane.SplitWAttr(attr)
} else {
fmt.Println(p.SplitType)
split.pane = p.pane.VsplitWAttr(attr)
}
split.pane.Exec(split.Command)
split.SplitPane()
}
}