Minimalist Go package aimed at creating Console User Interfaces.

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
  • 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
  • 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
  • Example is outdate

    Example is outdate

    Main page example does not compile under last release v0.3.0

    .\main.go:11:9: assignment mismatch: 2 variables but 1 values
    .\main.go:11:24: too many arguments in call to gocui.NewGui
    .\main.go:11:25: undefined: gocui.OutputNormal
    
    opened by vit1251 7
  • The layout is skewed on Windows

    The layout is skewed on Windows

    I built this sample code and ran on Windows 7. https://github.com/jroimartin/gocui#example

    The layout is skewed. How can I avoid this?

    2017-03-25 16 44 50

    Thank you for the awesome library!

    duplicate 
    opened by knqyf263 7
  • Support zero parameteter 'CSI n m' in parseOne

    Support zero parameteter 'CSI n m' in parseOne

    According to https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes, a zero-parameter 'CSI n m' code (for setting SGR parameters) should be treated as the same as 'CSI 0 m'. This PR changes escapeInterpreter.parseOne to support this shorthand.

    opened by nwidger 7
  • view.Line(n) contains

    view.Line(n) contains "\x00" at end

    I need to get the text a line n but len(line) is off because of "\x00" at end of line.

    Example: line := v.Line(n) if len(line) > 10 { // Do something }

    The above doesn't work as expected because len is off by 1. Would be nice if Line func would do the following before it returns value:

    strings.Replace(lineValue, "\x00", "", -1)

    bug 
    opened by kkellner 7
  • Keybinding prints key when switching to editable view.

    Keybinding prints key when switching to editable view.

    I am trying to write some code that edits a view with vim like key-bindings. The problem I am running into is the key I press is also getting inserted. I have put together some test code to hopefully explain better.

    package main
    
    import (
        "log"
        "github.com/jroimartin/gocui"
    )
    
    func edit(g *gocui.Gui, v *gocui.View) error {
        v.Editable = true
        return nil
    }
    
    func quit(g *gocui.Gui, v *gocui.View) error {
        return gocui.ErrQuit
    }
    
    func keybindings(g *gocui.Gui) error {
        if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {return err}
        if err := g.SetKeybinding("main", 'i', gocui.ModNone, edit); err != nil {return err}
    
        return nil
    }
    
    
    func layout(g *gocui.Gui) error {
        maxX, maxY := g.Size()
        if v, err := g.SetView("main", 30, -1, maxX, maxY); err != nil {
            if err != gocui.ErrUnknownView {
                return err
            }
    
            v.Editable = false
            v.Wrap = true
            if _, err := g.SetCurrentView("main"); err != nil {return err}
        }
        return nil
    }
    
    func main() {
        g, _ := gocui.NewGui()
        defer g.Close()
    
        g.SetManagerFunc(layout)
        keybindings(g); 
        g.Cursor = true
    
        if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {log.Panicln(err)}
    }
    

    What happens is when I press the 'i' key to change the main view from not-Editable to Editable it also inserts an i character. Is there a way to prevent this?

    Thank you for any help!

    opened by thekeymaker 7
  • Add Omnivore to projects list.

    Add Omnivore to projects list.

    Hey! Was wondering if it would be possible to add my project to the "projects using gocui" list?

    https://github.com/DiscoRiver/omnivore

    Thanks!

    opened by DiscoRiver 0
  • how to read input

    how to read input

    i want to let app read some inputs of number-key. finally when user entered enter-key, app will run a function. i hope the inputs of number-key do not echo in screen when user presses number-key.

    opened by liyoubdu 0
  • Added lazygit to list of projects in README

    Added lazygit to list of projects in README

    I am not the author of lazygit, but I use it daily and find it to be the absolute best git-gui out there. It really deserves mentioning on your list of projects using GOCUI.

    opened by carstengehling 2
  • 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
Releases(v0.3.0)
Owner
Roi Martin
Roi Martin
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 42 Jun 23, 2022
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 38 Jul 1, 2022
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 210 Mar 8, 2022
✨ #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 2.8k Jun 30, 2022
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 2k Jul 1, 2022
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 25 Mar 8, 2022
Generate TypeScript interfaces from Go structs/interfaces - useful for JSON RPC

bel Generate TypeScript interfaces from Go structs/interfaces - useful for JSON RPC bel is used in production in https://gitpod.io. Getting started be

Christian Weichel 24 Jun 13, 2022
Golang-Devnet-Interfaces - Quick example of using Scrapligo and TextFSM to parse interfaces from Devnet Sandbox

Scrapligo & TextFSM This is a simple example of using the Scrapligo library deve

null 4 Mar 7, 2022
Dabulang is an interpreted object-oriented programming language aimed towards game development.

Dabulang (ダブ言語) Dabulang is an interpreted object-oriented programming language aimed towards game development. The language's standard library has a

Job Vonk 1 Apr 21, 2022
Turtorial - A Hard Fork Of Icexin's Great Gocraft Project Aimed At Learning Basic Programming Tasks Through Turtles

TURTORIAL A voxel sandbox-survival game aimed at teaching the basics of programm

Joshua Steven Grant 1 Jan 25, 2022
git-glimpse is a command-line tool that is aimed at generating a git prompt like the one from zsh-vcs-prompt.

Git GoGlimpse git-glimpse is a command-line tool that is aimed at generating a git prompt like the one from zsh-vcs-prompt. The particularity of this

Corentin de Boisset 0 Jan 27, 2022
mlp is a comman line tool responsible for creating, updating and deleting kubernetes resources based on files generated by Mia-Platform Console.

mlp is a comman line tool responsible for creating, updating and deleting kubernetes resources based on files generated by Mia-Platform Console.

Mia-Platform 5 Apr 28, 2022
Console - Commands are defined in struct extending pkg/command/create user.go

Console Creating a Command Commands are defined in struct extending pkg/command/

null 0 Jan 2, 2022
null 2 Feb 7, 2022
Go package providing simple database and server interfaces for the CSV files produced by the sfomuseum/go-libraryofcongress package

go-libraryofcongress-database Go package providing simple database and server interfaces for the CSV files produced by the sfomuseum/go-libraryofcongr

San Francisco International Airport Museum 1 Oct 29, 2021
Go package that interfaces with AWS System Manager

go-aws-ssm Go package that interfaces with AWS System Manager. Why to use go-aws-ssm and not the aws-sdk-go? This package is wrapping the aws-sdk-go a

Paddle 50 May 31, 2022
Go package to simulate bandwidth, latency and packet loss for net.PacketConn and net.Conn interfaces

lossy Go package to simulate bandwidth, latency and packet loss for net.PacketConn and net.Conn interfaces. Its main usage is to test robustness of ap

Cevat Barış Yılmaz 307 Jun 4, 2022
Turbine-common - This package contains the common interfaces for Turbine that are shared with other software

turbine-common This package contains the common interfaces for Turbine that are

NoraSector 3 Feb 12, 2022
Godaddy - This package implements the libdns interfaces for the Godaddy API

Godaddy for libdns This package implements the libdns interfaces for the Godaddy

null 1 Jan 26, 2022
A simple cli tool for switching git user easily inspired by Git-User-Switch

gitsu A simple cli tool for switching git user easily inspired by Git-User-Switch Installation Binary releases are here. Homebrew brew install matsuyo

Masaya Watanabe 200 May 15, 2022
App with CRUD for user, with palindrome checker for user's first and last name

Run db container first, so that app does not connect to db while db has not started yet docker-compose up -d db docker-compose up -d app CRUD endpoint

Vinh Tran 0 Dec 9, 2021
Gum - Git User Manager (GUM) - Switch between git user profiles

Git User Manager (GUM) Add your profile info to config.yaml Build project: go bu

Mehmet Tevfik YÜKSEL 6 Feb 14, 2022
Go-user-service - User creation with Kafka producer

?? The Project This project is a simple user API developed to study microservice

Gustavo Belmonte Cioccari 0 Feb 2, 2022
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 396 Jun 15, 2022
A minimalist Go configuration library

fig fig is a tiny library for loading an application's config file and its environment into a Go struct. Individual fields can have default values def

null 214 Jun 21, 2022
High-performance minimalist queue implemented using a stripped-down lock-free ringbuffer, written in Go (golang.org)

This project is no longer maintained - feel free to fork the project! gringo A high-performance minimalist queue implemented using a stripped-down loc

Darren Elwood 126 Jun 8, 2022
High performance, minimalist Go web framework

Supported Go versions As of version 4.0.0, Echo is available as a Go module. Therefore a Go version capable of understanding /vN suffixed imports is r

LabStack LLC 22.7k Jun 24, 2022
🔊Minimalist message bus implementation for internal communication

?? Bus Bus is a minimalist event/message bus implementation for internal communication. It is heavily inspired from my event_bus package for Elixir la

Mustafa Turan 266 Jun 16, 2022
:notes: Minimalist websocket framework for Go

melody ?? Minimalist websocket framework for Go. Melody is websocket framework based on github.com/gorilla/websocket that abstracts away the tedious p

Ola 2.5k Jun 26, 2022