Detailed changes
@@ -10,7 +10,6 @@ import (
"github.com/charmbracelet/soft-serve/pkg/backend"
"github.com/charmbracelet/soft-serve/pkg/ui/common"
"github.com/charmbracelet/soft-serve/pkg/ui/styles"
- "github.com/muesli/termenv"
"github.com/spf13/cobra"
)
@@ -108,13 +107,6 @@ func commitCommand() *cobra.Command {
return cmd
}
-func renderCtx() gansi.RenderContext {
- return gansi.NewRenderContext(gansi.Options{
- ColorProfile: termenv.TrueColor,
- Styles: common.StyleConfig(),
- })
-}
-
func renderDiff(patch string, color bool) string {
c := patch
@@ -127,7 +119,7 @@ func renderDiff(patch string, color bool) string {
Language: "diff",
}
- err := diffChroma.Render(&pr, renderCtx())
+ err := diffChroma.Render(&pr, common.StyleRenderer())
if err != nil {
s.WriteString(fmt.Sprintf("\n%s", err.Error()))
@@ -15,11 +15,11 @@ import (
"github.com/charmbracelet/soft-serve/pkg/db"
"github.com/charmbracelet/soft-serve/pkg/proto"
"github.com/charmbracelet/soft-serve/pkg/store"
+ "github.com/charmbracelet/soft-serve/pkg/ui/common"
"github.com/charmbracelet/ssh"
"github.com/charmbracelet/wish"
bm "github.com/charmbracelet/wish/bubbletea"
rm "github.com/charmbracelet/wish/recover"
- "github.com/muesli/termenv"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
gossh "golang.org/x/crypto/ssh"
@@ -70,7 +70,7 @@ func NewSSHServer(ctx context.Context) (*SSHServer, error) {
rm.MiddlewareWithLogger(
logger,
// BubbleTea middleware.
- bm.MiddlewareWithProgramHandler(SessionHandler, termenv.ANSI256),
+ bm.MiddlewareWithProgramHandler(SessionHandler, common.DefaultColorProfile),
// CLI middleware.
CommandMiddleware,
// Logging middleware.
@@ -7,7 +7,6 @@ import (
"github.com/alecthomas/chroma/lexers"
gansi "github.com/charmbracelet/glamour/ansi"
"github.com/charmbracelet/soft-serve/pkg/ui/styles"
- "github.com/muesli/termenv"
)
// FormatLineNumber adds line numbers to a string.
@@ -48,10 +47,7 @@ func FormatHighlight(p, c string) (string, error) {
r := strings.Builder{}
styles := StyleConfig()
styles.CodeBlock.Margin = &zero
- rctx := gansi.NewRenderContext(gansi.Options{
- Styles: styles,
- ColorProfile: termenv.TrueColor,
- })
+ rctx := StyleRendererWithStyles(styles)
err := formatter.Render(&r, rctx)
if err != nil {
return "", err
@@ -3,6 +3,12 @@ package common
import (
"github.com/charmbracelet/glamour"
gansi "github.com/charmbracelet/glamour/ansi"
+ "github.com/muesli/termenv"
+)
+
+var (
+ // DefaultColorProfile is the default color profile used by the SSH server.
+ DefaultColorProfile = termenv.ANSI256
)
func strptr(s string) *string {
@@ -25,3 +31,17 @@ func StyleConfig() gansi.StyleConfig {
s.CodeBlock.Chroma.Error.BackgroundColor = noColor
return s
}
+
+// StyleRenderer returns a new Glamour renderer with the DefaultColorProfile.
+func StyleRenderer() gansi.RenderContext {
+ return StyleRendererWithStyles(StyleConfig())
+}
+
+// StyleRendererWithStyles returns a new Glamour renderer with the
+// DefaultColorProfile and styles.
+func StyleRendererWithStyles(styles gansi.StyleConfig) gansi.RenderContext {
+ return gansi.NewRenderContext(gansi.Options{
+ ColorProfile: DefaultColorProfile,
+ Styles: styles,
+ })
+}
@@ -51,10 +51,7 @@ func New(c common.Common, content, extension string) *Code {
}
st := common.StyleConfig()
r.styleConfig = st
- r.renderContext = gansi.NewRenderContext(gansi.Options{
- ColorProfile: termenv.TrueColor,
- Styles: st,
- })
+ r.renderContext = common.StyleRendererWithStyles(st)
r.SetSize(c.Width, c.Height)
return r
}
@@ -18,7 +18,6 @@ import (
"github.com/charmbracelet/soft-serve/pkg/ui/components/viewport"
"github.com/charmbracelet/soft-serve/pkg/ui/styles"
"github.com/muesli/reflow/wrap"
- "github.com/muesli/termenv"
)
var waitBeforeLoading = time.Millisecond * 100
@@ -476,13 +475,6 @@ func (l *Log) loadDiffCmd() tea.Msg {
return LogDiffMsg(diff)
}
-func renderCtx() gansi.RenderContext {
- return gansi.NewRenderContext(gansi.Options{
- ColorProfile: termenv.TrueColor,
- Styles: common.StyleConfig(),
- })
-}
-
func (l *Log) renderCommit(c *git.Commit) string {
s := strings.Builder{}
// FIXME: lipgloss prints empty lines when CRLF is used
@@ -518,7 +510,7 @@ func renderDiff(diff *git.Diff, width int) string {
Code: diff.Patch(),
Language: "diff",
}
- err := diffChroma.Render(&pr, renderCtx())
+ err := diffChroma.Render(&pr, common.StyleRenderer())
if err != nil {
s.WriteString(fmt.Sprintf("\n%s", err.Error()))
} else {