Top Related Projects
Terminal UI library with rich, interactive widgets — written in Golang
Tcell is an alternate terminal package, similar in some ways to termbox, but better in others.
Golang terminal dashboard
Pure Go termbox implementation
A UI library for terminal applications.
A powerful little TUI framework 🏗
Quick Overview
Gocui is a minimalist Go package that provides a powerful and flexible framework for creating console user interfaces. It allows developers to build terminal-based applications with interactive layouts, widgets, and event handling capabilities.
Pros
- Lightweight and efficient, with minimal dependencies
- Supports custom layouts and flexible widget positioning
- Provides event-driven programming model for handling user input
- Offers cross-platform compatibility for Unix-like systems and Windows
Cons
- Limited built-in widgets compared to more comprehensive GUI libraries
- Steeper learning curve for developers new to terminal-based UIs
- Documentation could be more extensive and include more examples
- Not actively maintained (last commit was in 2019)
Code Examples
- Creating a basic view:
g, err := gocui.NewGui(gocui.OutputNormal)
if err != nil {
// Handle error
}
defer g.Close()
g.SetManager(gocui.ManagerFunc(layout))
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
// Handle error
}
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
}
- Adding a keybinding:
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
// Handle error
}
func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}
- Handling mouse events:
g.Mouse = true
if err := g.SetKeybinding("", gocui.MouseLeft, gocui.ModNone, onClick); err != nil {
// Handle error
}
func onClick(g *gocui.Gui, v *gocui.View) error {
if v != nil {
cx, cy := v.Cursor()
fmt.Printf("Clicked at (%d, %d)\n", cx, cy)
}
return nil
}
Getting Started
To use Gocui in your Go project, follow these steps:
-
Install the package:
go get github.com/jroimartin/gocui
-
Import the package in your Go file:
import "github.com/jroimartin/gocui"
-
Create a new Gui instance and set up your layout:
g, err := gocui.NewGui(gocui.OutputNormal) if err != nil { // Handle error } defer g.Close() g.SetManager(gocui.ManagerFunc(layout)) if err := g.MainLoop(); err != nil && err != gocui.ErrQuit { // Handle error }
-
Implement your layout function and add views, keybindings, and event handlers as needed.
Competitor Comparisons
Terminal UI library with rich, interactive widgets — written in Golang
Pros of tview
- More feature-rich with a wider range of UI elements and widgets
- Better documentation and examples for easier learning and implementation
- Active development and maintenance with frequent updates
Cons of tview
- Slightly more complex API, which may require a steeper learning curve
- Larger codebase and dependencies, potentially increasing project size
Code Comparison
gocui example:
g, err := gocui.NewGui(gocui.OutputNormal)
if err != nil {
log.Panicln(err)
}
defer g.Close()
tview example:
app := tview.NewApplication()
box := tview.NewBox().SetBorder(true).SetTitle("Hello, world!")
if err := app.SetRoot(box, true).Run(); err != nil {
panic(err)
}
Both libraries offer terminal-based UI creation in Go, but tview provides a more comprehensive set of features and widgets. gocui focuses on simplicity and low-level control, while tview offers a higher-level API with more built-in functionality. The choice between them depends on the specific requirements of your project and your preference for API complexity versus feature richness.
Tcell is an alternate terminal package, similar in some ways to termbox, but better in others.
Pros of tcell
- More comprehensive and lower-level terminal handling, offering greater flexibility
- Better support for a wider range of terminal types and color schemes
- Active development and maintenance, with regular updates and improvements
Cons of tcell
- Steeper learning curve due to its lower-level nature
- Requires more code to create complex UI layouts compared to gocui
Code comparison
gocui example:
g, err := gocui.NewGui(gocui.OutputNormal)
if err != nil {
log.Panicln(err)
}
defer g.Close()
tcell example:
s, err := tcell.NewScreen()
if err != nil {
log.Fatalf("%+v", err)
}
if err := s.Init(); err != nil {
log.Fatalf("%+v", err)
}
Summary
tcell is a more powerful and flexible terminal handling library, offering greater control and compatibility with various terminal types. However, it requires more effort to create complex UIs compared to gocui, which provides higher-level abstractions for building text-based user interfaces. gocui may be easier to use for simpler projects, while tcell is better suited for more complex terminal applications that require fine-grained control over the display and input handling.
Golang terminal dashboard
Pros of termui
- More visually appealing and feature-rich UI components (charts, gauges, sparklines)
- Better suited for data visualization and dashboard-style applications
- Easier to create complex layouts with built-in grid system
Cons of termui
- Steeper learning curve due to more complex API
- Less flexible for creating custom widgets or modifying existing ones
- Larger codebase and dependencies, potentially impacting performance
Code Comparison
termui example:
ui.Init()
p := widgets.NewParagraph()
p.Text = "Hello World!"
ui.Render(p)
gocui example:
g, _ := gocui.NewGui(gocui.OutputNormal)
v, _ := g.SetView("hello", 1, 1, 22, 3)
fmt.Fprintln(v, "Hello World!")
Summary
termui excels in creating visually appealing dashboards and data visualizations with its rich set of pre-built components. It's ideal for applications that require complex layouts and graphical elements. However, it may be overkill for simpler text-based interfaces.
gocui, on the other hand, offers a more lightweight and flexible approach to building terminal UIs. It provides greater control over individual views and is better suited for applications that require custom widgets or fine-grained control over the interface. While it may require more code for complex layouts, it offers better performance and a gentler learning curve for basic terminal UI development.
Pure Go termbox implementation
Pros of termbox-go
- Lower-level library, offering more flexibility and control over terminal input/output
- Simpler API, making it easier to get started for basic terminal applications
- Supports a wider range of terminal types and configurations
Cons of termbox-go
- Lacks built-in support for creating complex UI layouts and widgets
- Requires more manual handling of screen updates and event processing
- Less suitable for creating sophisticated TUI applications without additional effort
Code Comparison
termbox-go:
err := termbox.Init()
if err != nil {
panic(err)
}
defer termbox.Close()
termbox.SetOutputMode(termbox.Output256)
gocui:
g, err := gocui.NewGui(gocui.OutputNormal)
if err != nil {
log.Panicln(err)
}
defer g.Close()
g.SetManagerFunc(layout)
Summary
termbox-go is a lower-level library that provides more direct control over terminal I/O, making it suitable for simpler applications or as a foundation for building more complex TUI frameworks. gocui, on the other hand, offers a higher-level abstraction with built-in support for creating sophisticated terminal user interfaces, including layouts and widgets. The choice between the two depends on the complexity of the desired application and the level of control required over terminal operations.
A UI library for terminal applications.
Pros of tui-go
- More modern and actively maintained
- Better documentation and examples
- Simpler API, easier to get started with
Cons of tui-go
- Less feature-rich compared to gocui
- Fewer built-in widgets and layout options
- May require more custom code for complex UIs
Code Comparison
tui-go:
box := tui.NewVBox(
tui.NewLabel("Hello, world!"),
tui.NewLabel("Press q to quit."),
)
ui, err := tui.New(box)
if err != nil {
log.Fatal(err)
}
gocui:
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)
}
The code comparison shows that tui-go has a more straightforward approach to creating UI elements and initializing the application. gocui requires more setup code and uses a manager function for layout, which can be more flexible but also more complex for beginners.
Both libraries have their strengths, with tui-go being more beginner-friendly and gocui offering more advanced features for complex terminal UIs.
A powerful little TUI framework 🏗
Pros of Bubbletea
- More modern and actively maintained
- Simpler API with a focus on composability
- Better support for keyboard input and mouse events
Cons of Bubbletea
- Steeper learning curve due to its unique approach
- Less fine-grained control over UI elements compared to Gocui
Code Comparison
Gocui example:
g, err := gocui.NewGui(gocui.OutputNormal)
if err != nil {
log.Panicln(err)
}
defer g.Close()
g.SetManagerFunc(layout)
Bubbletea example:
p := tea.NewProgram(initialModel())
if err := p.Start(); err != nil {
fmt.Printf("Alas, there's been an error: %v", err)
os.Exit(1)
}
Both libraries offer ways to create terminal user interfaces in Go, but they differ in their approach. Gocui provides a more traditional, low-level API for creating views and handling events, while Bubbletea uses a more modern, state-based approach inspired by The Elm Architecture. Bubbletea's design makes it easier to create complex, interactive applications, but it may require developers to think differently about UI construction. Gocui, on the other hand, offers more direct control over the UI elements but may require more boilerplate code for complex interactions.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
GOCUI - Go Console User Interface
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 pkg.go.dev 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
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! :)
Top Related Projects
Terminal UI library with rich, interactive widgets — written in Golang
Tcell is an alternate terminal package, similar in some ways to termbox, but better in others.
Golang terminal dashboard
Pure Go termbox implementation
A UI library for terminal applications.
A powerful little TUI framework 🏗
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot