Minimalist Go package aimed at creating Console User Interfaces.

Related tags

go gui cui gocui
Overview

GOCUI - Go Console User Interface

GoDoc

Minimalist Go package aimed at creating Console User Interfaces.

Features

  • Minimalist API.
  • Views (the "windows" in the GUI) implement the interface io.ReadWriter.
  • Support for overlapping views.
  • The GUI can be modified at runtime (concurrent-safe).
  • Global and view-level keybindings.
  • Mouse support.
  • Colored text.
  • Customizable edition mode.
  • Easy to build reusable widgets, complex layouts...

Installation

Execute:

$ go get github.com/jroimartin/gocui

Documentation

Execute:

$ go doc github.com/jroimartin/gocui

Or visit godoc.org to read it online.

Example

package main

import (
	"fmt"
	"log"

	"github.com/jroimartin/gocui"
)

func main() {
	g, err := gocui.NewGui(gocui.OutputNormal)
	if err != nil {
		log.Panicln(err)
	}
	defer g.Close()

	g.SetManagerFunc(layout)

	if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
		log.Panicln(err)
	}

	if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
		log.Panicln(err)
	}
}

func layout(g *gocui.Gui) error {
	maxX, maxY := g.Size()
	if v, err := g.SetView("hello", maxX/2-7, maxY/2, maxX/2+7, maxY/2+2); err != nil {
		if err != gocui.ErrUnknownView {
			return err
		}
		fmt.Fprintln(v, "Hello world!")
	}
	return nil
}

func quit(g *gocui.Gui, v *gocui.View) error {
	return gocui.ErrQuit
}

Screenshots

r2cui

_examples/demo.go

_examples/dynamic.go

Projects using gocui

  • komanda-cli: IRC Client For Developers.
  • vuls: Agentless vulnerability scanner for Linux/FreeBSD.
  • wuzz: Interactive cli tool for HTTP inspection.
  • httplab: Interactive web server.
  • domainr: Tool that checks the availability of domains based on keywords.
  • gotime: Time tracker for projects and tasks.
  • claws: Interactive command line client for testing websockets.
  • terminews: Terminal based RSS reader.
  • diagram: Tool to convert ascii arts into hand drawn diagrams.
  • pody: CLI app to manage Pods in a Kubernetes cluster.
  • kubexp: Kubernetes client.
  • kcli: Tool for inspecting kafka topics/partitions/messages.
  • fac: git merge conflict resolver
  • jsonui: Interactive JSON explorer for your terminal.
  • cointop: Interactive terminal based UI application for tracking cryptocurrencies.

Note: if your project is not listed here, let us know! :)

Issues
  • 256 OutputMode support prototype

    256 OutputMode support prototype

    Known issue with gray-scale colors

    opened by mephux 23
  • How do I update a view from another goroutine?

    How do I update a view from another goroutine?

    I have a top-like application that updates views vi coroutines. I am able to update the views fine but get panic (panic: bytes.Buffer: truncation out of range) when the terminal is reset. I notice that if I do not call flush from my update code the error does not occur, but the ui does not refresh until an event is processed. How do I correctly signal to gocui that a view has changed?

    question 
    opened by kgilmer 15
  • Correct concurrent use of stdin : user input field

    Correct concurrent use of stdin : user input field

    Hey there, I'm totally new to gocui / term-box etc. I am trying to make a simple frame in which on can type text in an input field and when hitting enter, the field is cleared, and text appended to another view.

    However, when using the /_examples/stdin.go method, the program just freezes before even displaying the frames.

    How should I go about it ?

    question 
    opened by Spriithy 14
  • Colored text

    Colored text

    Add support for colored text. E.g.: fmt.Println(v, "Regular text and [yb:Yellow bold text]")

    opened by jroimartin 14
  • 256 colors

    256 colors

    Any reason why using this shouldn't work? https://github.com/aybabtme/rgbterm

    enhancement 
    opened by mephux 13
  • Add basic support for ANSI terminal escape sequences

    Add basic support for ANSI terminal escape sequences

    • when printing the cells of the view, we look for escape codes, and update the attributes of the cell accordingly. This is done via the escapeIntepreter struct and methods
    • add a colors.go example

    The code currently only supports the 8 basic colors, and bold, underscore and reverse.

    opened by deweerdt 10
  • Disabling arrow keys for empty lines.

    Disabling arrow keys for empty lines.

    When using a text editor, it's customary that using the down or right arrow keys have no effect when we're at the end of the text and there's no more characters after the cursor. The enter key is then used to insert a new line.

    In an input box created with v.Editable = true, the cursor keys can be used indefinitely to create newlines (see _examples/mask.go). Since we're still pre-v1.0.0, I think this is a safe change to make.

    bug 
    opened by awnumar 9
  • Forcing a re-update from another go-routine.

    Forcing a re-update from another go-routine.

    I think #15 is related but it seems outdated since I can't find any reference to concurrency or the flush() function/method in the docs.

    How can you update a view from another goroutine? Currently the only way I can make edits show up on the screen is by pressing a random key so it loops again and shows the updates. How can this be down without pressing the key?

    It seems there is a flush function as referenced in #15, but it's not exported so cannot be accessed externally.

    question 
    opened by awnumar 9
  • Reading buffer without carriage returns inserted by Wrap = true

    Reading buffer without carriage returns inserted by Wrap = true

    Hey! First of all, thank you so much for an awesome library! I have only been using it for a few days but I already have a version of my app working really well, thanks to how great your library is.

    I am building a simple cui note taking app (https://github.com/jameycribbs/cribbnotes_cui). So far, I've been able to get pretty much everything working that I want, but I have run into an issue when saving a note to a json file. When I use the view.Buffer() method to grab the internal buffer, and I have view.Wrap=true, then the json file I save has all of the carriage returns that are getting inserted into the text because Wrap is set to true.

    Is there any way to keep Wrap=true, but be able to grab the contents of the internal buffer without the carriage returns that are being inserted?

    I took a look at the source code, but I didn't see a way to do this. I'm fairly new to Go, so I am probably missing something.

    Thanks for any help you can give and thanks again for such a great library!

    Jamey Cribbs

    bug question 
    opened by jameycribbs 8
  • DeleteView() should remove the associated key bindings with the view

    DeleteView() should remove the associated key bindings with the view

    It seems like delete view is not removing the associated key bindings and it causes issues on dynamic UIs.

    enhancement 
    opened by dcu 7
  • Start printing at cursor position

    Start printing at cursor position

    Hi i want to create a custom widget , a button with text alignment, but seems like I can't use SetCursor / SetOrigin to start printing at cursor position, what i'm doing wrong??

    package widgets
    
    import (
    	"fmt"
    
    	"github.com/jroimartin/gocui"
    )
    
    var (
    	ButtonID      = "Button"
    	ButtonCounter = 0
    )
    
    type ButtonHandler func(b *Button) error
    
    type Button struct {
    	lrpadding   int
    	tbpadding   int
    	x           int
    	y           int
    	w           int
    	h           int
    	name        *Text
    	label       *Text
    	borderColor gocui.Attribute
    	textColor   gocui.Attribute
    	handler     func(g *gocui.Gui, v *gocui.View) error
    }
    
    func (b *Button) Layout(g *gocui.Gui) error {
    	v, err := g.SetView(b.name.String(), b.x, b.y, b.x+b.w, b.y+b.h)
    	if err != nil {
    		if err != gocui.ErrUnknownView {
    			return err
    		}
    		if _, err := g.SetCurrentView(b.name.String()); err != nil {
    			return err
    		}
    		if err := g.SetKeybinding(b.name.String(), gocui.KeyEnter, gocui.ModNone, b.handler); err != nil {
    			return err
    		}
    		v.SetCursor(1, 1)
    		v.FgColor = b.textColor
    		g.Highlight = true
    		g.SelFgColor = b.borderColor
    		g.Cursor = true
    		fmt.Fprint(v, b.label.String())
    	}
    	return nil
    }
    
    func (b *Button) Resize() *Button {
    	b.w += b.label.Len() + (b.lrpadding * 2)
    	b.h += (b.tbpadding * 2)
    	return b
    }
    
    func (b *Button) Color(borderColor, textColor gocui.Attribute) *Button {
    	b.borderColor = borderColor
    	b.textColor = textColor
    	return b
    }
    
    func NewButton(label string, x, y int, handler ButtonHandler) *Button {
    	ButtonCounter++
    	return &Button{
    		name:      NewText(fmt.Sprintf("#%s_%d", ButtonID, ButtonCounter)),
    		label:     NewText(label),
    		lrpadding: 1,
    		tbpadding: 0,
    		x:         x,
    		y:         y,
    		h:         2,
    		w:         1,
    		handler:   nil,
    	}
    }
    
    
    opened by dzonerzy 0
  • Projects using gocui - Add lazykube

    Projects using gocui - Add lazykube

    https://github.com/TNK-Studio/lazykube

    ⎈ The lazier way to manage kubernetes.

    gif

    opened by elfgzp 0
  • Support maximum number of lines for a view

    Support maximum number of lines for a view

    Added a variable to a View to support capping the number of lines in a lines, defaults to be infinite.

    opened by dsouzae 2
  • force update

    force update

    I used g.Update to append lines to a text box that scrolls - like a tail -f.

    Periodically i remove lines from buffer so the size doesnt grow forever, however the fact that g.Update() creates a go routine leaks lots of memory over time. After a few 10k lines you end up with 10k go routines worth of descriptors in memory that will never be freed.

    Editing the code and changing update to:

    func (g *Gui) Update(f func(*Gui) error) {
    	g.userEvents <- userEvent{f: f}
    }
    

    improves things for me drastically without impacting anything noticable. Can you perhaps tell me the reason why Update does this in a go routine? Might we add a SyncUpdate or similar that doesnt create a go routine?

    opened by ripienaar 6
  • Adding `lazygit` to README

    Adding `lazygit` to README

    opened by keheliya 1
  • Add lazyhub to Projects using gocui

    Add lazyhub to Projects using gocui

    Thank you for good product.

    opened by ryo-ma 0
  • Examples does not support east asian windows?

    Examples does not support east asian windows?

    Hi. It seems that Gocui examples need to be added the code below in main funcs when I build it for Windows 10 (in japanese language). You may already know. Just for info.

    	if runtime.GOOS == "windows" && runewidth.IsEastAsian() {
    		g.ASCII = true
    	}
    
    opened by heri3x 1
Releases(v0.3.0)
Owner
Roi Martin
Roi Martin
Console Text Colors - The non-invasive cross-platform terminal color library does not need to modify the Print method

ctc - Console Text Colors The non-invasive cross-platform terminal color library does not need to modify the Print method Virtual unix-like environmen

null 34 Sep 8, 2021
✨ #PTerm is a modern go module to beautify console output. Featuring charts, progressbars, tables, trees, and many more 🚀 It's completely configurable and 100% cross-platform compatible.

?? PTerm | Pretty Terminal Printer A golang module to print pretty text Show Demo Code PTerm.sh | Installation | Documentation | Quick Start | Example

null 1.9k Sep 26, 2021
Change the color of console text.

go-colortext package This is a package to change the color of the text and background in the console, working both under Windows and other systems. Un

Yi Deng 207 Jul 1, 2021
Intuitive package for prettifying terminal/console output. http://godoc.org/github.com/ttacon/chalk

chalk Chalk is a go package for styling console/terminal output. Check out godoc for some example usage: http://godoc.org/github.com/ttacon/chalk The

Trey Tacon 380 Sep 10, 2021
Terminal string styling for go done right, with full and painless Windows 10 support.

GChalk GChalk is a library heavily inspired by chalk, the popular Node.js terminal color library, and using go ports of supports-color and ansi-styles

Jason Walton 280 Sep 12, 2021
Small library for simple and convenient formatted stylized output to the console.

cfmt cfmt is a small library for simple and convenient formatted stylized output to the console, providing an interface that is exactly the same as th

Makhnev Petr 28 Sep 19, 2021
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.

asciigraph Go package to make lightweight ASCII line graphs ╭┈╯. Installation go get github.com/guptarohit/asciigraph Usage Basic graph package main

Rohit Gupta 1.8k Sep 20, 2021
Golang ultimate ANSI-colors that supports Printf/Sprintf methods

Aurora Ultimate ANSI colors for Golang. The package supports Printf/Sprintf etc. TOC Installation Usage Simple Printf aurora.Sprintf Enable/Disable co

Konstantin Ivanov 1.1k Sep 20, 2021
Yet Another CLi Spinner; providing over 70 easy to use and customizable terminal spinners for multiple OSes

Yet Another CLi Spinner (for Go) Package yacspin provides yet another CLi spinner for Go, taking inspiration (and some utility code) from the https://

Tim Heckman 196 Sep 12, 2021
An ANSI colour terminal package for Go

colourize An ANSI colour terminal package for Go. Supports all ANSI colours and emphasis. Not compatible with Windows systems. Installation go get gi

Trey Bastian 24 Mar 30, 2021
Simple tables in terminal with Go

Simple tables in terminal with Go This package allows to generate and display ascii tables in the terminal, f.e.: +----+------------------+-----------

Alexey Popov 327 Sep 21, 2021
:art: Contextual fmt inspired by bootstrap color classes

Cfmt Contextual fmt It provides contextual formatting functions that have nearly identical usage of the fmt package. The ideas were borrowed from boot

MinJae Kwon 81 Sep 9, 2021
A tiny library for super simple Golang tables

Tabby A tiny library for super simple Golang tables Get Tabby go get github.com/cheynewallace/tabby Import Tabby import "github.com/cheynewallace/tabb

Cheyne Wallace 296 Sep 16, 2021
Building powerful interactive prompts in Go, inspired by python-prompt-toolkit.

go-prompt A library for building powerful interactive prompts inspired by python-prompt-toolkit, making it easier to build cross-platform command line

Masashi SHIBATA 4.1k Sep 23, 2021
Golang terminal dashboard

termui termui is a cross-platform and fully-customizable terminal dashboard and widget library built on top of termbox-go. It is inspired by blessed-c

Zack Guo 11.3k Sep 25, 2021
multi progress bar for Go cli applications

Multi Progress Bar mpb is a Go lib for rendering progress bars in terminal applications. Features Multiple Bars: Multiple progress bars are supported

Vladimir Bauer 1.4k Sep 18, 2021
Terminal based dashboard.

Termdash is a cross-platform customizable terminal based dashboard. The feature set is inspired by the gizak/termui project, which in turn was inspire

Jakub Sobon 1.8k Sep 23, 2021
go-colorable - Colorable writer for windows.

go-colorable Colorable writer for windows. For example, most of logger packages doesn't show colors on windows. (I know we can do it with ansicon. But

mattn 548 Sep 8, 2021