2020-10-21 15:49:04 -04:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"github.com/charmbracelet/bubbles/viewport"
|
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
|
|
|
"github.com/charmbracelet/glamour"
|
2021-05-14 22:25:51 -04:00
|
|
|
|
"github.com/charmbracelet/lipgloss"
|
2020-10-21 15:49:04 -04:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const content = `
|
2022-09-23 15:41:33 -04:00
|
|
|
|
# Today’s Menu
|
|
|
|
|
|
|
|
|
|
## Appetizers
|
2020-10-21 15:49:04 -04:00
|
|
|
|
|
|
|
|
|
| Name | Price | Notes |
|
|
|
|
|
| --- | --- | --- |
|
|
|
|
|
| Tsukemono | $2 | Just an appetizer |
|
|
|
|
|
| Tomato Soup | $4 | Made with San Marzano tomatoes |
|
|
|
|
|
| Okonomiyaki | $4 | Takes a few minutes to make |
|
|
|
|
|
| Curry | $3 | We can add squash if you’d like |
|
|
|
|
|
|
2022-09-23 15:41:33 -04:00
|
|
|
|
## Seasonal Dishes
|
2020-10-21 15:49:04 -04:00
|
|
|
|
|
|
|
|
|
| Name | Price | Notes |
|
|
|
|
|
| --- | --- | --- |
|
|
|
|
|
| Steamed bitter melon | $2 | Not so bitter |
|
|
|
|
|
| Takoyaki | $3 | Fun to eat |
|
|
|
|
|
| Winter squash | $3 | Today it's pumpkin |
|
|
|
|
|
|
2022-09-23 15:41:33 -04:00
|
|
|
|
## Desserts
|
2020-10-21 15:49:04 -04:00
|
|
|
|
|
|
|
|
|
| Name | Price | Notes |
|
|
|
|
|
| --- | --- | --- |
|
|
|
|
|
| Dorayaki | $4 | Looks good on rabbits |
|
|
|
|
|
| Banana Split | $5 | A classic |
|
|
|
|
|
| Cream Puff | $3 | Pretty creamy! |
|
|
|
|
|
|
|
|
|
|
All our dishes are made in-house by Karen, our chef. Most of our ingredients
|
2021-03-18 13:04:27 -04:00
|
|
|
|
are from our garden or the fish market down the street.
|
2020-10-21 15:49:04 -04:00
|
|
|
|
|
|
|
|
|
Some famous people that have eaten here lately:
|
|
|
|
|
|
|
|
|
|
* [x] René Redzepi
|
|
|
|
|
* [x] David Chang
|
|
|
|
|
* [ ] Jiro Ono (maybe some day)
|
|
|
|
|
|
|
|
|
|
Bon appétit!
|
|
|
|
|
`
|
|
|
|
|
|
2021-05-14 22:25:51 -04:00
|
|
|
|
var helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241")).Render
|
2020-10-21 15:49:04 -04:00
|
|
|
|
|
|
|
|
|
type example struct {
|
|
|
|
|
viewport viewport.Model
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func newExample() (*example, error) {
|
2022-09-02 15:56:18 -04:00
|
|
|
|
const width = 78
|
|
|
|
|
|
|
|
|
|
vp := viewport.New(width, 20)
|
2021-09-02 16:18:51 -04:00
|
|
|
|
vp.Style = lipgloss.NewStyle().
|
|
|
|
|
BorderStyle(lipgloss.RoundedBorder()).
|
|
|
|
|
BorderForeground(lipgloss.Color("62")).
|
|
|
|
|
PaddingRight(2)
|
2020-10-21 15:49:04 -04:00
|
|
|
|
|
2022-09-02 15:56:18 -04:00
|
|
|
|
renderer, err := glamour.NewTermRenderer(
|
2022-09-23 15:41:33 -04:00
|
|
|
|
glamour.WithAutoStyle(),
|
2022-09-02 15:56:18 -04:00
|
|
|
|
glamour.WithWordWrap(width),
|
|
|
|
|
)
|
2020-10-21 15:49:04 -04:00
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
str, err := renderer.Render(content)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vp.SetContent(str)
|
|
|
|
|
|
|
|
|
|
return &example{
|
|
|
|
|
viewport: vp,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e example) Init() tea.Cmd {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e example) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
|
|
switch msg := msg.(type) {
|
|
|
|
|
case tea.KeyMsg:
|
|
|
|
|
switch msg.String() {
|
2021-05-01 09:28:58 -04:00
|
|
|
|
case "q", "ctrl+c", "esc":
|
2020-10-21 15:49:04 -04:00
|
|
|
|
return e, tea.Quit
|
|
|
|
|
default:
|
2021-09-02 16:18:51 -04:00
|
|
|
|
var cmd tea.Cmd
|
|
|
|
|
e.viewport, cmd = e.viewport.Update(msg)
|
2020-10-31 20:58:24 -04:00
|
|
|
|
return e, cmd
|
2020-10-21 15:49:04 -04:00
|
|
|
|
}
|
2020-10-31 20:58:24 -04:00
|
|
|
|
default:
|
|
|
|
|
return e, nil
|
2020-10-21 15:49:04 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e example) View() string {
|
2020-10-31 20:58:24 -04:00
|
|
|
|
return e.viewport.View() + e.helpView()
|
2020-10-21 15:49:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e example) helpView() string {
|
2021-05-14 22:25:51 -04:00
|
|
|
|
return helpStyle("\n ↑/↓: Navigate • q: Quit\n")
|
2020-10-21 15:49:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
model, err := newExample()
|
|
|
|
|
if err != nil {
|
2021-05-28 13:45:17 -04:00
|
|
|
|
fmt.Println("Could not initialize Bubble Tea model:", err)
|
2020-10-21 15:49:04 -04:00
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := tea.NewProgram(model).Start(); err != nil {
|
|
|
|
|
fmt.Println("Bummer, there's been an error:", err)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
}
|