// Displays a list created from given slice / array.
// If allowMultipleSelection is set, you can select multiple entries with space.
Displays a list created from given slice / array.
If allowMultipleSelection is set, you can select multiple entries with space.
// Displays a list created from given slice / array . // If allowMultipleSelection is set you can select multiple entries with space .
func ListSelect(gui *gocui.Gui, title string, slice interface{}, allowMultipleSelection bool) (
	<-chan []int, CleanUpFunc, error,
) {
	value := reflect.ValueOf(slice)
	if k := value.Kind(); k != reflect.Slice && k != reflect.Array {
		return nil, nil, fmt.Errorf("slice argument must be a slice or an array")
	}
	listW := 1
	listH := value.Len()
	buf := bytes.Buffer{}
	for i := 0; i < value.Len(); i++ {
		idxLen, _ := buf.WriteString(strconv.Itoa(i))
		buf.WriteByte('.')
		strBytes := []byte(fmt.Sprint(value.Index(i).Interface()))
		if bLen := len(strBytes) + idxLen + 2; bLen > listW {
			listW = bLen
		}
		buf.Write(strBytes)
		buf.WriteRune('\n')
	}
	listW += 2
	cleanUp := cleanUpFunc(gui, listSelectViewName)
	selectedIdxes, v, err := listSelect(gui, title, listW, listH, allowMultipleSelection)
	if v != nil {
		buf.WriteTo(v)
	}
	return selectedIdxes, cleanUp, err
}
func ListSelect ( gui * gocui . Gui , title string , slice interface { } , allowMultipleSelection bool ) ( <- chan [ ] int , CleanUpFunc , error , ) { value := reflect . ValueOf ( slice ) if k := value . Kind ( ) ; k != reflect . Slice && k != reflect . Array { return nil , nil , fmt . Errorf ( " " ) } listW := 1 listH := value . Len ( ) buf := bytes . Buffer { } for i := 0 ; i < value . Len ( ) ; i ++ { idxLen , _ := buf . WriteString ( strconv . Itoa ( i ) ) buf . WriteByte ( '.' ) strBytes := [ ] byte ( fmt . Sprint ( value . Index ( i ) . Interface ( ) ) ) if bLen := len ( strBytes ) + idxLen + 2 ; bLen > listW { listW = bLen } buf . Write ( strBytes ) buf . WriteRune ( '\n' ) } listW += 2 cleanUp := cleanUpFunc ( gui , listSelectViewName ) selectedIdxes , v , err := listSelect ( gui , title , listW , listH , allowMultipleSelection ) if v != nil { buf . WriteTo ( v ) } return selectedIdxes , cleanUp , err }
Displays a list created from given slice / array.
Displays a list created from given slice / array .