Minimalist Go package aimed at creating Console User Interfaces.

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! :)

Comments
  • 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?

  • 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 ?

  • 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.

  • 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.

  • 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.

  • 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

  • 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
    
  • 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!

  • 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.

  • 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)

  • 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!

  • 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!

  • 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.

  • 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.

Small library for simple and convenient formatted stylized output to the console.
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

Jan 7, 2023
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

Nov 9, 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

Oct 26, 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 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

Dec 27, 2022
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.
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

Jan 1, 2023
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

Sep 26, 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

Oct 23, 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

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

Sep 14, 2022
Turtorial - A Hard Fork Of Icexin's Great Gocraft Project Aimed At Learning Basic Programming Tasks Through Turtles
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

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

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.

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/

Jan 2, 2022
Feb 7, 2022
Go package providing simple database and server interfaces for the CSV files produced by the sfomuseum/go-libraryofcongress package
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

Oct 29, 2021
A simple cli tool for switching git user easily inspired by Git-User-Switch
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

Dec 31, 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

Dec 9, 2021
Gum - Git User Manager (GUM) - Switch between git user profiles
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

Feb 14, 2022
Go-user-service - User creation with Kafka producer

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

Aug 19, 2022
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

Nov 12, 2022