Upgrade k8s package verison (#5358)
* upgrade k8s package version Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io> * Script upgrade and code formatting. Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io> Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io>
This commit is contained in:
48
vendor/k8s.io/kubectl/pkg/util/term/term_writer.go
generated
vendored
48
vendor/k8s.io/kubectl/pkg/util/term/term_writer.go
generated
vendored
@@ -17,11 +17,14 @@ limitations under the License.
|
||||
package term
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
wordwrap "github.com/mitchellh/go-wordwrap"
|
||||
"github.com/moby/term"
|
||||
|
||||
"k8s.io/client-go/tools/remotecommand"
|
||||
)
|
||||
|
||||
type wordWrapWriter struct {
|
||||
@@ -32,9 +35,11 @@ type wordWrapWriter struct {
|
||||
// NewResponsiveWriter creates a Writer that detects the column width of the
|
||||
// terminal we are in, and adjusts every line width to fit and use recommended
|
||||
// terminal sizes for better readability. Does proper word wrapping automatically.
|
||||
// if terminal width >= 120 columns use 120 columns
|
||||
// if terminal width >= 100 columns use 100 columns
|
||||
// if terminal width >= 80 columns use 80 columns
|
||||
//
|
||||
// if terminal width >= 120 columns use 120 columns
|
||||
// if terminal width >= 100 columns use 100 columns
|
||||
// if terminal width >= 80 columns use 80 columns
|
||||
//
|
||||
// In case we're not in a terminal or if it's smaller than 80 columns width,
|
||||
// doesn't do any wrapping.
|
||||
func NewResponsiveWriter(w io.Writer) io.Writer {
|
||||
@@ -51,16 +56,7 @@ func NewResponsiveWriter(w io.Writer) io.Writer {
|
||||
if terminalSize == nil {
|
||||
return w
|
||||
}
|
||||
|
||||
var limit uint
|
||||
switch {
|
||||
case terminalSize.Width >= 120:
|
||||
limit = 120
|
||||
case terminalSize.Width >= 100:
|
||||
limit = 100
|
||||
case terminalSize.Width >= 80:
|
||||
limit = 80
|
||||
}
|
||||
limit := getTerminalLimitWidth(terminalSize)
|
||||
|
||||
return NewWordWrapWriter(w, limit)
|
||||
}
|
||||
@@ -74,6 +70,32 @@ func NewWordWrapWriter(w io.Writer, limit uint) io.Writer {
|
||||
}
|
||||
}
|
||||
|
||||
func getTerminalLimitWidth(terminalSize *remotecommand.TerminalSize) uint {
|
||||
var limit uint
|
||||
switch {
|
||||
case terminalSize.Width >= 120:
|
||||
limit = 120
|
||||
case terminalSize.Width >= 100:
|
||||
limit = 100
|
||||
case terminalSize.Width >= 80:
|
||||
limit = 80
|
||||
}
|
||||
return limit
|
||||
}
|
||||
|
||||
func GetWordWrapperLimit() (uint, error) {
|
||||
stdout := os.Stdout
|
||||
fd := stdout.Fd()
|
||||
if !term.IsTerminal(fd) {
|
||||
return 0, errors.New("file descriptor is not a terminal")
|
||||
}
|
||||
terminalSize := GetSize(fd)
|
||||
if terminalSize == nil {
|
||||
return 0, errors.New("terminal size is nil")
|
||||
}
|
||||
return getTerminalLimitWidth(terminalSize), nil
|
||||
}
|
||||
|
||||
func (w wordWrapWriter) Write(p []byte) (nn int, err error) {
|
||||
if w.limit == 0 {
|
||||
return w.writer.Write(p)
|
||||
|
||||
Reference in New Issue
Block a user