gui_windows.go

 1// Copyright 2014 The gocui Authors. All rights reserved.
 2// Use of this source code is governed by a BSD-style
 3// license that can be found in the LICENSE file.
 4
 5// +build windows
 6
 7package gocui
 8
 9import (
10	"os"
11	"syscall"
12	"unsafe"
13)
14
15type wchar uint16
16type short int16
17type dword uint32
18type word uint16
19
20type coord struct {
21	x short
22	y short
23}
24
25type smallRect struct {
26	left   short
27	top    short
28	right  short
29	bottom short
30}
31
32type consoleScreenBufferInfo struct {
33	size              coord
34	cursorPosition    coord
35	attributes        word
36	window            smallRect
37	maximumWindowSize coord
38}
39
40var (
41	kernel32                       = syscall.NewLazyDLL("kernel32.dll")
42	procGetConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo")
43)
44
45// getTermWindowSize is get terminal window size on windows.
46func (g *Gui) getTermWindowSize() (int, int, error) {
47	var csbi consoleScreenBufferInfo
48	r1, _, err := procGetConsoleScreenBufferInfo.Call(os.Stdout.Fd(), uintptr(unsafe.Pointer(&csbi)))
49	if r1 == 0 {
50		return 0, 0, err
51	}
52	return int(csbi.window.right - csbi.window.left + 1), int(csbi.window.bottom - csbi.window.top + 1), nil
53}