nsf / termbox-go

Pure Go termbox implementation
http://godoc.org/github.com/nsf/termbox-go
MIT License
4.67k stars 373 forks source link

Fix invalid console buffer size under windows 10. #153 #168

Closed gries closed 7 years ago

gries commented 7 years ago

Hi, this provides a fix for issue: #153 As documented here: https://docs.microsoft.com/en-us/windows/console/setconsolescreenbuffersize

This minimum depends on the current font size for the console (selected by the user) and the SM_CXMIN and SM_CYMIN values returned by the GetSystemMetrics function.

This PR aims to read out the aboved mentioned metrics to use them as minimum values for the buffer size. To make it work the user32.dll must be loaded.

This is my first PR in go so if you find any problems with it please be gentle ;)

nsf commented 7 years ago

Thanks. Looks okay, I guess. Haven't tried it myself.

gries commented 6 years ago

The change was done in order to fix #153 The problem was that this call: https://github.com/nsf/termbox-go/blob/b6acae516ace002cb8105a89024544a1480655a5/api_windows.go#L48

left the powershell unsable as the given buffer sizes where incorrect. My change basically reads the minimum window size provided by user32.dll and uses that as minimum buffer size. As stated here: https://docs.microsoft.com/en-us/windows/console/setconsolescreenbuffersize

The specified dimensions also cannot be less than the minimum size allowed by the system. This minimum depends on the current font size for the console (selected by the user) and the SM_CXMIN and SM_CYMIN values returned by the GetSystemMetrics function.

So it seems to me that for some reason the SM_C*MIN value on your system is 146 thus the window size is adjusted to the minimum height.