Skip to content

Instantly share code, notes, and snippets.

@nicolasparada
Created June 22, 2022 21:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicolasparada/8c956ff63cea3a900d5c1a13c7db122d to your computer and use it in GitHub Desktop.
Save nicolasparada/8c956ff63cea3a900d5c1a13c7db122d to your computer and use it in GitHub Desktop.
VSCode Bubble Tea snippet
{
"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