cliui

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2026 License: MIT Imports: 2 Imported by: 0

README

CliUI

GitHub go.mod Go version GitHub tag (latest SemVer) Unit-Tests

English | 简体中文

gookit/cliui is a terminal UI helper module, provides some commonly used display and interactive functional components for CLI.

It focuses on three core areas for CLI applications:

  • show: structured terminal output helpers
  • interact: interactive input helpers
  • progress: progress and loading display helpers

The root package also provides shared input/output helpers used by the subpackages:

  • SetInput(in io.Reader)
  • SetOutput(out io.Writer)
  • CustomIO(in io.Reader, out io.Writer)
  • ResetInput()
  • ResetOutput()
  • ResetIO()

Install

go get github.com/gookit/cliui

Or install a sub package directly:

go get github.com/gookit/cliui/show
go get github.com/gookit/cliui/progress
go get github.com/gookit/cliui/interact

Package Overview

show

Provides structured terminal output helpers for displaying formatted content in CLI applications. It includes table, title, banner, list, multi-list, alert messages and JSON output helpers.

Import:

github.com/gookit/cliui/show

[!NOTE] More Details: docs/show.md

Quick Usage:

package main

import "github.com/gookit/cliui/show"

func main() {
	show.Banner("Deploy started")
	show.AList("App info", map[string]any{
		"name": "cliui",
		"env":  "dev",
	})
	show.JSON(map[string]any{"ok": true})
}
interact

Provides interactive input helpers for CLI programs. It supports prompt, confirm, question, select, multi-select, password input and other common terminal interaction patterns.

It also includes a newer interact/ui layer for backend-driven components:

  • plain backend for line-based input, tests and redirected stdin
  • readline backend for raw terminal interaction
  • Input, Confirm, Select and MultiSelect components
  • UTF-8 input editing, common navigation keys and persistent validation errors

Import:

github.com/gookit/cliui/interact

[!NOTE] More Details: docs/interact.md

Quick Usage:

package main

import (
	"context"
	"fmt"

	"github.com/gookit/cliui/interact"
)

func main() {
	be := interact.NewUIReadlineBackend()

	name, err := interact.NewUIInput("Your name").Run(context.Background(), be)
	if err != nil {
		panic(err)
	}

	env, err := interact.NewUISelect("Choose env", []interact.UIItem{
		{Key: "dev", Label: "Development", Value: "dev"},
		{Key: "prod", Label: "Production", Value: "prod"},
	}).Run(context.Background(), be)
	if err != nil {
		panic(err)
	}

	fmt.Println("name:", name)
	fmt.Println("env:", env.Value)
}
progress

Provides progress and loading display helpers for long-running tasks. It includes progress bars, text bars, spinner/loading indicators, counters, dynamic text output and MultiProgress for rendering multiple bars in one terminal block.

Import:

github.com/gookit/cliui/progress

[!NOTE] More Details: docs/progress.md

Quick Usage:

package main

import (
	"time"

	"github.com/gookit/cliui/progress"
)

func main() {
	p := progress.Bar(100)
	p.Start()

	for i := 0; i < 100; i++ {
		time.Sleep(20 * time.Millisecond)
		p.Advance()
	}

	p.Finish()
}

Migration

If you are migrating from gookit/gcli/v3, the corresponding package paths are:

  • github.com/gookit/gcli/v3/show -> github.com/gookit/cliui/show
  • github.com/gookit/gcli/v3/interact -> github.com/gookit/cliui/interact
  • github.com/gookit/gcli/v3/progress -> github.com/gookit/cliui/progress

Development

go test ./...

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CustomIO

func CustomIO(in io.Reader, out io.Writer)

CustomIO stream

func ResetIO

func ResetIO()

ResetIO stream

func ResetInput

func ResetInput()

ResetInput stream

func ResetOutput

func ResetOutput()

ResetOutput stream

func SetInput

func SetInput(in io.Reader)

SetInput stream

func SetOutput

func SetOutput(out io.Writer)

SetOutput stream

Types

This section is empty.

Directories

Path Synopsis
Package cutypes provides common types, definitions for cliui
Package cutypes provides common types, definitions for cliui
examples
Package interact collect some interactive methods for CLI
Package interact collect some interactive methods for CLI
backend
Package backend defines the runtime abstraction used by interact/ui.
Package backend defines the runtime abstraction used by interact/ui.
backend/fake
Package fake provides an in-memory backend for interaction tests.
Package fake provides an in-memory backend for interaction tests.
backend/plain
Package plain provides a line-based backend for interact/ui.
Package plain provides a line-based backend for interact/ui.
backend/readline
Package readline provides a minimal raw-terminal event backend for interact/ui.
Package readline provides a minimal raw-terminal event backend for interact/ui.
ui
Package ui defines interactive component models built on top of a backend.
Package ui defines interactive component models built on top of a backend.
Package progress provide terminal progress bar display.
Package progress provide terminal progress bar display.
Package show provides some formatter tools for display data.
Package show provides some formatter tools for display data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL