Skip to content

Commit

Permalink
Shuffled some arguments around in getConsoleScreenBufferInfo in commo…
Browse files Browse the repository at this point in the history
…n/terminal_windows.go so that the interface forces the user to correctly declare a _CONSOLE_SCREEN_BUFFER_INFO type.
  • Loading branch information
arizvisa committed Aug 19, 2018
1 parent c5e15e7 commit a1f8eb5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions common/terminal_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit a1f8eb5

Please sign in to comment.