TermUI Go语言编写终端仪表盘 TermUI

polaris • 8306 次点击    
这是一个分享于 的项目,其中的信息可能已经有所发展或是发生改变。
Go terminal dashboard. Inspired by [blessed-contrib](https://github.com/yaronn/blessed-contrib), but purely in Go. Cross-platform, easy to compile, and fully-customizable. __Demo:__ (cast under osx 10.10; Terminal.app; Menlo Regular 12pt.) <img src="https://github.com/gizak/termui/raw/master/example/dashboard.gif" alt="demo" width="600"> __Grid layout:__ Expressive syntax, using [12 columns grid system](http://www.w3schools.com/bootstrap/bootstrap_grid_system.asp) ```go import ui "github.com/gizak/termui" // init and create widgets... // build ui.Body.AddRows( ui.NewRow( ui.NewCol(6, 0, widget0), ui.NewCol(6, 0, widget1)), ui.NewRow( ui.NewCol(3, 0, widget2), ui.NewCol(3, 0, widget30, widget31, widget32), ui.NewCol(6, 0, widget4))) // calculate layout ui.Body.Align() ui.Render(ui.Body) ``` [demo code:](https://github.com/gizak/termui/blob/master/example/grid.go) <img src="https://github.com/gizak/termui/raw/master/example/grid.gif" alt="grid" width="500"> ## Installation go get github.com/gizak/termui ## Usage Each component's layout is a bit like HTML block (box model), which has border and padding. The `Border` property can be chosen to hide or display (with its border label), when it comes to display, the label takes 1 padding space (i.e. in css: `padding: 1;`, innerHeight and innerWidth therefore shrunk by 1). `````go import ui "github.com/gizak/termui" // <- ui shortcut, optional func main() { err := ui.Init() if err != nil { panic(err) } defer ui.Close() p := ui.NewPar(":PRESS q TO QUIT DEMO") p.Height = 3 p.Width = 50 p.TextFgColor = ui.ColorWhite p.Border.Label = "Text Box" p.Border.FgColor = ui.ColorCyan g := ui.NewGauge() g.Percent = 50 g.Width = 50 g.Height = 3 g.Y = 11 g.Border.Label = "Gauge" g.BarColor = ui.ColorRed g.Border.FgColor = ui.ColorWhite g.Border.LabelFgColor = ui.ColorCyan ui.Render(p, g) // event handler... } ````` Note that components can be overlapped (I'd rather call this a feature...), `Render(rs ...Renderer)` renders its args from left to right (i.e. each component's weight is arising from left to right). ## Themes _All_ colors in _all_ components can be changed at _any_ time, while there provides some predefined color schemes: ```go // for now there are only two themes: default and helloworld termui.UseTheme("helloworld") // create components... ``` The `default ` theme's settings depend on the user's terminal color scheme, which is saying if your terminal default font color is white and background is white, it will be like: <img src="https://github.com/gizak/termui/raw/master/example/themedefault.png" alt="default" type="image/png" width="600"> The `helloworld` color scheme drops in some colors! <img src="https://github.com/gizak/termui/raw/master/example/themehelloworld.png" alt="helloworld" type="image/png" width="600"> ## Widgets #### Par [demo code](https://github.com/gizak/termui/blob/master/example/par.go) <img src="https://github.com/gizak/termui/raw/master/example/par.png" alt="par" type="image/png" width="300"> #### List [demo code](https://github.com/gizak/termui/blob/master/example/list.go) <img src="https://github.com/gizak/termui/raw/master/example/list.png" alt="list" type="image/png" width="200"> #### Gauge [demo code](https://github.com/gizak/termui/blob/master/example/gauge.go) <img src="https://github.com/gizak/termui/raw/master/example/gauge.png" alt="gauge" type="image/png" width="350"> #### Line Chart [demo code](https://github.com/gizak/termui/blob/master/example/linechart.go) <img src="https://github.com/gizak/termui/raw/master/example/linechart.png" alt="linechart" type="image/png" width="450"> #### Bar Chart [demo code](https://github.com/gizak/termui/blob/master/example/barchart.go) <img src="https://github.com/gizak/termui/raw/master/example/barchart.png" alt="barchart" type="image/png" width="150"> #### Sparklines [demo code](https://github.com/gizak/termui/blob/master/example/sparklines.go) <img src="https://github.com/gizak/termui/raw/master/example/sparklines.png" alt="sparklines" type="image/png" width="350">
授权协议:
MIT
开发语言:
Go 查看源码»
操作系统:
跨平台
8306 次点击  ∙  1 赞  
加入收藏 微博
4 回复  |  直到
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传