mirror of
https://github.com/yudai/gotty.git
synced 2025-12-26 20:28:49 +01:00
Refactor
This commit is contained in:
parent
54403dd678
commit
a6133f34b7
54 changed files with 2140 additions and 1334 deletions
55
webtty/option.go
Normal file
55
webtty/option.go
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
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
|
||||
}
|
||||
}
|
||||
|
||||
// WithFixedSize sets a fixed size to TTY master.
|
||||
func WithFixedSize(width int, height int) Option {
|
||||
return func(wt *WebTTY) error {
|
||||
wt.width = width
|
||||
wt.height = height
|
||||
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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue