Skip to content

Commit

Permalink
support getWinsize on windows
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof authored and buger committed Apr 1, 2021
1 parent 2f3e71b commit bb646f1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/buger/goterm

go 1.16

require golang.org/x/sys v0.0.0-20210331175145-43e1dd70ce54
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang.org/x/sys v0.0.0-20210331175145-43e1dd70ce54 h1:rF3Ohx8DRyl8h2zw9qojyLHLhrJpEMgyPOImREEryf0=
golang.org/x/sys v0.0.0-20210331175145-43e1dd70ce54/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
2 changes: 1 addition & 1 deletion terminal_nosysioctl.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build windows plan9 solaris
// +build !windows plan9 solaris

package goterm

Expand Down
22 changes: 22 additions & 0 deletions terminal_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// +build windows

package goterm

import (
"golang.org/x/sys/windows"
"os"
)

func getWinsize() (*winsize, error) {
ws := new(winsize)
fd := os.Stdout.Fd()
var info windows.ConsoleScreenBufferInfo
if err := windows.GetConsoleScreenBufferInfo(windows.Handle(fd), &info); err != nil {
return nil, err
}

ws.Col = uint16(info.Window.Right - info.Window.Left + 1)
ws.Row = uint16(info.Window.Bottom - info.Window.Top + 1)

return ws, nil
}

0 comments on commit bb646f1

Please sign in to comment.