nsf / termbox-go

Pure Go termbox implementation

Home Page:http://godoc.org/github.com/nsf/termbox-go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Any way to get the effects of Clear() on the back buffer without calling get_term_size()?

daniel-fanjul-alcuten opened this issue · comments

I seek a loop like this one:

for {
  Clear()
  w, h := Size()
  for ...  {
    SetCell(...)
  }
  Flush()
  // sleep for fps throttling
}

I do not see the need for calling the same syscall inside get_term_size() twice. Any way to achieve it?

Also, if there is a resize during Flush() and the buffers do not get sync, I cannot skip the sleep because there is no return value in that func.

I think it may be good to extract the resize check from the Clear() and Flush() funcs to a new one.

Thanks in advance.

Another alternative to consider: to remove the call to update_size_maybe() inside Flush().

What would be the benefit of such a change, and what would be the compatibility impact for existing programs using termbox-go?

commented

My honest opinion on that (and I mentioned that a few times) - stop making "games" on termbox. Sure maybe you're making some realtime financial or not so financial monitoring software or whatever, but stop doing it. Terminals are very basic interfaces, just use html, it's easier, more portable, runs even on a phone with some effort. Yes, for that you need to learn javascript/typescript/react/webpack/npm/css and all that crap, but it's a good way of making GUIs. Good example of a mixed (Go/HTML) GUI app: https://github.com/grafana/grafana

But if I can suggest something constructive about your problem, that would be this. There is a resize event in termbox input code path. You can run input handling and output handling in different goroutines. After you've received resize event on the input goroutine, communicate that to output goroutine so that it makes at least +1 full draw cycle. Might help.

Ok, thanks for your answers.