From f6008596df10ce399cb3f4341e30d8a63e128496 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Wed, 25 May 2022 16:07:01 -0400 Subject: [PATCH] fix: replace tabs with space to avoid breaking files line wrapping --- ui/components/code/code.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ui/components/code/code.go b/ui/components/code/code.go index c475e9636c0485255859935b5fdbd1043f5d77c8..c25f462ad7adcb53c72097788451aab54d9d4c5c 100644 --- a/ui/components/code/code.go +++ b/ui/components/code/code.go @@ -16,6 +16,10 @@ import ( "github.com/muesli/termenv" ) +const ( + tabWidth = 4 +) + var ( lineDigitStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("239")) lineBarStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("236")) @@ -181,6 +185,10 @@ func (r *Code) glamourize(w int, md string) (string, error) { } func (r *Code) renderFile(path, content string, width int) (string, error) { + // FIXME chroma & glamour might break wrapping when using tabs since tab + // width depends on the terminal. This is a workaround to replace tabs with + // 4-spaces. + content = strings.ReplaceAll(content, "\t", strings.Repeat(" ", tabWidth)) lexer := lexers.Fallback if path == "" { lexer = lexers.Analyse(content)