background code checker for golang

view: fix word wrapping

+34 -15
+5 -3
gust.go model.go
··· 3 3 import ( 4 4 "io" 5 5 "os/exec" 6 + "path/filepath" 6 7 "time" 7 8 8 9 "github.com/charmbracelet/bubbles/spinner" ··· 90 91 file: lipgloss.NewStyle().Foreground(lipgloss.Color("4")), 91 92 duration: lipgloss.NewStyle().Foreground(lipgloss.Color("7")), 92 93 separator: lipgloss.NewStyle().Foreground(lipgloss.Color("8")), 93 - line: lipgloss.NewStyle().Foreground(lipgloss.Color("15")), 94 + line: lipgloss.NewStyle().Foreground(lipgloss.Color("7")), 94 95 context: ContextStyles{ 95 96 activeLine: lipgloss.NewStyle().Foreground(lipgloss.Color("12")), 96 97 activeLineNr: lipgloss.NewStyle().Foreground(lipgloss.Color("1")), ··· 175 176 return watcherrMsg{} 176 177 } 177 178 178 - if event.Has(fsnotify.Write | fsnotify.Create | fsnotify.Remove) { 179 + if event.Has(fsnotify.Write|fsnotify.Create|fsnotify.Remove) && 180 + filepath.Ext(event.Name) == ".go" { 179 181 return modifiedMsg{} 180 182 } 181 183 ··· 194 196 cmd := Success.Cmd() 195 197 m.systemErrors = []error{} 196 198 197 - command := exec.Command("go", m.mode, "./cmd/main.go") 199 + command := exec.Command("go", m.mode, "./cmd/gust") 198 200 stderr, err := command.StderrPipe() 199 201 if err != nil { 200 202 m.systemErrors = append(m.systemErrors, err)
+29 -12
view.go
··· 2 2 3 3 import ( 4 4 "fmt" 5 + "strconv" 5 6 "strings" 6 7 7 8 "github.com/charmbracelet/lipgloss" ··· 31 32 sign := m.options.signs 32 33 33 34 for _, msg := range m.messages { 35 + var mb strings.Builder 34 36 if msg.Type == "error" { 35 - b.WriteString(style.error.Render(sign.error)) 36 - b.WriteString(" ") 37 + mb.WriteString(style.error.Render(sign.error)) 38 + mb.WriteString(" ") 37 39 } else { 38 - b.WriteString(style.warning.Render(sign.warning)) 39 - b.WriteString(" ") 40 + mb.WriteString(style.warning.Render(sign.warning)) 41 + mb.WriteString(" ") 40 42 } 41 43 42 44 if msg.Location.Line != "" { 43 - b.WriteString(style.line.Align(lipgloss.Right).Width(maxLineLen).Render(msg.Location.Line)) 45 + mb.WriteString(style.line.Align(lipgloss.Right).Width(maxLineLen).Render(msg.Location.Line)) 44 46 45 47 if msg.Location.Column != "" { 46 - b.WriteString(":") 47 - b.WriteString(style.line.Align(lipgloss.Left).Width(maxColLen).Render(msg.Location.Column)) 48 + mb.WriteString(":") 49 + mb.WriteString(style.line.Align(lipgloss.Left).Width(maxColLen).Render(msg.Location.Column)) 48 50 } 49 51 } 50 52 if msg.Location.File != "" { 51 - b.WriteString(" ") 52 - b.WriteString(style.file.Render(msg.Location.File)) 53 - b.WriteString(" ") 53 + mb.WriteString(" ") 54 + mb.WriteString(style.file.Render(msg.Location.File)) 55 + mb.WriteString(" ") 54 56 } 55 57 56 - b.WriteString(wordwrap.String(msg.Message, m.width)) 58 + mb.WriteString(msg.Message) 59 + 60 + b.WriteString(wordwrap.String(mb.String(), m.width)) 57 61 58 62 // display context 59 63 if !m.options.summarized { ··· 65 69 nrStyle := style.passiveLineNr 66 70 lineStyle := style.passiveLine 67 71 indent := sign.passiveIndent 72 + active := false 68 73 if msg.Location.Line == nr { 74 + active = true 69 75 nrStyle = style.activeLineNr 70 76 lineStyle = style.activeLine 71 77 indent = sign.activeIndent ··· 73 79 b.WriteString(nrStyle.Render(indent)) 74 80 b.WriteString(nrStyle.Align(lipgloss.Right).Render(nr)) 75 81 b.WriteString(" ") 76 - b.WriteString(lineStyle.Align(lipgloss.Right).Render(line)) 82 + 83 + simplifiedLine := strings.ReplaceAll(line, "\t", " ") 84 + b.WriteString(lineStyle.Render(simplifiedLine)) // makes this easier to reason about 85 + if active && msg.Location.Column != "" { 86 + col, _ := strconv.Atoi(msg.Location.Column) 87 + // special logic to handle tab characters in the target line 88 + tabCount := strings.Count(line[:col-1], "\t") 89 + 90 + b.WriteString("\n") 91 + b.WriteString(style.passiveLineNr.Render(sign.passiveIndent)) 92 + b.WriteString(style.activeLineNr.Width(col + 3*tabCount + len(msg.Location.Line)).Align(lipgloss.Right).Render("^")) 93 + } 77 94 b.WriteString("\n") 78 95 } 79 96 }