Merge pull request #1966 from weaveworks/746-resize-ttys

Resize TTYs
This commit is contained in:
Simon
2016-11-03 11:06:16 +01:00
committed by GitHub
59 changed files with 4393 additions and 116 deletions

View File

@@ -3,6 +3,7 @@ package xfer
import (
"fmt"
"net/rpc"
"strconv"
"sync"
)
@@ -11,9 +12,10 @@ var ErrInvalidMessage = fmt.Errorf("Invalid Message")
// Request is the UI -> App -> Probe message type for control RPCs
type Request struct {
AppID string // filled in by the probe on receiving this request
NodeID string
Control string
AppID string // filled in by the probe on receiving this request
NodeID string
Control string
ControlArgs map[string]string
}
// Response is the Probe -> App -> UI message type for the control RPCs.
@@ -22,8 +24,9 @@ type Response struct {
Error string `json:"error,omitempty"`
// Pipe specific fields
Pipe string `json:"pipe,omitempty"`
RawTTY bool `json:"raw_tty,omitempty"`
Pipe string `json:"pipe,omitempty"`
RawTTY bool `json:"raw_tty,omitempty"`
ResizeTTYControl string `json:"resize_tty_control,omitempty"`
// Remove specific fields
RemovedNode string `json:"removedNode,omitempty"` // Set if node was removed
@@ -52,6 +55,41 @@ func (c ControlHandlerFunc) Handle(req Request, res *Response) error {
return nil
}
// ResizeTTYControlWrapper extracts the arguments needed by the resize tty control handler
func ResizeTTYControlWrapper(next func(pipeID string, height, width uint) Response) ControlHandlerFunc {
return func(req Request) Response {
var (
height, width uint64
err error
)
pipeID, ok := req.ControlArgs["pipeID"]
if !ok {
return ResponseErrorf("Missing argument: pipeID")
}
heightS, ok := req.ControlArgs["height"]
if !ok {
return ResponseErrorf("Missing argument: height")
}
widthS, ok := req.ControlArgs["width"]
if !ok {
return ResponseErrorf("Missing argument: width")
}
height, err = strconv.ParseUint(heightS, 10, 32)
if err != nil {
return ResponseErrorf("Bad parameter: height (%q): %v", heightS, err)
}
width, err = strconv.ParseUint(widthS, 10, 32)
if err != nil {
return ResponseErrorf("Bad parameter: width (%q): %v", widthS, err)
}
return next(pipeID, uint(height), uint(width))
}
}
// ResponseErrorf creates a new Response with the given formatted error string.
func ResponseErrorf(format string, a ...interface{}) Response {
return Response{

View File

@@ -7,7 +7,7 @@ import (
"github.com/gorilla/websocket"
)
// Pipe is a bi-directional channel from someone thing in the probe
// Pipe is a bi-directional channel from something in the probe
// to the UI.
type Pipe interface {
Ends() (io.ReadWriter, io.ReadWriter)