tangled
alpha
login
or
join now
oppi.li
/
gust
6
fork
atom
background code checker for golang
6
fork
atom
overview
issues
2
pulls
pipelines
view: fix word wrapping
oppi.li
11 months ago
b29c6a26
24604e7b
+34
-15
2 changed files
expand all
collapse all
unified
split
model.go
view.go
+5
-3
gust.go
model.go
···
3
3
import (
4
4
"io"
5
5
"os/exec"
6
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
93
-
line: lipgloss.NewStyle().Foreground(lipgloss.Color("15")),
94
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
178
-
if event.Has(fsnotify.Write | fsnotify.Create | fsnotify.Remove) {
179
179
+
if event.Has(fsnotify.Write|fsnotify.Create|fsnotify.Remove) &&
180
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
197
-
command := exec.Command("go", m.mode, "./cmd/main.go")
199
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
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
35
+
var mb strings.Builder
34
36
if msg.Type == "error" {
35
35
-
b.WriteString(style.error.Render(sign.error))
36
36
-
b.WriteString(" ")
37
37
+
mb.WriteString(style.error.Render(sign.error))
38
38
+
mb.WriteString(" ")
37
39
} else {
38
38
-
b.WriteString(style.warning.Render(sign.warning))
39
39
-
b.WriteString(" ")
40
40
+
mb.WriteString(style.warning.Render(sign.warning))
41
41
+
mb.WriteString(" ")
40
42
}
41
43
42
44
if msg.Location.Line != "" {
43
43
-
b.WriteString(style.line.Align(lipgloss.Right).Width(maxLineLen).Render(msg.Location.Line))
45
45
+
mb.WriteString(style.line.Align(lipgloss.Right).Width(maxLineLen).Render(msg.Location.Line))
44
46
45
47
if msg.Location.Column != "" {
46
46
-
b.WriteString(":")
47
47
-
b.WriteString(style.line.Align(lipgloss.Left).Width(maxColLen).Render(msg.Location.Column))
48
48
+
mb.WriteString(":")
49
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
51
-
b.WriteString(" ")
52
52
-
b.WriteString(style.file.Render(msg.Location.File))
53
53
-
b.WriteString(" ")
53
53
+
mb.WriteString(" ")
54
54
+
mb.WriteString(style.file.Render(msg.Location.File))
55
55
+
mb.WriteString(" ")
54
56
}
55
57
56
56
-
b.WriteString(wordwrap.String(msg.Message, m.width))
58
58
+
mb.WriteString(msg.Message)
59
59
+
60
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
72
+
active := false
68
73
if msg.Location.Line == nr {
74
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
76
-
b.WriteString(lineStyle.Align(lipgloss.Right).Render(line))
82
82
+
83
83
+
simplifiedLine := strings.ReplaceAll(line, "\t", " ")
84
84
+
b.WriteString(lineStyle.Render(simplifiedLine)) // makes this easier to reason about
85
85
+
if active && msg.Location.Column != "" {
86
86
+
col, _ := strconv.Atoi(msg.Location.Column)
87
87
+
// special logic to handle tab characters in the target line
88
88
+
tabCount := strings.Count(line[:col-1], "\t")
89
89
+
90
90
+
b.WriteString("\n")
91
91
+
b.WriteString(style.passiveLineNr.Render(sign.passiveIndent))
92
92
+
b.WriteString(style.activeLineNr.Width(col + 3*tabCount + len(msg.Location.Line)).Align(lipgloss.Right).Render("^"))
93
93
+
}
77
94
b.WriteString("\n")
78
95
}
79
96
}