Created
June 22, 2022 21:35
-
-
Save nicolasparada/8c956ff63cea3a900d5c1a13c7db122d to your computer and use it in GitHub Desktop.
VSCode Bubble Tea snippet
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
{ | |
"New Bubble Tea Program": { | |
"prefix": "bubbletea", | |
"body": [ | |
"package main", | |
"", | |
"import (", | |
"\t\"fmt\"", | |
"\t\"os\"", | |
"", | |
"\ttea \"github.com/charmbracelet/bubbletea\"", | |
")", | |
"", | |
"func main() {", | |
"\terr := tea.NewProgram(initialModel(), tea.WithAltScreen()).Start()", | |
"\tif err != nil {", | |
"\t\tfmt.Fprintln(os.Stderr, err)", | |
"\t\tos.Exit(1)", | |
"\t}", | |
"}", | |
"", | |
"func initialModel() model {", | |
"\treturn model{}", | |
"}", | |
"", | |
"type model struct{}", | |
"", | |
"func (m model) Init() tea.Cmd {", | |
"\treturn nil", | |
"}", | |
"", | |
"func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {", | |
"\tswitch msg := msg.(type) {", | |
"\tcase tea.KeyMsg:", | |
"\t\tswitch msg.String() {", | |
"\t\tcase \"ctrl+c\":", | |
"\t\t\treturn m, tea.Quit", | |
"\t\t}", | |
"\t}", | |
"\treturn m, nil", | |
"}", | |
"", | |
"func (m model) View() string {", | |
"\treturn \"Press Ctrl+C to exit\"", | |
"}" | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment