Skip to content

Commit

Permalink
feat(internal/ui): set window title and customize renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
nullswan committed Oct 6, 2024
1 parent bd81e06 commit b302115
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions internal/ui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ func NewModel(inputChan chan string) model {
func (m model) Init() tea.Cmd {
return tea.Batch(
textarea.Blink,
tea.SetWindowTitle("Golem 🗿"),
)
}
16 changes: 14 additions & 2 deletions internal/ui/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/glamour"
"github.com/charmbracelet/glamour/styles"
"github.com/charmbracelet/lipgloss"
)

Expand Down Expand Up @@ -60,10 +61,19 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

m.textArea.SetWidth(msg.Width)

// Override the default glamour style with a dark one
// TODO(nullswan): Handle light theme
var styleOpt glamour.TermRendererOption
darkStyle := styles.DarkStyleConfig
darkStyle.Document.Margin = uintPtr(0)
styleOpt = glamour.WithStyles(darkStyle)

// Initialize the glamour renderer
var err error
m.pagerRenderer, err = glamour.NewTermRenderer(
glamour.WithStandardStyle("dark"),
glamour.WithWordWrap(int(msg.Width)),
styleOpt,
glamour.WithWordWrap(0),
glamour.WithEmoji(),
)
if err != nil {
fmt.Printf("Error initializing renderer: %v\n", err)
Expand Down Expand Up @@ -145,3 +155,5 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Return the updated model and any commands to run
return m, tea.Batch(cmds...)
}

func uintPtr(u uint) *uint { return &u }

0 comments on commit b302115

Please sign in to comment.