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

Build a glamorous habit tracker using Charm CLI

Donia Chaiehloudj
July 07, 2024
110

Build a glamorous habit tracker using Charm CLI

Are you a terminal and keyboard addict? Do you want to combine your love for Go and CLI? How about building a habit tracker using Charm CLI! In a few lines of code, you will turn programs in your terminal into beautiful, user-friendly, and glamorous UIs.

In this talk, learn how to:

• Write the basic syntax data model of Bubble Tea library from Charm CLI
• Apply some lip gloss to turn your CLI into something glamorous

Apply Charm CLI to your daily tooling to make your developer life better and sexier using our favorite language!

Donia Chaiehloudj

July 07, 2024
Tweet

Transcript

  1. Using Charm CLI Build a glamorous Habits Tracker Donia Chaiehloudj

    | @doniacld GopherCon Chicago, 2024 Software Engineer @Isovalent by Cisco Co-author of “Learn Go with Pocket-Sized Projects”
  2. Agenda_ My ideal Habit Tracker What is Charm_ ? Demo

    🤞 Charm_ Cheatsheet @doniacld
  3. Libs Charm_ Making the command line glamourous, powerful, fun and

    modern. glamourous @doniacld Stylesheet mardown renderer Terminal style toolkit Some components for Bubble Tea apps Terminal UI framework
  4. Libs Charm_ Making the command line glamourous, powerful, fun and

    modern. glamourous @doniacld Stylesheet mardown renderer Terminal style toolkit Some components for Bubble Tea apps Terminal UI framework Apps Render markdown on the CLI Self-host your Git server for CLI Write terminal GIFs as code
  5. Model — the state of your application View — render

    your model in your terminal as string Update — a way to update your state based on messages Bubble Tea @doniacld Based on the Elm Architecture Architecture
  6. Bubbles @doniacld Bubble = Component = Model Spinner, Text input,

    Text area, Table, Progress, List, Paginator, ...
  7. @doniacld List Habits Habit Define a Habit 1. 2. Implement

    Item Interface // pkg/habit/habit.go
  8. @doniacld List Habits Habit Define a Habit 1. 2. Implement

    Item Interface 3. Define main Model // pkg/habittracker/model.go // pkg/habit/habit.go
  9. List Habits @doniacld Model interface Check the message type 1.

    Update the pagination at resize 2. // pkg/habittracker/model.go
  10. List Habits @doniacld Model interface Check the message type 1.

    Update the pagination at resize 2. Check input keyboard 3. // pkg/habittracker/model.go
  11. List Habits @doniacld Model interface Check the message type 1.

    Update the pagination at resize 2. Check input keyboard 3. Delegate update to Bubbletea 4. // pkg/habittracker/model.go
  12. func (m Model) View() string { var details string if

    m.habits.SelectedItem() != nil { current := m.habits.SelectedItem().(habit) details = fmt.Sprintf("\nDetails: \nAchieved %d/%d", current.ticksCount, current.target) } return lipgloss.JoinHorizontal(lipgloss.Top, m.habits.View(), details) } List Habits @doniacld Put some Lipgloss // pkg/habittracker/model.go
  13. @doniacld Progression Bar Create new command Add new Model //

    pkg/habittracker/model.go // pkg/habittracker/cmd.go
  14. @doniacld Add a Habit Introduce session state Create new nested

    Model // pkg/form/model.go // pkg/habittracker/model.go
  15. @doniacld Add a Habit Introduce session state Create new nested

    Model // pkg/form/model.go // pkg/habittracker/model.go // pkg/habittracker/model.go Add to main Model
  16. Key Takeaways Build your Model and combine: list, table, text,

    form, etc. Model interface: Init, Update, View Put some lipstick 💄 Create new commands Apply to your everyday boring CLI && Have fun! 🤩 @doniacld xxxCmd(msg tea.Msg) tea.Cmd
  17. Key Takeaways Build your Model and combine: list, table, text,

    form, etc. Model interface: Init, Update, View Put some lipstick 💄 Create new commands Apply to your everyday boring CLI && Have fun! 🤩 https://charm.sh https://github.com/bashbunni/pjs/ @doniacld xxxCmd(msg tea.Msg) tea.Cmd