2016-04-18 16:54:44 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015 The Kubernetes Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2017-01-11 14:09:48 +00:00
|
|
|
"k8s.io/apimachinery/pkg/util/runtime"
|
2017-04-14 09:33:57 +00:00
|
|
|
"k8s.io/client-go/tools/remotecommand"
|
2016-04-18 16:54:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// handleResizing spawns a goroutine that processes the resize channel, calling resizeFunc for each
|
2017-02-15 10:34:49 +00:00
|
|
|
// remotecommand.TerminalSize received from the channel. The resize channel must be closed elsewhere to stop the
|
2016-04-18 16:54:44 +00:00
|
|
|
// goroutine.
|
2017-02-15 10:34:49 +00:00
|
|
|
func HandleResizing(resize <-chan remotecommand.TerminalSize, resizeFunc func(size remotecommand.TerminalSize)) {
|
2016-04-18 16:54:44 +00:00
|
|
|
if resize == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
defer runtime.HandleCrash()
|
|
|
|
|
2018-03-29 11:55:25 +00:00
|
|
|
for size := range resize {
|
2016-04-18 16:54:44 +00:00
|
|
|
if size.Height < 1 || size.Width < 1 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
resizeFunc(size)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|