doujiao6116 2017-07-10 22:00
浏览 89
已采纳

使用“ 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-10 22: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 java启动jar包后,运行过程中宕机
  • ¥500 高有偿提问!求优化设计微信小程序
  • ¥15 matlab在安装时报错 无法找到入口 无法定位程序输入点
  • ¥15 Android Studio webview 的使用问题, 播放器横屏全屏
  • ¥15 删掉jdk后重新下载,Java web所需要的eclipse无法使用
  • ¥15 uniapp正式环境中通过webapi将本地数据推送到设备出现的跨域问题
  • ¥15 xui建立节点,显示错误
  • ¥15 关于#单片机#的问题:开始、复位、十进制的功能可以实现,但是切换八进制的功能无法实现(按下按键也没有效果),把初始状态调成八进制,也是八进制可以实现但是切换到十进制不行(相关搜索:汇编语言|计数器)
  • ¥15 VINS-Mono或Fusion中feature_manager中estimated_depth是特征的深度还是逆深度?
  • ¥15 谷歌浏览器如何备份抖音网页数据
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部