Skip to content

Commit

Permalink
add embeds and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
getinnocuous committed Apr 12, 2024
1 parent 3b38f3b commit 57ff1a6
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions cmd/theme.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package cmd

import (
_ "embed"
"fmt"

"github.com/charmbracelet/glamour"
"github.com/charmbracelet/lipgloss"
"github.com/muesli/termenv"
Expand Down Expand Up @@ -117,15 +120,27 @@ var addedLineStyle = lipgloss.NewStyle().Foreground(lipgloss.Color(ColorPalette.
var deletedLineStyle = lipgloss.NewStyle().Background(lipgloss.Color(ColorPalette.Light.BgDanger)).Foreground(lipgloss.Color(ColorPalette.Light.LabelControl))
var containerStyle = lipgloss.NewStyle().PaddingLeft(2).PaddingTop(2)

//go:embed overmind-theme.json
var overmindTheme string

//go:embed overmind-theme-dark.json
var overmindThemeDark string

func markdownToString(markdown string) string {
themePath := "./overmind-theme.json"
themePath := overmindTheme
hasDarkBackground := termenv.HasDarkBackground()
if hasDarkBackground {
themePath = "./overmind-theme-dark.json"
themePath = overmindThemeDark
}
r, _ := glamour.NewTermRenderer(
r, err := glamour.NewTermRenderer(
glamour.WithStylesFromJSONFile(themePath),
)
out, _ := r.Render(markdown)
if err != nil {
panic(fmt.Errorf("failed to initialize terminal renderer: %w", err))
}
out, err := r.Render(markdown)
if err != nil {
panic(fmt.Errorf("failed to render markdown: %w", err))
}
return out
}

0 comments on commit 57ff1a6

Please sign in to comment.