rthornton128 / goncurses

NCurses Library for Go
Other
383 stars 51 forks source link

Window.Maxyx returns off-by-one value #5

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Get a window. [stdscr, _ := goncurses.Init()]
2. Call Maxyx. [y, x := stdscr.Maxyx()]

What is the expected output? What do you see instead?
I expect the width and height of the window. I instead get the width and height 
plus one. (For example, on a standard 80x24 terminal window, I would expect to 
get 80 & 24 back. Instead I get 85 & 21.)

What version of the product are you using? On what operating system?
Latest from repository.

Please provide any additional information below.
I believe the issue was introduced in revision 73b8b800ab54. In window.go, you 
switched from:

return int(w.win._maxy + 1), int(w.win._maxx + 1)

to:

C.ncurses_getmaxyx(w.win, &cy, &cx)
return int(cy) + 1, int(cx) + 1

Quick experimentation with my local ncurses library indicates that _maxx, _maxy 
are (on an 80x24 terminal) 79 and 23, so this used to work. But evidently 
getmaxyx is already doing the offset calculation--it is returning 80 and 24, so 
the additional +1 is causing the error. I think this can be solved by changing 
the second line to return int(cy), int(cx).

Original issue reported on code.google.com by brandon....@gmail.com on 12 Jan 2013 at 10:21

GoogleCodeExporter commented 9 years ago
Spot on. A silly oversight and now fixed in tip.

Original comment by rthornto...@gmail.com on 12 Jan 2013 at 5:04