box

package module
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: BSD-3-Clause Imports: 12 Imported by: 1

README

Go-Box - Interactive item selector

box - Executable

  • box reads choices from STDIN,
  • On box, the user selects one by cursor (HJKL , C-n & C-p & C-f & C-b)
  • box outputs chosen one to STDOUT.

demo

Install

Download the binary package from Releases and extract the executable.

Use "go install"
go install github.com/nyaosorg/go-box/v2/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/v2"
)

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")
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AnsiCutter = regexp.MustCompile("\x1B[^a-zA-Z]*[A-Za-z]")

Functions

func Choice deprecated

func Choice(sources []string, out io.Writer) string

Deprecated: Choice returns returns the string that user selected.

func ChoiceMulti deprecated

func ChoiceMulti(sources []string, out io.Writer) []string

Deprecated: ChoiceMulti returns the strings that user selected.

func Choose deprecated

func Choose(sources []string, out io.Writer) int

Deprecated: Choose returns the index that user selected

func ChooseMulti deprecated

func ChooseMulti(sources []string, out io.Writer) []int

Deprecated: Choose Multi returns the indices that user selected.

func Print deprecated

func Print(ctx context.Context, nodes []string, out io.Writer) bool

Deprecated:

func PrintNoLastLineFeed deprecated added in v2.2.1

func PrintNoLastLineFeed(ctx context.Context,
	nodes []string,
	offset int,
	out io.Writer) (bool, int, int)

Deprecated:

func PrintX added in v2.2.0

func PrintX(ctx context.Context, nodes []string, out io.Writer) error

PrintX outputs items in a tabular format

func SelectIndex added in v2.2.0

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

SelectIndex returns the indexes that user selected.

func SelectIndexContext added in v2.2.1

func SelectIndexContext(ctx context.Context, sources []string, multi bool, out io.Writer) ([]int, error)

func SelectString added in v2.2.0

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

SelectString returns the strings that user selected.

func SelectStringContext added in v2.2.1

func SelectStringContext(ctx context.Context, sources []string, multi bool, out io.Writer) ([]string, error)

Types

type Box added in v2.2.0

type Box struct {
	// contains filtered or unexported fields
}

func New deprecated

func New() *Box

Deprecated:

func NewBox added in v2.2.0

func NewBox() (*Box, error)

func (*Box) Close added in v2.2.0

func (b *Box) Close() error

func (*Box) Print deprecated added in v2.2.0

func (b *Box) Print(ctx context.Context,
	nodes []string,
	offset int,
	out io.Writer) (bool, int, int)

Deprecated:

func (*Box) PrintNoLastLineFeed deprecated added in v2.2.0

func (b *Box) PrintNoLastLineFeed(ctx context.Context,
	nodes []string,
	offset int,
	out io.Writer) (bool, int, int)

Deprecated:

func (*Box) PrintNoLastLineFeedX added in v2.2.0

func (b *Box) PrintNoLastLineFeedX(ctx context.Context,
	nodes []string,
	offset int,
	out io.Writer) (int, int, error)

PrintNoLastLineFeedX outputs items in a tabular format, but removes the last line feed

func (*Box) PrintX added in v2.2.0

func (b *Box) PrintX(ctx context.Context,
	nodes []string,
	offset int,
	out io.Writer) (int, int, error)

PrintX outputs items in a tabular format

func (*Box) SelectIndex added in v2.2.0

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

SelectIndex returns the indexes that user selected.

func (*Box) SelectIndexContext added in v2.2.1

func (b *Box) SelectIndexContext(ctx context.Context, sources []string, multi bool, out io.Writer) ([]int, error)

func (*Box) SelectString added in v2.2.0

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

SelectString returns the strings that user selected.

func (*Box) SelectStringContext added in v2.2.1

func (b *Box) SelectStringContext(ctx context.Context, sources []string, multi bool, out io.Writer) ([]string, error)

type BoxT deprecated

type BoxT = Box

Deprecated:

Directories

Path Synopsis
cmd
box
internal

Jump to

Keyboard shortcuts

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