Terminal dashboard in golang using "termui"

I am working on drawing graphs on the terminal itself from inside a go code.I found this () in golang. And used this() to draw graph in my code.

Problem is this , as we can see in the code( ), they are passing g0,g1,g2,g3 all together in the end "termui.Render(g0, g1, g2, g3, g4)". In my case I don't know how many gauges to draw before hand so I used a list to store gauge objects and then tried to pass list to render.

 termui.Render(chartList...)

But it creates only one gauge.

This is how I am appending elements in the list.

 for i := 0; i < 5; i++ { g0 := termui.NewGauge() g0.Percent = i g0.Width = 50 g0.Height = 3 g0.BorderLabel = "Slim Gauge" chartList = append(chartList, g0) }

what I am getting is a gauge for i=4 only. when I am doing termui.Render(chartList...) Am I doing something wrong? PS - I have modified question based on the answer I got in this question.

1

1 Answer

Here is a good read on Variadic Functions

Take a look at the function signature of Render,

func Render(bs ...Bufferer) {

All you need to do is

termui.Render(chatList...)

assuming chartList is a []Bufferer

Edit
You are only seeing one because they are stacking on top of one-another. To see this add

g0.Height = 3
g0.Y = i * g0.Height // <-- add this line
g0.BorderLabel = "Slim Gauge" 

From a quick review of the project, it appears there are ways for auto-arranging that have to do with creating rows (and probably columns). So you might want to explore that, or you will need to manually position your elements.

enter image description here

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like