forked from yudai/gotty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.go
62 lines (53 loc) · 1.33 KB
/
option.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
package webtty
import (
"encoding/json"
"github.com/pkg/errors"
)
// Option is an option for WebTTY.
type Option func(*WebTTY) error
// WithPermitWrite sets a WebTTY to accept input from slaves.
func WithPermitWrite() Option {
return func(wt *WebTTY) error {
wt.permitWrite = true
return nil
}
}
// WithFixedColumns sets a fixed width to TTY master.
func WithFixedColumns(columns int) Option {
return func(wt *WebTTY) error {
wt.columns = columns
return nil
}
}
// WithFixedRows sets a fixed height to TTY master.
func WithFixedRows(rows int) Option {
return func(wt *WebTTY) error {
wt.rows = rows
return nil
}
}
// WithWindowTitle sets the default window title of the session
func WithWindowTitle(windowTitle []byte) Option {
return func(wt *WebTTY) error {
wt.windowTitle = windowTitle
return nil
}
}
// WithReconnect enables reconnection on the master side.
func WithReconnect(timeInSeconds int) Option {
return func(wt *WebTTY) error {
wt.reconnect = timeInSeconds
return nil
}
}
// WithMasterPreferences sets an optional configuration of master.
func WithMasterPreferences(preferences interface{}) Option {
return func(wt *WebTTY) error {
prefs, err := json.Marshal(preferences)
if err != nil {
return errors.Wrapf(err, "failed to marshal preferences as JSON")
}
wt.masterPrefs = prefs
return nil
}
}