gizak / termui

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

termui.Handle(ā€œ/timer/1sā€, func(e termui.Event)) not working on ubuntu 18.04 #198

Closed imwaddy closed 5 years ago

imwaddy commented 5 years ago

I used the function which is correctly working with windows(windows 7 & 8) but it is not working on Ubuntu 18.04

imwaddy commented 5 years ago

err := termui.Init() if err != nil { panic(err) } defer termui.Close()

lsss := time.Now().Format(time.RFC1123)
strs := []string{
    "",
    "",
    "",
    "  ",
    "",
    "",
    "",
    " ",
    "",
    "",
    " Current Time is : " + lsss,
    "",
}

ls := termui.NewList()
ls.Items = strs
ls.ItemFgColor = termui.ColorYellow

// ls.BorderLabel = borderLabel

ls.Height = 15
ls.Width = 80
ls.Border = false
ls.Y = 10
termui.Render(ls)

termui.Handle("/timer/1s", func(e termui.Event) {

    strs = []string{
        "",
        "",
        "",
        " ",
        "",
        "",
        "",
        "",
        " Current Time is : " + time.Now().Format(time.RFC1123),
        "",
    }
    ls.Items = strs

    termui.Render(ls)

})

termui.Handle("q", func(termui.Event) {
    termui.StopLoop()

})

termui.Loop()

scr

this is freezing the time but in windows it continuously showing current time.

bgadrian commented 5 years ago

I thought that I was doing something wrong, it does not work for me either

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"
NAME="Ubuntu"
VERSION="18.04.1 LTS (Bionic Beaver)"

Is there any other way to update a widget?

As a workaround:

go func() {
        update := time.NewTicker(time.Second)
        for {
            <-update.C
            ls.Items = strs
            ui.Render(ls)
        }
    }()
imwaddy commented 5 years ago

@bgadrian I was also thought that I was doing something wrong too. Finally put this into issue so I can be get little help by authors.

cjbassi commented 5 years ago

My apologies for not updating the documentation, the termui timers were removed on the master branch in favor of Go's built in timers. Most of the event logic in termui has actually been reworked on master. I'll make sure to update the documentation this week with the updates. The v2.3.0 release should still have all the functionality as documented however.

To switch to Go's built in timers, I would recommend either @bgadrian's example, the example from go by example, or using a select statement to choose between timer events and termui events.

imwaddy commented 5 years ago

@cjbassi thanks for your reply. Keyboard events (combination keys as 'C-c' ) is not working but working in windows. Does this also removed?

cjbassi commented 5 years ago

The key identifiers were also changed on master, so you would have to do <C-c> now. The available keycodes are listed here. Let me know if you still get issues with it.

imwaddy commented 5 years ago

Thank you so much for help...Please update documention as early as possible..Thanks for awesome library..šŸ™‚

imwaddy commented 5 years ago

@cjbassi I used key identifier() as you've mentioned in comment. It's working properly with keys but not clearing the console first time run

1

And while second time it's clear whole console screen.

I tested on windows 7 but not on Ubuntu...Once I'm done I'll let you know.

imwaddy commented 5 years ago

Hii @cjbassi, I have tested same with ubuntu but it's exactly opposite of windows behaviour. On second run it will freezing window and nothing happend with keys. But first time it works totally fine in my case.

cjbassi commented 5 years ago

Hi, I just updated the documentation. You can check godoc for code documentation and also the wiki for general info now. I also reworked the events (again) and changed the names of a few things so there's some breaking changes that are documented in the CHANGELOG. Let me know if anyone has any suggestions about anything.

cjbassi commented 5 years ago

@imwaddy Let me know if you're still having issues with the latest version.

imwaddy commented 5 years ago

@cjbassi I have updated the package and now it's working fine in both cases....I've not seen documentation yet but soon I'll inform you. Thanks!

cjbassi commented 5 years ago

Closing this but let me know if you have any more issues/suggestions!