{"action":"created","issue":{"url":"https://api.github.com/repos/gizak/termui/issues/14","labels_url":"https://api.github.com/repos/gizak/termui/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/gizak/termui/issues/14/comments","events_url":"https://api.github.com/repos/gizak/termui/issues/14/events","html_url":"https://github.com/gizak/termui/issues/14","id":64944048,"number":14,"title":"Panic when List height is less than 2 (and borders are enabled)","user":{"login":"warmans","id":1299401,"avatar_url":"https://avatars.githubusercontent.com/u/1299401?v=3","gravatar_id":"","url":"https://api.github.com/users/warmans","html_url":"https://github.com/warmans","followers_url":"https://api.github.com/users/warmans/followers","following_url":"https://api.github.com/users/warmans/following{/other_user}","gists_url":"https://api.github.com/users/warmans/gists{/gist_id}","starred_url":"https://api.github.com/users/warmans/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/warmans/subscriptions","organizations_url":"https://api.github.com/users/warmans/orgs","repos_url":"https://api.github.com/users/warmans/repos","events_url":"https://api.github.com/users/warmans/events{/privacy}","received_events_url":"https://api.github.com/users/warmans/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-28T13:39:38Z","updated_at":"2015-03-28T16:57:42Z","closed_at":null,"body":"Hi, \r\n\r\nI've found an issue with Lists. The following code will generate a panic: \r\n\r\n```go\r\npackage main\r\n\r\nimport \"github.com/gizak/termui\"\r\nimport \"github.com/nsf/termbox-go\"\r\n\r\nfunc main() {\r\n\terr := termui.Init()\r\n\tif err != nil {\r\n\t\tpanic(err)\r\n\t}\r\n\tdefer termui.Close()\r\n\r\n\ttermui.UseTheme(\"helloworld\")\r\n\r\n\tls := termui.NewList()\r\n\tls.Items = []string{\"[0] github.com/gizak/termui\"}\r\n\tls.Width = 25\r\n\tls.Height = 1\r\n\r\n\ttermui.Render(ls)\r\n\ttermbox.PollEvent()\r\n}\r\n```\r\n\r\n```\r\npanic: runtime error: slice bounds out of range\r\n\r\ngoroutine 1 [running]:\r\ngithub.com/gizak/termui.(*List).Buffer(0xc208066000, 0x0, 0x0, 0x0)\r\n\t/home/warmans/go/src/github.com/gizak/termui/list.go:82 +0x490\r\ngithub.com/gizak/termui.Render(0xc20805af50, 0x1, 0x1)\r\n\t/home/warmans/go/src/github.com/gizak/termui/render.go:51 +0xc7\r\nmain.main()\r\n\t/home/warmans/go/src/github.com/gizak/termui/example/list.go:26 +0x1fc\r\n\r\ngoroutine 5 [runnable]:\r\nos/signal.loop()\r\n\t/home/warmans/Downloads/go/src/os/signal/signal_unix.go:21 +0x1f\r\ncreated by os/signal.init·1\r\n\t/home/warmans/Downloads/go/src/os/signal/signal_unix.go:27 +0x35\r\nexit status 2\r\n```\r\n\r\nline 82 of list is:\r\n\r\n```go \r\ntrimItems = trimItems[:l.innerHeight]\r\n```\r\n\r\nIt would seem that `l.innerHeight` is set to -1 which prevents the slice from working. I believe the reason for this is that it deducts 2 from `Height` for the top and bottom border to get `innerHeight`. As such setting the Height to 2 will avoid the error. This is fine if you understand that the borders contribute to the height but is a bit unintuitive, particularly when the heights are calculated dynamically.\r\n\r\nThe following code prevents the error but renders a blank list\r\n\r\n```go \r\nif l.innerHeight < 0 {\r\n\ttrimItems = make([]string, 0)\r\n} else {\r\n\tif len(trimItems) > l.innerHeight {\r\n\t\ttrimItems = trimItems[:l.innerHeight]\r\n\t}\r\n}\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/gizak/termui/issues/comments/87267941","html_url":"https://github.com/gizak/termui/issues/14#issuecomment-87267941","issue_url":"https://api.github.com/repos/gizak/termui/issues/14","id":87267941,"user":{"login":"gizak","id":2100512,"avatar_url":"https://avatars.githubusercontent.com/u/2100512?v=3","gravatar_id":"","url":"https://api.github.com/users/gizak","html_url":"https://github.com/gizak","followers_url":"https://api.github.com/users/gizak/followers","following_url":"https://api.github.com/users/gizak/following{/other_user}","gists_url":"https://api.github.com/users/gizak/gists{/gist_id}","starred_url":"https://api.github.com/users/gizak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gizak/subscriptions","organizations_url":"https://api.github.com/users/gizak/orgs","repos_url":"https://api.github.com/users/gizak/repos","events_url":"https://api.github.com/users/gizak/events{/privacy}","received_events_url":"https://api.github.com/users/gizak/received_events","type":"User","site_admin":false},"created_at":"2015-03-28T16:57:42Z","updated_at":"2015-03-28T16:57:42Z","body":"> This is fine if you understand that the borders contribute to the height but is a bit unintuitive, particularly when the heights are calculated dynamically.\r\n\r\nit's sure a little bit unintuitive, but if bring all the margin, border and padding terminologies may make it complex. I originally thought it would be good that let users do a little math but keep the box model simple.\r\n\r\nAnyway, `innerHeight` may be a general problem, so I traced back and changed `align()` in `block.go`, set `innerHeight` and `innerWidth` to zero when they are negative. "}}