Skip to content

Commit

Permalink
docs: example of MakeRenderer
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <[email protected]>
  • Loading branch information
caarlos0 committed Jan 18, 2024
1 parent 7f44d6d commit 0337c4b
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions examples/bubbletea/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
"github.com/charmbracelet/ssh"
"github.com/charmbracelet/wish"
Expand Down Expand Up @@ -67,19 +68,24 @@ func teaHandler(s ssh.Session) (tea.Model, []tea.ProgramOption) {
wish.Fatalln(s, "no active terminal, skipping")
return nil, nil
}
renderer := bm.MakeRenderer(s)
m := model{
term: pty.Term,
width: pty.Window.Width,
height: pty.Window.Height,
term: pty.Term,
width: pty.Window.Width,
height: pty.Window.Height,
txtStyle: renderer.NewStyle().Foreground(lipgloss.Color("10")),
quitStyle: renderer.NewStyle().Foreground(lipgloss.Color("8")),
}
return m, []tea.ProgramOption{tea.WithAltScreen()}
}

// Just a generic tea.Model to demo terminal information of ssh.
type model struct {
term string
width int
height int
term string
width int
height int
txtStyle lipgloss.Style
quitStyle lipgloss.Style
}

func (m model) Init() tea.Cmd {
Expand All @@ -101,8 +107,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

func (m model) View() string {
s := "Your term is %s\n"
s += "Your window size is x: %d y: %d\n\n"
s += "Press 'q' to quit\n"
return fmt.Sprintf(s, m.term, m.width, m.height)
s := fmt.Sprintf("Your term is %s\nYour window size is %dx%d", m.term, m.width, m.height)
return m.txtStyle.Render(s) + "\n\n" + m.quitStyle.Render("Press 'q' to quit\n")
}

0 comments on commit 0337c4b

Please sign in to comment.