gizak / termui

Golang terminal dashboard
MIT License
13.06k stars 783 forks source link

v3 gets me "undefined: termui.Handle" #253

Closed DaleEMoore closed 4 years ago

DaleEMoore commented 4 years ago

Please pardon my noviceness! I'm perplexed that Handle is undefined. I had some almost functioning v2 code that I had hopes would be improved by trying it with v3. But it seems like Handle has disappeared in v3 and I'm unsure what direction to head now. Here is a piece of code that I've crafted showing my issue.

// DaleEMoore@gMail.Com
// termui v3 implementation got me "undefined: termui.Handle"

package main

import (
    "fmt"
    "os"
)
import termui "github.com/gizak/termui/v3"

func main() {
    err := termui.Init()
    if err != nil {
        panic(err)
    }
    defer termui.Close()
    fmt.Println("q)uit, CTRL-c, other gets printed.")

    termui.Handle("/sys/kbd/q", func(termui.Event) {
        os.Exit(212)
    })
    termui.Handle("/sys/kbd/C-c", func(termui.Event) { 
        fmt.Println("C-c")
        os.Exit(230)
    })
    termui.Handle("/sys/kbd", func(termui.Event) { 
        fmt.Println("other")
    })
    fmt.Println("Completed UI setup.")

    termui.Close()
    fmt.Println("Completed UI Close.")
    os.Exit(223)
}

// .vimrc needs ":set modeline" in Ubuntu to turn on modeline processing.
// Make the following line the last line of the file, always.
// vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

Any help you can provide is very much appreciated! DaleEMoore@gMail.Com

DaleEMoore commented 4 years ago

Perhaps I would be better off if I read the v2 to v3 documentation. Could anybody tell me where to go?

DaleEMoore commented 4 years ago

Howdy y'all; Thanks to everyone whom contributed their time and effort! Here's what seems to be working fine for me now:

// DaleEMoore@gMail.Com
// termui v3 implementation got me "undefined: termui.Handle"

package main

import (
    "fmt"
    "os"
)
import termui "github.com/gizak/termui/v3"

func main() {
    err := termui.Init()
    if err != nil {
        panic(err)
    }
    defer termui.Close()
    fmt.Println("q)uit, CTRL-c, other gets printed.")
    uiEvents := termui.PollEvents()
    for {
        e := <-uiEvents
        switch e.ID {
        case "q":
            fmt.Println("q")
            os.Exit(212)
        case  "<c-c":
            fmt.Println("C-c")
            os.Exit(230)
        default:
            fmt.Println("other ", e.ID)
        }
    }
}

// .vimrc needs ":set modeline" in Ubuntu to turn on modeline processing.
// Make the following line the last line of the file, always.
// vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: