|
@@ -3,14 +3,12 @@
|
|
|
package term
|
|
|
|
|
|
import (
|
|
|
- "fmt"
|
|
|
"io"
|
|
|
"os"
|
|
|
"os/signal"
|
|
|
"syscall"
|
|
|
|
|
|
"github.com/Azure/go-ansiterm/winterm"
|
|
|
- "github.com/Sirupsen/logrus"
|
|
|
"github.com/docker/docker/pkg/system"
|
|
|
"github.com/docker/docker/pkg/term/windows"
|
|
|
)
|
|
@@ -123,52 +121,6 @@ func GetWinsize(fd uintptr) (*Winsize, error) {
|
|
|
return winsize, nil
|
|
|
}
|
|
|
|
|
|
-// SetWinsize tries to set the specified window size for the specified file descriptor.
|
|
|
-func SetWinsize(fd uintptr, ws *Winsize) error {
|
|
|
-
|
|
|
- // Ensure the requested dimensions are no larger than the maximum window size
|
|
|
- info, err := winterm.GetConsoleScreenBufferInfo(fd)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
- if ws.Width == 0 || ws.Height == 0 || ws.Width > uint16(info.MaximumWindowSize.X) || ws.Height > uint16(info.MaximumWindowSize.Y) {
|
|
|
- return fmt.Errorf("Illegal window size: (%v,%v) -- Maximum allow: (%v,%v)",
|
|
|
- ws.Width, ws.Height, info.MaximumWindowSize.X, info.MaximumWindowSize.Y)
|
|
|
- }
|
|
|
-
|
|
|
- // Narrow the sizes to that used by Windows
|
|
|
- width := winterm.SHORT(ws.Width)
|
|
|
- height := winterm.SHORT(ws.Height)
|
|
|
-
|
|
|
- // Set the dimensions while ensuring they remain within the bounds of the backing console buffer
|
|
|
- // -- Shrinking will always succeed. Growing may push the edges past the buffer boundary. When that occurs,
|
|
|
- // shift the upper left just enough to keep the new window within the buffer.
|
|
|
- rect := info.Window
|
|
|
- if width < rect.Right-rect.Left+1 {
|
|
|
- rect.Right = rect.Left + width - 1
|
|
|
- } else if width > rect.Right-rect.Left+1 {
|
|
|
- rect.Right = rect.Left + width - 1
|
|
|
- if rect.Right >= info.Size.X {
|
|
|
- rect.Left = info.Size.X - width
|
|
|
- rect.Right = info.Size.X - 1
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if height < rect.Bottom-rect.Top+1 {
|
|
|
- rect.Bottom = rect.Top + height - 1
|
|
|
- } else if height > rect.Bottom-rect.Top+1 {
|
|
|
- rect.Bottom = rect.Top + height - 1
|
|
|
- if rect.Bottom >= info.Size.Y {
|
|
|
- rect.Top = info.Size.Y - height
|
|
|
- rect.Bottom = info.Size.Y - 1
|
|
|
- }
|
|
|
- }
|
|
|
- logrus.Debugf("[windows] SetWinsize: Requested((%v,%v)) Actual(%v)", ws.Width, ws.Height, rect)
|
|
|
-
|
|
|
- return winterm.SetConsoleWindowInfo(fd, true, rect)
|
|
|
-}
|
|
|
-
|
|
|
// IsTerminal returns true if the given file descriptor is a terminal.
|
|
|
func IsTerminal(fd uintptr) bool {
|
|
|
return windows.IsConsole(fd)
|