|
5 | 5 | "fmt" |
6 | 6 | "github.com/charmbracelet/bubbles/list" |
7 | 7 | tea "github.com/charmbracelet/bubbletea" |
8 | | - "github.com/muesli/reflow/ansi" |
9 | 8 | "os" |
10 | 9 | "strconv" |
11 | 10 | "strings" |
@@ -46,16 +45,16 @@ func main() { |
46 | 45 | stringerList := list.MakeStringerList(itemList) |
47 | 46 |
|
48 | 47 | endResult := make(chan string, 1) |
49 | | - list := list.NewModel() |
50 | | - list.AddItems(stringerList) |
51 | | - list.SuffixGen = &exampleSuffixer{currentMarker: "<"} |
| 48 | + l := list.NewModel() |
| 49 | + l.AddItems(stringerList) |
| 50 | + l.SuffixGen = list.NewSuffixer() |
52 | 51 |
|
53 | 52 | // Since in this example we only use UNIQUE string items we can use a String Comparison for the equals methode |
54 | 53 | // but be aware that different items in your case can have the same string -> false-positiv |
55 | 54 | // Better: Assert back to your struct and test on something unique within it! |
56 | | - list.SetEquals(func(first, second fmt.Stringer) bool { return first.String() == second.String() }) |
| 55 | + l.SetEquals(func(first, second fmt.Stringer) bool { return first.String() == second.String() }) |
57 | 56 | m := model{} |
58 | | - m.list = list |
| 57 | + m.list = l |
59 | 58 |
|
60 | 59 | m.endResult = endResult |
61 | 60 |
|
@@ -100,7 +99,7 @@ func (m model) View() string { |
100 | 99 | func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { |
101 | 100 | if m.list.PrefixGen == nil { |
102 | 101 | // use default |
103 | | - m.list.PrefixGen = list.NewDefault() |
| 102 | + m.list.PrefixGen = list.NewPrefixer() |
104 | 103 | } |
105 | 104 |
|
106 | 105 | switch msg := msg.(type) { |
@@ -213,22 +212,3 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { |
213 | 212 | } |
214 | 213 | return m, nil |
215 | 214 | } |
216 | | - |
217 | | -type exampleSuffixer struct { |
218 | | - viewPos list.ViewPos |
219 | | - currentMarker string |
220 | | - markerLenght int |
221 | | -} |
222 | | - |
223 | | -func (e *exampleSuffixer) InitSuffixer(viewPos list.ViewPos, screen list.ScreenInfo) int { |
224 | | - e.viewPos = viewPos |
225 | | - e.markerLenght = ansi.PrintableRuneWidth(e.currentMarker) |
226 | | - return e.markerLenght |
227 | | -} |
228 | | - |
229 | | -func (e *exampleSuffixer) Suffix(item, line int, selected bool) string { |
230 | | - if item == e.viewPos.Cursor && line == 0 { |
231 | | - return e.currentMarker |
232 | | - } |
233 | | - return strings.Repeat(" ", e.markerLenght) |
234 | | -} |
0 commit comments