-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcreate-session.go
62 lines (53 loc) · 1.51 KB
/
create-session.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
// The MIT License (MIT)
// Copyright (C) 2019-2023 Georgiy Komarov <[email protected]>
// Simple example that shows how to create a tmux session with the user-defined
// configuration.
package main
import (
"fmt"
gotmux "github.com/jubnzv/go-tmux"
)
func main() {
// Create instance of the running tmux server.
server := new(gotmux.Server)
// Check that the "example" session already exists.
exists, err := server.HasSession("example")
if err != nil {
msg := fmt.Errorf("Can't check 'example' session: %s", err)
fmt.Println(msg)
return
}
if exists {
// You can also use KillSession here.
fmt.Println("Session 'example' already exists!")
fmt.Println("Please stop it before running this demo.")
return
}
// Prepare a configuration for the new session that contains some windows.
session := gotmux.Session{Name: "example-session"}
w1 := gotmux.Window{Name: "first", Id: 0}
w2 := gotmux.Window{Name: "second", Id: 1}
session.AddWindow(w1)
session.AddWindow(w2)
server.AddSession(session)
sessions := []*gotmux.Session{}
sessions = append(sessions, &session)
conf := gotmux.Configuration{
Server: server,
Sessions: sessions,
ActiveSession: nil}
// Setup this configuration.
err = conf.Apply()
if err != nil {
msg := fmt.Errorf("Can't apply prepared configuration: %s", err)
fmt.Println(msg)
return
}
// Attach to the created session
err = session.AttachSession()
if err != nil {
msg := fmt.Errorf("Can't attached to created session: %s", err)
fmt.Println(msg)
return
}
}