Skip to content

Commit

Permalink
chore: adjust line number coloring
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed Feb 22, 2022
1 parent 752d67a commit e267bc9
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions server/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import (
)

var (
linenoStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("8"))
dirnameStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#00AAFF"))
filenameStyle = lipgloss.NewStyle()
filemodeStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#777777"))
lineDigitStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("239"))
lineBarStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("236"))
dirnameStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#00AAFF"))
filenameStyle = lipgloss.NewStyle()
filemodeStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#777777"))
)

type entries []object.TreeEntry
Expand Down Expand Up @@ -144,13 +145,18 @@ func softServeMiddleware(ac *appCfg.Config) wish.Middleware {

func withLineNumber(s string, color bool) string {
lines := strings.Split(s, "\n")
mll := fmt.Sprintf("%d", len(fmt.Sprintf("%d", len(lines))))
// NB: len() is not a particularly safe way to count string width (because
// it's counting bytes instead of runes) but in this case it's okay
// because we're only dealing with digits, which are one byte each.
mll := len(fmt.Sprintf("%d", len(lines)))
for i, l := range lines {
lines[i] = fmt.Sprintf("%-"+mll+"d", i+1)
digit := fmt.Sprintf("%*d", mll, i)
line := "│"
if color {
lines[i] = linenoStyle.Render(lines[i])
digit = lineDigitStyle.Render(digit)
line = lineBarStyle.Render(line)
}
lines[i] += " │ " + l
lines[i] = fmt.Sprintf(" %s %s %s", digit, line, l)
}
return strings.Join(lines, "\n")
}
Expand Down

0 comments on commit e267bc9

Please sign in to comment.