interact

package
v0.0.0-...-48b6be6 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package interact provides implementations for some basic interaction that aims to make cli program a bit more pretty and let it easy to use.

This package will be splitted to a standalone repository in the future.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewToPreviouswithErr

func NewToPreviouswithErr(err error) error

NewToPreviouswithErr warps error to ToPrevious.

func ScanInputAndCheck

func ScanInputAndCheck() int

ScanInputAndCheck scans user input with check.

It returns -1 if input is not a number or is less than 0.

If nothing is input, return -2

func ScantoSting

func ScantoSting() string

ScantoSting scans user input to string.

Types

type Choice

type Choice interface {
	Desc() string
	Run() (output func(), err error)
}

Choice defines the basic abilities of Choice node.

This interface might be extended in the future.

func NewChoice

func NewChoice(desc string, function func() (func(), error)) Choice

NewChoice returns a Choice node.

type ChoiceHanlder

type ChoiceHanlder func() (func(), error)

ChoiceHanlder defines function signature of a vaild choice function.

type Choose

type Choose struct {
	Title                string
	Choices              []Choice
	Loop                 bool
	ToPreviousChooseDesc string

	// TODO
	ToNextPageDesc *Choice
	// TODO
	ToPreviousPageDesc *Choice
}

Choose defines essential fields to let this interaction work.

func (*Choose) Do

func (c *Choose) Do() (func(), error)

Do the interaction.

func (*Choose) ToClosure

func (c *Choose) ToClosure() ChoiceHanlder

ToClosure warps the Choose interaction to a ChoiceHanlder. It can be used to create a nesting choose interaction.

type DefaultChoice

type DefaultChoice struct {
	Description string
	Function    ChoiceHanlder
}

DefaultChoice implements Choice interface with essential fields.

func (*DefaultChoice) Desc

func (c *DefaultChoice) Desc() string

Desc returnn description

func (*DefaultChoice) Run

func (c *DefaultChoice) Run() (func(), error)

Run the choose.

type Element

type Element interface {
	Do() error
}

type ToPrevious

type ToPrevious struct {
	Err error
}

ToPrevious implements error interface that let app step out current choose loop.

func (*ToPrevious) Error

func (e *ToPrevious) Error() string

Jump to

Keyboard shortcuts

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