Skip to content

Commit

Permalink
fix: change cat lineno color and style
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Feb 22, 2022
1 parent eaf9f4b commit fd04680
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions server/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import (
"github.com/muesli/termenv"
)

var (
linenoStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("8"))
)

// softServeMiddleware is a middleware that handles displaying files with the
// option of syntax highlighting and line numbers.
func softServeMiddleware(ac *appCfg.Config) wish.Middleware {
Expand Down Expand Up @@ -109,14 +113,14 @@ func readFile(r *gg.Repository, fp string) (string, error) {
}

func withLineNumber(s string, color bool) string {
st := lipgloss.NewStyle().Foreground(lipgloss.Color("15"))
lines := strings.Split(s, "\n")
mll := fmt.Sprintf("%d", len(fmt.Sprintf("%d", len(lines))))
for i, l := range lines {
lines[i] = fmt.Sprintf("%-"+mll+"d │ %s", i+1, l)
lines[i] = fmt.Sprintf("%-"+mll+"d", i+1)
if color {
lines[i] = st.Render(lines[i])
lines[i] = linenoStyle.Render(lines[i])
}
lines[i] += " │ " + l
}
return strings.Join(lines, "\n")
}
Expand Down

0 comments on commit fd04680

Please sign in to comment.