Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ QUESTION ] Update widget NOW #46

Open
Peter2121 opened this issue Jul 25, 2022 · 2 comments
Open

[ QUESTION ] Update widget NOW #46

Peter2121 opened this issue Jul 25, 2022 · 2 comments

Comments

@Peter2121
Copy link

I use edit widget to show command's output. According to the gowid documentation, I use
app.Run(gowid.RunFunction(func(app gowid.IApp) { <some code> app.Redraw() } construction to update the content of the edit widget. It works correctly, but the updates received by the widget are not very frequent, really I get only one update at the end of my command, so I cannot see the progress of command execution. Is there any way to do more frequent updates? I tried to use app.RedrawTerminal() somehow, but the application crashes sometimes, probably due to race conditions.

@gcla
Copy link
Owner

gcla commented Aug 27, 2022

Hi @Peter2121 - one thing to watch for is to ensure RedrawTerminal is only called from the "main" UI-updating goroutine. If you use app.Run(...), that ensures your function will be issued in that way. But app.Run(...) will call RedrawTerminal automatically for you anyway (maybe that shouldn't always be the case - I'll think about that) - so the explicit call of yours to RedrawTerminal would be redundant here. Do you run app.Run(...) in a timed loop of some kind for regular updates to your display? editor.go has an example of that; a goroutine is started to wait for a timer to expire; when it does, the editor status bar is updated, but via app.Run(...) to ensure execution in the main gowid goroutine. If you don't mind pasting some of your application code, I will try to debug more.

@Peter2121
Copy link
Author

Peter2121 commented Aug 30, 2022

In cbsd-tui.go at line 777 I check if there are something new in a file. If yes - I need to update edit widget named logspace immediately with the additional text from buf. So, I do the following:

			logText = logspace.Text() + string(buf[:rbytes]) + "\n"
			app.RunThenRenderEvent(gowid.RunFunction(func(app gowid.IApp) {
				logspace.SetText(logText, app)
				logspace.SetCursorPos(utf8.RuneCountInString(logspace.Text()), app)
				app.Sync()
			}))

It works, but it seems that there is a delay between the update of the text in my file and in the widget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants