box

package module
v3.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: BSD-3-Clause Imports: 11 Imported by: 4

README

Go-Box - Interactive item selector

Go Test License Go Reference

Note: This is the documentation for go-box v3.
If your code still imports github.com/nyaosorg/go-box or /v2,
please update the import path to github.com/nyaosorg/go-box/v3.

box - Executable

box is a command-line program built with the go-box library.
It reads a list of items from STDIN and lets the user select one interactively.

demo

Install

Download the binary package from Releases and extract the executable.

Use "go install"
go install github.com/nyaosorg/go-box/v3/cmd/box@latest
Use "scoop-installer"
scoop install https://raw.githubusercontent.com/nyaosorg/go-box/master/box.json

or

scoop bucket add hymkor https://github.com/hymkor/scoop-bucket
scoop install box

go-box - golang package

package main

import (
    "os"

    "github.com/nyaosorg/go-box/v3"
)

func main() {
    println("Are you sure ?")
    choose, err := box.SelectString([]string{"Yes", "No"}, false, os.Stderr)
    if err != nil {
        println(err.Error())
        os.Exit(1)
    }
    println()
    if len(choose) >= 1 {
        println("You selected ->", choose[0])
    } else {
        println("You did not select any items")
    }
}

Release notes

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Println

func Println(nodes []string, out io.Writer) error

Println outputs the given items in a tabular layout and appends a newline after the final line.

func SelectIndex

func SelectIndex(sources []string, multi bool, out io.Writer) ([]int, error)

SelectIndex returns the indexes that user selected.

func SelectString

func SelectString(sources []string, multi bool, out io.Writer) ([]string, error)

SelectString returns the strings that user selected.

Types

type Box

type Box struct {
	grid.Grid
	ttyadapter.Tty
}

func New

func New() (*Box, error)

New creates and initializes a Box using the default terminal backend (tty8pe). It is equivalent to creating a Box with &tty8pe.Tty{} and calling Open().

Example:

b, err := box.New()
if err != nil {
	log.Fatal(err)
}
defer b.Close()

Use this function when you do not need to customize the terminal input.

func (*Box) Open

func (b *Box) Open() error

Open initializes the Box with the terminal backend assigned to b.Tty. This method is used when you want to provide a custom TTY implementation instead of the default one created by New().

Example:

import "github.com/nyaosorg/go-ttyadapter/auto"

b := &box.Box{
	Tty: &auto.Pilot{Text: []string{"l", "l", "\r"}},
}
if err := b.Open(); err != nil {
	log.Fatal(err)
}
defer b.Close()

func (*Box) SelectIndex

func (b *Box) SelectIndex(sources []string, multi bool, out io.Writer) ([]int, error)

SelectIndex returns the indexes that user selected.

func (*Box) SelectString

func (b *Box) SelectString(sources []string, multi bool, out io.Writer) ([]string, error)

SelectString returns the strings that user selected.

Directories

Path Synopsis
cmd
box command
internal

Jump to

Keyboard shortcuts

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