[GH-ISSUE #795] Question: Implementing Progress bar Draw Method #583

Closed
opened 2026-03-04 01:06:14 +03:00 by kerem · 1 comment
Owner

Originally created by @akurdunkar on GitHub (Jan 17, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/795

Hi, I have implemented a progress bar primitive. It works as follows:

  1. You set the progressFunc which returns the values that you need to show (e.g BarTitle, BarText, percentage)
  2. And then the Draw() method draws the progressbar from the value it receives from the progressFunc()

As far as I have read the documentation and used tview, the Draw Method is called upon Events (correct me if I am wrong). I wanted to Draw only the progress bar primitive every second. Upon using QueueUpdate and QueueUpdateDraw the whole "screen" seems to stop responding maybe it's because:

The provided function will be executed as part of the event loop
- tview documentation

Please take into consideration that the progressFunc I use takes some time to retrieve the values hence the blockage (ig?)

So I have been left but no choice but to Draw the whole app every time. like so:

	go func() {
		for {
			App.Draw()
			time.Sleep(time.Second)
		}
	}()

This seems to work fine. I have been using this for a long time. But I keep wondering is this the right way or if is there a more elegant way to do this. Any help would be welcome. Thanks for your time.

Originally created by @akurdunkar on GitHub (Jan 17, 2023). Original GitHub issue: https://github.com/rivo/tview/issues/795 Hi, I have implemented a progress bar [primitive](https://github.com/aditya-K2/gomp/blob/master/ui/progressBar.go). It works as follows: 1. You set the `progressFunc` which returns the values that you need to show (e.g BarTitle, BarText, percentage) 2. And then the Draw() method draws the progressbar from the value it receives from the progressFunc() As far as I have read the documentation and used `tview`, the `Draw` Method is called upon Events (correct me if I am wrong). I wanted to Draw only the progress bar primitive every second. Upon using `QueueUpdate` and `QueueUpdateDraw` the whole "screen" seems to stop responding maybe it's because: > The provided function will be executed as part of the event loop \- tview [documentation](https://pkg.go.dev/github.com/rivo/tview#Application.QueueUpdate) > Please take into consideration that the progressFunc I use takes some time to retrieve the values hence the blockage (ig?) So I have been left but no choice but to Draw the whole app every time. like so: ```go go func() { for { App.Draw() time.Sleep(time.Second) } }() ``` This seems to work fine. I have been using this for a long time. But I keep wondering is this the right way or if is there a more elegant way to do this. Any help would be welcome. Thanks for your time.
kerem closed this issue 2026-03-04 01:06:14 +03:00
Author
Owner

@akurdunkar commented on GitHub (Jan 26, 2023):

@aditya-K2 What you are doing is currently the only way to handle it with vanilla tview's application methods.

However, the most minimal steps would be to use the screen.SetContent methods, and then call screen.Show.

Those methods update the backend cell/frame buffers handled by tcell.Screen and mark dirty cells which are then actually rendered to the terminal with the screen.Show().

However for me the application.Draw also seemed a little heavier then necessary when only wanting to redraw certain primitives... Maybe these will help you? The functions are made variadic so you do not have to update any existing code, but can pass multiple primitives when you want to...

I see. Thanks for the help. 🤝🏽

<!-- gh-comment-id:1404577793 --> @akurdunkar commented on GitHub (Jan 26, 2023): > @aditya-K2 What you are doing is currently the only way to handle it with vanilla tview's application methods. > > However, the most minimal steps would be to use the `screen.SetContent` methods, and then call `screen.Show`. > > Those methods update the backend cell/frame buffers handled by `tcell.Screen` and mark dirty cells which are then actually rendered to the terminal with the `screen.Show()`. > > However for me the `application.Draw` also seemed a little heavier then necessary when only wanting to redraw certain primitives... Maybe these will help you? The functions are made variadic so you do not have to update any existing code, but can pass multiple primitives when you want to... > I see. Thanks for the help. 🤝🏽
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#583
No description provided.