select.go
func (sa *SelectWithAdd) Run() (int, string, error) {
	if len(sa.Items) > 0 {
		newItems := append([]string{sa.AddLabel}, sa.Items...)

		list, err := list.New(newItems, 5)
		if err != nil {
			return 0, "", err
		}

		s := Select{
			Label:     sa.Label,
			Items:     newItems,
			IsVimMode: sa.IsVimMode,
			HideHelp:  sa.HideHelp,
			Size:      5,
			list:      list,
			Pointer:   sa.Pointer,
		}
		s.setKeys()

		err = s.prepareTemplates()
		if err != nil {
			return 0, "", err
		}

		selected, value, err := s.innerRun(1, 0, '+')
		if err != nil || selected != 0 {
			return selected - 1, value, err
		}

		// XXX run through terminal for windows
		os.Stdout.Write([]byte(upLine(1) + "\r" + clearLine))
	}

	p := Prompt{
		Label:     sa.AddLabel,
		Validate:  sa.Validate,
		IsVimMode: sa.IsVimMode,
		Pointer:   sa.Pointer,
	}
	value, err := p.Run()
	return SelectedAdd, value, err
}
func (sa *SelectWithAdd) Run() (int, string, error) {
	if len(sa.Items) > 0 {
		newItems := append([]string{sa.AddLabel}, sa.Items...)

		list, err := list.New(newItems, 5)
		if err != nil {
			return 0, "", err
		}

		s := Select{
			Label:     sa.Label,
			Items:     newItems,
			IsVimMode: sa.IsVimMode,
			HideHelp:  sa.HideHelp,
			Size:      5,
			list:      list,
			Pointer:   sa.Pointer,
		}
		s.setKeys()

		err = s.prepareTemplates()
		if err != nil {
			return 0, "", err
		}

		selected, value, err := s.innerRun(1, 0, '+')
		if err != nil || selected != 0 {
			return selected - 1, value, err
		}

		// XXX run through terminal for windows
		os.Stdout.Write([]byte(upLine(1) + "\r" + clearLine))
	}

	p := Prompt{
		Label:     sa.AddLabel,
		Validate:  sa.Validate,
		IsVimMode: sa.IsVimMode,
		Pointer:   sa.Pointer,
	}
	value, err := p.Run()
	return SelectedAdd, value, err
}
func ( sa * SelectWithAdd ) Run ( ) ( int , string , error ) { if len ( sa . Items ) > 0 { newItems := append ( [ ] string { sa . AddLabel } , sa . Items ... ) list , err := list . New ( newItems , 5 ) if err != nil { return 0 , " " , err } s := Select { Label : sa . Label , Items : newItems , IsVimMode : sa . IsVimMode , HideHelp : sa . HideHelp , Size : 5 , list : list , Pointer : sa . Pointer , } s . setKeys ( ) err = s . prepareTemplates ( ) if err != nil { return 0 , " " , err } selected , value , err := s . innerRun ( 1 , 0 , '+' ) if err != nil || selected != 0 { return selected - 1 , value , err } // XXX run through terminal for windows os . Stdout . Write ( [ ] byte ( upLine ( 1 ) + " \r " + clearLine ) ) } p := Prompt { Label : sa . AddLabel , Validate : sa . Validate , IsVimMode : sa . IsVimMode , Pointer : sa . Pointer , } value , err := p . Run ( ) return SelectedAdd , value , err }
// Run executes the select list. Its displays the label and the list of items, asking the user to chose any
// value within to list or add his own. Run will keep the prompt alive until it has been canceled from
// the command prompt or it has received a valid value.
//
// If the addLabel is selected in the list, this function will return a -1 index with the added label and no error.
// Otherwise, it will return the index and the value of the selected item. In any case, if an error is triggered, it
// will also return the error as its third return value.
Run executes the select list . Its displays the label and the list of items asking the user to chose any value within to list or add his own . Run will keep the prompt alive until it has been canceled from the command prompt or it has received a valid value . If the addLabel is selected in the list this function will return a - 1 index with the added label and no error . Otherwise it will return the index and the value of the selected item . In any case if an error is triggered it will also return the error as its third return value .