项目作者: liamg

项目描述 :
Build beautiful terminal dashboards/GUIs in golang.
高级语言: Go
项目地址: git://github.com/liamg/gobless.git
创建时间: 2018-03-10T09:00:37Z
项目社区:https://github.com/liamg/gobless

开源协议:MIT License

下载


gobless

Build beautiful terminal dashboards and GUIs in Golang.

example

The name was intended to be pronounced go-bless due to the inspiration from blessed-contrib, but gob-less is kind of funnier, so we’ll go with that instead.

Thanks to tcell, full cross-platform terminal support is expected.

Requirements

  • Go 1.10+
  • Terminal with:
    • Unicode support
    • 256 color support

Get Started

  1. go get github.com/liamg/gobless

You can get started by experimenting with the various examples.

Components

Text Box

example

  1. textbox := gobless.NewTextBox()
  2. textbox.SetWidth(64)
  3. textbox.SetHeight(10)
  4. helloTextbox.SetTextWrap(true)
  5. helloTextbox.SetText(`Lorem ipsum...`)

Full example code is here.

Bar Chart

example

  1. chart := gobless.NewBarChart()
  2. chart.SetTitle("Traffic")
  3. chart.SetWidth(40)
  4. chart.SetHeight(15)
  5. chart.SetYScale(100)
  6. chart.SetBar("Europe", 60)
  7. chart.SetBar("US", 72)
  8. chart.SetBar("Asia", 37)

Full example code is here.

Progress Bar

Sparklines

Line Chart

Block Chart

(kind of like blessed-contrib’s stacked gauge)

Donut

Log

Table

Tree

Dot Matrix

The dot matrix component allows you set blocks of colour at double the resolution of the terminal characters, using the various partial quadrant unicode characters.

It includes utility methods for drawing lines, circles etc.

example

Example code is here.

Layout System

Gobless includes a built-in CSS style 12 column nestable grid layout system. This uses Rows and Columns (which are themselves components) to quickly build a UI with minimal effort.

example

  1. rows := []gobless.Component{
  2. gobless.NewRow(
  3. gobless.GridSizeHalf,
  4. gobless.NewColumn(
  5. gobless.GridSizeTwoThirds,
  6. helloTextbox,
  7. ),
  8. gobless.NewColumn(
  9. gobless.GridSizeOneThird,
  10. gobless.NewRow(
  11. gobless.GridSizeFull,
  12. gobless.NewColumn(
  13. gobless.GridSizeFull,
  14. chart,
  15. chart2,
  16. ),
  17. ),
  18. ),
  19. ),
  20. gobless.NewRow(
  21. gobless.GridSizeHalf,
  22. gobless.NewColumn(
  23. gobless.GridSizeFull,
  24. quitTextbox,
  25. ),
  26. ),
  27. }
  28. gui.Render(rows...)

You can also detect resize events and automatically resize the layout of your components if you wish.

  1. gui.HandleResize(func(event gobless.ResizeEvent) {
  2. gui.Render(rows...)
  3. })

A full example is also available.

Alternatively, if you need to, you can position components absolutely using the .SetX(), .SetY(), .SetWidth() and .SetHeight() methods, omitting the presence of rows/columns entirely.

Events

Gobless can currently detect two types of events:

Key Press Events

You can add your own handlers for key presses, utilising the gobless.Key* constants.

For example, to stop rendering the GUI when the user presses CTRL + Q, you could do:

  1. gui.HandleKeyPress(gobless.KeyCtrlQ, func(event gobless.KeyPressEvent){
  2. gui.Close()
  3. })

Terminology

  • A Cell refers to an individual terminal cell, in which a single character can be drawn.
  • A Tile refers to a rectangular grouping of cells.
  • A Component is an entity which provides a tile - or tiles - to the GUI to render. A bar chart, for example.