From 3fba1d1f88f4a9b0c3e33e9a0c1249b5849dfe66 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Sat, 23 Feb 2019 00:20:48 -0800 Subject: [PATCH] ssh/terminal: fix GetSize on Windows Return window size instead of buffer size. Fixes golang/go#27743 Change-Id: Ib1cd249f5680d86d505032e51d9102c2718ddf6f Reviewed-on: https://go-review.googlesource.com/c/163538 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- util_windows.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/util_windows.go b/util_windows.go index 6cb8a95..5cfdf8f 100644 --- a/util_windows.go +++ b/util_windows.go @@ -64,13 +64,15 @@ func Restore(fd int, state *State) error { return windows.SetConsoleMode(windows.Handle(fd), state.mode) } -// GetSize returns the dimensions of the given terminal. +// GetSize returns the visible dimensions of the given terminal. +// +// These dimensions don't include any scrollback buffer height. func GetSize(fd int) (width, height int, err error) { var info windows.ConsoleScreenBufferInfo if err := windows.GetConsoleScreenBufferInfo(windows.Handle(fd), &info); err != nil { return 0, 0, err } - return int(info.Size.X), int(info.Size.Y), nil + return int(info.Window.Right - info.Window.Left + 1), int(info.Window.Bottom - info.Window.Top + 1), nil } // ReadPassword reads a line of input from a terminal without local echo. This