Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Build nice terminal UI with Bubble Tea

Build nice terminal UI with Bubble Tea

Ladislav Prskavec (Pure Storage) - @abtris

Bubble Tea is Go library for nice Terminal UI. Charm (https://charm.sh/) created whole ecosystem libraries and tools around. I'm showing how you can easily use for your CLI application.

Source code: https://github.com/abtris/rss-bubletea-demo

Ladislav Prskavec

April 23, 2024
Tweet

More Decks by Ladislav Prskavec

Other Decks in Technology

Transcript

  1. Golang Prague #15, 2024 1 Build nice terminal UI with

    bubble tea Ladislav Prskavec, Pure Storage, @abtris
  2. Golang Prague #15, 2024 3 What is Bubble Tea? The

    fun, functional and stateful way to build terminal apps. – A Go framework based on The Elm Architecture –
  3. Golang Prague #15, 2024 5 Model type model struct {

    choices []string cursor int selected map[int]struct{} }
  4. Golang Prague #15, 2024 6 Methods func (m model) Init()

    tea.Cmd func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) func (m model) View() string
  5. Golang Prague #15, 2024 7 Commands and Messages func checkServer()

    tea.Msg { c := &http.Client{Timeout: 10 * time.Second} res, err := c.Get(url) if err != nil { return errMsg{err} } return statusMsg(res.StatusCode) } type statusMsg int type errMsg struct{ err error } func (e errMsg) Error() string { return e.err.Error() }
  6. Golang Prague #15, 2024 8 One More Thing About Commands

    func cmdWithArg(id int) tea.Cmd { return func() tea.Msg { return someMsg{id: id} } }
  7. Golang Prague #15, 2024 9 func checkSomeUrl(url string) tea.Cmd {

    return func() tea.Msg { c := &http.Client{Timeout: 10 * time.Second} res, err := c.Get(url) if err != nil { return errMsg{err} } return statusMsg(res.StatusCode) } }
  8. Golang Prague #15, 2024 11 Who is behind this? -

    startup, NY – Charm Founders: – – Toby Padilla – Christian Rocha
  9. Golang Prague #15, 2024 13 Apps - Send emails from

    your terminal – Pop - AI on the command line – Mods - The SSH directory – Wishlist - Your CLI home video recorder – VHS - The mighty, self-hostable Git server for the command line – SoftServe - Render markdown on the CLI, with pizzazz! – Glow - A personal key value store – Skate - A tool for glamorous shell scripts – Gum
  10. Golang Prague #15, 2024 14 SoftServe --- # Jump directly

    to a repo in the TUI ssh git.charm.sh -t soft-serve --- # Print out a directory tree for a repo ssh git.charm.sh repo tree soft-serve --- # Print a specific file ssh git.charm.sh repo blob soft-serve cmd/soft/main.go --- # Print a file with syntax highlighting and line numbers ssh git.charm.sh repo blob soft-serve cmd/soft/main.go -c -l
  11. Golang Prague #15, 2024 19 - Terminal UI library with

    rich, interactive widgets — written in Golang – TView – TCell - Tea provides an Elm inspired functional framework for interactive command-line programs. – GoTea - Golang terminal dashboard – TermUI
  12. Golang Prague #15, 2024 21 Contact Ladislav Prskavec, Pure Storage

    Follow me on Mastodon or LinkedIn - www.prskavec.net Follow Prague Go Meetup on and - www.gomeetupprague.cz Mastodon YouTube
  13. Golang Prague #15, 2024 22 Links - simple RSS reader

    as TUI – Demo - A powerful little TUI framework – Bubble Tea – Commands tutorial - TUI components for Bubble Tea – Bubbles - Style definitions for nice terminal layouts – LipGloss - Stylesheet-based markdown rendering for your CLI apps – Glamour - Build terminal forms and prompts – Huh - Your CLI home video recorder – VHS