github.com/elves/elvish@v0.15.0/pkg/cli/state.go (about) 1 package cli 2 3 import ( 4 "fmt" 5 6 "github.com/elves/elvish/pkg/ui" 7 ) 8 9 // ListBoxState keeps the mutable state ListBox. 10 type ListBoxState struct { 11 Items Items 12 Selected int 13 First int 14 Height int 15 } 16 17 // Items is an interface for accessing multiple items. 18 type Items interface { 19 // Show renders the item at the given zero-based index. 20 Show(i int) ui.Text 21 // Len returns the number of items. 22 Len() int 23 } 24 25 // TestItems is an implementation of Items useful for testing. 26 type TestItems struct { 27 Prefix string 28 Style ui.Styling 29 NItems int 30 } 31 32 // Show returns a plain text consisting of the prefix and i. If the prefix is 33 // empty, it defaults to "item ". 34 func (it TestItems) Show(i int) ui.Text { 35 prefix := it.Prefix 36 if prefix == "" { 37 prefix = "item " 38 } 39 return ui.T(fmt.Sprintf("%s%d", prefix, i), it.Style) 40 } 41 42 // Len returns it.NItems. 43 func (it TestItems) Len() int { 44 return it.NItems 45 }