-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
380b842
commit 12c3f51
Showing
4 changed files
with
69 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module examples | ||
|
||
go 1.17 | ||
go 1.18 | ||
|
||
replace github.com/charmbracelet/lipgloss => ../ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/charmbracelet/lipgloss" | ||
"github.com/charmbracelet/lipgloss/list" | ||
) | ||
|
||
var purchased = []string{ | ||
"Bananas", | ||
"Barley", | ||
"Cashews", | ||
"Coconut Milk", | ||
"Dill", | ||
"Eggs", | ||
"Fish Cake", | ||
"Leeks", | ||
"Papaya", | ||
} | ||
|
||
func GroceryEnumerator(l *list.List, i int) string { | ||
item := l.Items[i-1] | ||
for _, p := range purchased { | ||
if item == p { | ||
return "✓" | ||
} | ||
} | ||
return " " | ||
} | ||
|
||
func newList(items ...any) *list.List { | ||
enumStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("10")).MarginRight(1) | ||
|
||
return list.New(items...). | ||
Enumerator(GroceryEnumerator). | ||
EnumeratorStyle(enumStyle) | ||
} | ||
|
||
func main() { | ||
itemStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("12")) | ||
enumStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("12")).MarginRight(1) | ||
|
||
l := list.New( | ||
"A", newList("Artichoke"), | ||
"B", newList("Baking Flour", "Bananas", "Barley", "Bean Sprouts"), | ||
"C", newList("Cashew Apple", "Cashews", "Coconut Milk", "Curry Paste", "Currywurst"), | ||
"D", newList("Dill", "Dragonfruit", "Dried Shrimp"), | ||
"E", newList("Eggs"), | ||
"F", newList("Fish Cake", "Furikake"), | ||
"J", newList("Jicama"), | ||
"K", newList("Kohlrabi"), | ||
"L", newList("Leeks", "Lentils", "Licorice Root"), | ||
). | ||
ItemStyle(itemStyle). | ||
EnumeratorStyle(enumStyle) | ||
|
||
fmt.Println(l) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters