rthornton128 / goncurses

NCurses Library for Go
Other
383 stars 51 forks source link

Compilation error when using REQ_LEFT #53

Closed kallerosenbaum closed 4 years ago

kallerosenbaum commented 4 years ago

I'm running into problems using REQ_LEFT.

The following code doesn't compile:

package main

import (
    gc "github.com/rthornton128/goncurses"
)

func main() {
    menuWin, _ := gc.Init()

    gc.Raw(true)
    gc.Echo(false)
    menuWin.Keypad(true)
    gc.Cursor(0)

    menuWin.Keypad(true)
    itemPos, _ := gc.NewItem("YES", "")
    itemNeg, _ := gc.NewItem("NO","")

    choices := []*gc.MenuItem {itemNeg, itemPos}
    menu, _ := gc.NewMenu(choices)
    menu.SetWindow(menuWin)
    height, width := dimensions(menuWin)
    menu.SubWindow(menuWin.Derived(height, width, 0, 0))

    menu.Format(1, 2)
    menu.Post()

    menuWin.Refresh()

    var key gc.Key
    for ; ; key = menuWin.GetChar(){
        switch key {
        case gc.KEY_RIGHT:
            menu.Driver(gc.REQ_RIGHT) // Works
        case gc.KEY_LEFT:
            menu.Driver(gc.REQ_LEFT) // Compilation error
        }
    }

    gc.End()
}

func dimensions(w *gc.Window) (height int, width int) {
    y, x := w.YX()
    maxy, maxx := w.MaxYX()
    height = maxy - y
    width = maxx - x
    return
}

Compilation error:

$ go build req_left.go 
# command-line-arguments
./req_left.go:36:15: cannot use goncurses.REQ_LEFT (type goncurses.MenuDriverReq) as type int in argument to menu.Driver

However if I change REQ_LEFT to REQ_RIGHT it does compile.

$ go version
go version go1.13.8 linux/amd64

goncurses version seems to be v0.0.0-20200419155752-a72cfe131f63 according to my go.mod file.