list

package module
v0.0.0-...-e1c2a89 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: MIT Imports: 6 Imported by: 1

README

List Build Status GoDoc Go Report Card

Terminal interactive list

This

options := []string{"Gangsta panda", "Sexy turtle", "Killa gorilla",}

// returns user choice i.e. "Gangsta panda"
list.GetWith("Which animal is the coolest?", options)

Will get you

A bit of flexibility

package main

import (
	"fmt"

	"github.com/fatih/color"
	"github.com/markelog/list"
)

options := []string{"Gangsta panda", "Sexy turtle", "Killa gorilla",}

l := list.New("Which animal is the coolest?", options)

// Set your own printer
l.SetPrint(func(args ...interface{}) (n int, err error) {
	return fmt.Print(args...)
})

// Set your own colors
// With github.com/fatih/color package
l.SetColors(&list.Colors{
	Head:      color.New(color.BgRed),
	Option:    color.New(color.FgGreen, color.Underline),
	Highlight: color.New(color.FgCyan, color.Bold),
})

// Show the list
l.Show()

// Waiting for the user input
l.Get()

Documentation

Overview

Package list for interactive CLI list

Index

Constants

View Source
const (
	// HideCursor ASCII sequence to hide cursor
	HideCursor = "\033[?25l"

	// ShowCursor ASCII sequence for show cursor
	ShowCursor = "\033[?25h"
)

Variables

View Source
var DefaultColors = &Colors{
	Head:      color.New(color.FgWhite, color.Bold),
	Option:    color.New(color.FgWhite),
	Highlight: color.New(color.FgCyan),
}

DefaultColors which will be used by default

Functions

func GetWith

func GetWith(name string, options []string) string

GetWith will call .New(...); .Show() and returns .Get()

Types

type Colors

type Colors struct {
	Head,
	Option,
	Highlight *color.Color
}

Colors settings

type List

type List struct {
	Index  int
	Print  Printer
	Cursor *curse.Cursor
	// contains filtered or unexported fields
}

List base struct

func New

func New(name string, options []string) *List

New returns a list initialized with Default theme.

func (*List) ClearOptions

func (list *List) ClearOptions()

ClearOptions clears options from console

func (*List) Enter

func (list *List) Enter() string

Enter key handler

func (*List) Exit

func (list *List) Exit()

Exit Ctrl + (C | D | Z) and alike handler

func (*List) Get

func (list *List) Get() string

Get result

func (*List) HighlightDown

func (list *List) HighlightDown() *List

HighlightDown highlights option below

func (*List) HighlightUp

func (list *List) HighlightUp() *List

HighlightUp highlights option above

func (*List) PrintHead

func (list *List) PrintHead() int

PrintHead prints list header

func (*List) PrintHighlight

func (list *List) PrintHighlight(element string) int

PrintHighlight prints highlighted list element

func (*List) PrintOption

func (list *List) PrintOption(option string) int

PrintOption prints list option

func (*List) PrintResult

func (list *List) PrintResult(result string) int

PrintResult prints list header and choosen option

func (*List) Println

func (list *List) Println() int

Println just prints "\n"

func (*List) SetChooser

func (list *List) SetChooser(chooser string)

SetChooser sets chooser string i.e. " ❯ "

func (*List) SetColors

func (list *List) SetColors(colors *Colors)

SetColors sets colors for the output

func (*List) SetIndent

func (list *List) SetIndent(indent int)

SetIndent sets indent before options

func (*List) SetPrint

func (list *List) SetPrint(print Printer)

SetPrint set print function

func (*List) Show

func (list *List) Show() int

Show list

func (*List) ShowOptions

func (list *List) ShowOptions() int

ShowOptions shows options

type Printer

type Printer func(...interface{}) (int, error)

Printer function type used for outputing

Jump to

Keyboard shortcuts

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