doujiao6116 2017-07-11 06:00
浏览 87
已采纳

使用“ termui”在golang中的终端仪表板

I am working on drawing graphs on the terminal itself from inside a go code.I found this (https://github.com/gizak/termui) in golang. And used this(https://github.com/gizak/termui/blob/master/_example/gauge.go) to draw graph in my code.

Problem is this , as we can see in the code( https://github.com/gizak/termui/blob/master/_example/gauge.go ), 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条回答 默认 最新

  • douke1942 2017-07-11 06:09
    关注

    Here is a good read on Variadic Functions

    Take a look at the function signature of Render, https://github.com/gizak/termui/blob/master/render.go#L161

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog