From a0c2cee8533e6752e043b785080d8017626e5627 Mon Sep 17 00:00:00 2001 From: SonarBeserk Date: Sun, 29 Oct 2023 19:45:43 -0400 Subject: [PATCH] Go fmt all files --- clearScreen.go | 2 +- error.go | 16 +++---- menu.go | 114 ++++++++++++++++++++++++------------------------- option.go | 4 +- 4 files changed, 68 insertions(+), 68 deletions(-) diff --git a/clearScreen.go b/clearScreen.go index 5d5f645..a8d4c60 100644 --- a/clearScreen.go +++ b/clearScreen.go @@ -36,7 +36,7 @@ func init() { } } -//Clear simply clears the command line interface (os.Stdout only). +// Clear simply clears the command line interface (os.Stdout only). func Clear() { value, ok := clear[runtime.GOOS] if ok { diff --git a/error.go b/error.go index 7cf52ce..c1ce994 100644 --- a/error.go +++ b/error.go @@ -16,14 +16,14 @@ var ( ErrDuplicate = errors.New("duplicated response") ) -//MenuError records menu errors +// MenuError records menu errors type MenuError struct { Err error Res string TriesLeft int } -//Error prints the error in an easy to read string. +// Error prints the error in an easy to read string. func (e *MenuError) Error() string { if e.Res != "" { return e.Err.Error() + ": " + e.Res @@ -39,7 +39,7 @@ func newMenuError(err error, res string, tries int) *MenuError { } } -//IsInvalidErr checks to see if err is of type invalid error returned by menu. +// IsInvalidErr checks to see if err is of type invalid error returned by menu. func IsInvalidErr(err error) bool { e, ok := err.(*MenuError) if ok && e.Err == ErrInvalid { @@ -48,7 +48,7 @@ func IsInvalidErr(err error) bool { return false } -//IsNoResponseErr checks to see if err is of type no response returned by menu. +// IsNoResponseErr checks to see if err is of type no response returned by menu. func IsNoResponseErr(err error) bool { e, ok := err.(*MenuError) if ok && e.Err == ErrNoResponse { @@ -57,7 +57,7 @@ func IsNoResponseErr(err error) bool { return false } -//IsTooManyErr checks to see if err is of type too many returned by menu. +// IsTooManyErr checks to see if err is of type too many returned by menu. func IsTooManyErr(err error) bool { e, ok := err.(*MenuError) if ok && e.Err == ErrTooMany { @@ -66,7 +66,7 @@ func IsTooManyErr(err error) bool { return false } -//IsDuplicateErr checks to see if err is of type duplicate returned by menu. +// IsDuplicateErr checks to see if err is of type duplicate returned by menu. func IsDuplicateErr(err error) bool { e, ok := err.(*MenuError) if ok && e.Err == ErrDuplicate { @@ -75,8 +75,8 @@ func IsDuplicateErr(err error) bool { return false } -//IsMenuErr checks to see if it is a menu err. -//This is a general check not a specific one. +// IsMenuErr checks to see if it is a menu err. +// This is a general check not a specific one. func IsMenuErr(err error) bool { _, ok := err.(*MenuError) return ok diff --git a/menu.go b/menu.go index 2e62068..25ba286 100644 --- a/menu.go +++ b/menu.go @@ -1,10 +1,10 @@ -//Package wmenu creates menus for cli programs. -//It uses wlog for it's interface with the command line. -//It uses os.Stdin, os.Stdout, and os.Stderr with concurrency by default. -//wmenu allows you to change the color of the different parts of the menu. -//This package also creates it's own error structure so you can type assert if you need to. -//wmenu will validate all responses before calling any function. -//It will also figure out which function should be called so you don't have to. +// Package wmenu creates menus for cli programs. +// It uses wlog for it's interface with the command line. +// It uses os.Stdin, os.Stdout, and os.Stderr with concurrency by default. +// wmenu allows you to change the color of the different parts of the menu. +// This package also creates it's own error structure so you can type assert if you need to. +// wmenu will validate all responses before calling any function. +// It will also figure out which function should be called so you don't have to. package wmenu import ( @@ -19,7 +19,7 @@ import ( "github.com/mattn/go-isatty" ) -//DefaultYN is used to specify what the default answer is to a yes/no question. +// DefaultYN is used to specify what the default answer is to a yes/no question. type DefaultYN int const ( @@ -34,8 +34,8 @@ var ( (!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd())) ) -//Menu is used to display options to a user. -//A user can then select options and Menu will validate the response and perform the correct action. +// Menu is used to display options to a user. +// A user can then select options and Menu will validate the response and perform the correct action. type Menu struct { question string function func([]Opt) error @@ -53,7 +53,7 @@ type Menu struct { initialIndex int } -//NewMenu creates a menu with a wlog.UI as the writer. +// NewMenu creates a menu with a wlog.UI as the writer. func NewMenu(question string) *Menu { //Create a default ui to use for menu var ui wlog.UI @@ -77,11 +77,11 @@ func NewMenu(question string) *Menu { } } -//AddColor will change the color of the menu items. -//optionColor changes the color of the options. -//questionColor changes the color of the questions. -//errorColor changes the color of the question. -//Use wlog.None if you do not want to change the color. +// AddColor will change the color of the menu items. +// optionColor changes the color of the options. +// questionColor changes the color of the questions. +// errorColor changes the color of the question. +// Use wlog.None if you do not want to change the color. func (m *Menu) AddColor(optionColor, questionColor, responseColor, errorColor wlog.Color) { if !noColor { m.ui = wlog.AddColor(questionColor, errorColor, wlog.None, wlog.None, optionColor, responseColor, wlog.None, wlog.None, wlog.None, m.ui) @@ -93,40 +93,40 @@ func (m *Menu) PadOptionID() { m.padOptionID = true } -//ClearOnMenuRun will clear the screen when a menu is ran. -//This is checked when LoopOnInvalid is activated. -//Meaning if an error occurred then it will clear the screen before asking again. +// ClearOnMenuRun will clear the screen when a menu is ran. +// This is checked when LoopOnInvalid is activated. +// Meaning if an error occurred then it will clear the screen before asking again. func (m *Menu) ClearOnMenuRun() { m.clear = true } -//SetSeparator sets the separator to use when multiple options are valid responses. -//Default value is a space. +// SetSeparator sets the separator to use when multiple options are valid responses. +// Default value is a space. func (m *Menu) SetSeparator(sep string) { m.multiSeparator = sep } -//SetTries sets the number of tries on the loop before failing out. -//Default is 3. -//Negative values act like 0. +// SetTries sets the number of tries on the loop before failing out. +// Default is 3. +// Negative values act like 0. func (m *Menu) SetTries(i int) { m.tries = i } -//LoopOnInvalid is used if an invalid option was given then it will prompt the user again. +// LoopOnInvalid is used if an invalid option was given then it will prompt the user again. func (m *Menu) LoopOnInvalid() { m.loopOnInvalid = true } -//SetDefaultIcon sets the icon used to identify which options will be selected by default +// SetDefaultIcon sets the icon used to identify which options will be selected by default func (m *Menu) SetDefaultIcon(icon string) { m.defIcon = icon } -//IsYesNo sets the menu to a yes/no state. -//Does not show options but does ask question. -//Will also parse the answer to allow for all variants of yes/no (IE Y yes No ...) -//Both will call the Action function you specified. +// IsYesNo sets the menu to a yes/no state. +// Does not show options but does ask question. +// Will also parse the answer to allow for all variants of yes/no (IE Y yes No ...) +// Both will call the Action function you specified. // Opt{ID: 1, Text: "y"} for yes and Opt{ID: 2, Text: "n"} for no will be passed to the function. func (m *Menu) IsYesNo(def DefaultYN) { m.isYN = true @@ -138,43 +138,43 @@ func (m *Menu) InitialIndex(index int) { m.initialIndex = index } -//Option adds an option to the menu for the user to select from. -//value is an empty interface that can be used to pass anything through to the function. -//title is the string the user will select -//isDefault is whether this option is a default option (IE when no options are selected). -//function is what is called when only this option is selected. -//If function is nil then it will default to the menu's Action. +// Option adds an option to the menu for the user to select from. +// value is an empty interface that can be used to pass anything through to the function. +// title is the string the user will select +// isDefault is whether this option is a default option (IE when no options are selected). +// function is what is called when only this option is selected. +// If function is nil then it will default to the menu's Action. func (m *Menu) Option(title string, value interface{}, isDefault bool, function func(Opt) error) { option := newOption(len(m.options), title, value, isDefault, function) m.options = append(m.options, *option) } -//Action adds a default action to use in certain scenarios. -//If the selected option (by default or user selected) does not have a function applied to it this will be called. -//If there are no default options and no option was selected this will be called with an option that has an ID of -1. +// Action adds a default action to use in certain scenarios. +// If the selected option (by default or user selected) does not have a function applied to it this will be called. +// If there are no default options and no option was selected this will be called with an option that has an ID of -1. func (m *Menu) Action(function func([]Opt) error) { m.function = function } -//AllowMultiple will tell the menu to allow multiple selections. -//The menu will fail if this is not called and mulple selections were selected. +// AllowMultiple will tell the menu to allow multiple selections. +// The menu will fail if this is not called and mulple selections were selected. func (m *Menu) AllowMultiple() { m.allowMultiple = true } -//ChangeReaderWriter changes where the menu listens and writes to. -//reader is where user input is collected. -//writer and errorWriter is where the menu should write to. +// ChangeReaderWriter changes where the menu listens and writes to. +// reader is where user input is collected. +// writer and errorWriter is where the menu should write to. func (m *Menu) ChangeReaderWriter(reader io.Reader, writer, errorWriter io.Writer) { ui := wlog.New(reader, writer, errorWriter) m.ui = ui } -//Run is used to execute the menu. -//It will print to options and question to the screen. -//It will only clear the screen if ClearOnMenuRun is activated. -//This will validate all responses. -//Errors are of type MenuError. +// Run is used to execute the menu. +// It will print to options and question to the screen. +// It will only clear the screen if ClearOnMenuRun is activated. +// This will validate all responses. +// Errors are of type MenuError. func (m *Menu) Run() error { if m.clear { Clear() @@ -232,7 +232,7 @@ func (m *Menu) callAppropriateNoOptions() (err error) { return m.function(options) } -//hide options when this is a yes or no +// hide options when this is a yes or no func (m *Menu) print() { if !m.isYN { outputFormat := "%d) %s%s" @@ -311,7 +311,7 @@ func (m *Menu) ask() ([]Opt, error) { return finalOptions, nil } -//Converts the response string to a slice of ints, also validates along the way. +// Converts the response string to a slice of ints, also validates along the way. func (m *Menu) resToInt(res string) ([]int, error) { resStrings := strings.Split(res, m.multiSeparator) //Check if we don't want multiple responses @@ -349,8 +349,8 @@ func (m *Menu) ynResParse(res string) ([]int, error) { return []int{int(DefN)}, nil } -//Check if response is in the range of options -//If it is make sure it is not duplicated +// Check if response is in the range of options +// If it is make sure it is not duplicated func (m *Menu) validateResponses(responses []int) error { var tmp []int for _, response := range responses { @@ -368,7 +368,7 @@ func (m *Menu) validateResponses(responses []int) error { return nil } -//Simply checks if number exists in the slice +// Simply checks if number exists in the slice func exist(slice []int, number int) bool { for _, s := range slice { if number == s { @@ -378,7 +378,7 @@ func exist(slice []int, number int) bool { return false } -//gets a list of default options +// gets a list of default options func (m *Menu) getDefault() []Opt { var opt []Opt for _, o := range m.options { @@ -389,8 +389,8 @@ func (m *Menu) getDefault() []Opt { return opt } -//make sure that there is an action available to be called in certain cases -//returns false if it chould not find an action for the number options available +// make sure that there is an action available to be called in certain cases +// returns false if it chould not find an action for the number options available func (m *Menu) validOptAndFunc(opt []Opt) bool { if m.function == nil { if len(opt) == 1 && opt[0].function != nil { diff --git a/option.go b/option.go index bd4a300..2802816 100644 --- a/option.go +++ b/option.go @@ -1,7 +1,7 @@ package wmenu -//Opt is what Menu uses to display options to screen. -//Also holds information on what should run and if it is a default option +// Opt is what Menu uses to display options to screen. +// Also holds information on what should run and if it is a default option type Opt struct { ID int Text string