From a1f8eb563dd6fc244813eec4b242921ccd45aacd Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Sat, 18 Aug 2018 23:54:19 -0500 Subject: [PATCH] Shuffled some arguments around in getConsoleScreenBufferInfo in common/terminal_windows.go so that the interface forces the user to correctly declare a _CONSOLE_SCREEN_BUFFER_INFO type. --- common/terminal_windows.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/common/terminal_windows.go b/common/terminal_windows.go index 2d394a3d777..556873eb031 100644 --- a/common/terminal_windows.go +++ b/common/terminal_windows.go @@ -54,27 +54,31 @@ func kernel32_GetConsoleScreenBufferInfo(hConsoleOutput syscall.Handle, info *_C } // windows api to get the console screen buffer info -func getConsoleScreenBufferInfo() (csbi *_CONSOLE_SCREEN_BUFFER_INFO, err error) { - var fd syscall.Handle +func getConsoleScreenBufferInfo(csbi *_CONSOLE_SCREEN_BUFFER_INFO) (err error) { + var ( + bi _CONSOLE_SCREEN_BUFFER_INFO + fd syscall.Handle + ) // Re-open CONOUT$ as in some instances, stdout may be closed and guaranteed an stdout if fd, err = syscall.Open("CONOUT$", syscall.O_RDWR, 0); err != nil { - return nil, err + return err } defer syscall.Close(fd) // grab the dimensions for the console - if err = kernel32_GetConsoleScreenBufferInfo(fd, &csbi); err != nil { - return nil, err + if err = kernel32_GetConsoleScreenBufferInfo(fd, &bi); err != nil { + return err } - return csbi, nil + *csbi = bi + return nil } func platformGetTerminalDimensions() (width, height int, err error) { - var csbi *_CONSOLE_SCREEN_BUFFER_INFO + var csbi _CONSOLE_SCREEN_BUFFER_INFO - if csbi, err := getConsoleScreenBufferInfo(); err != nil { + if err = getConsoleScreenBufferInfo(&csbi); err != nil { return 0, 0, err }