Fix linter warnings

This commit is contained in:
Stefan Haller 2026-04-07 10:00:06 +02:00
parent 196e0a3c17
commit cfcdcdb5be
6 changed files with 49 additions and 51 deletions

View file

@ -151,6 +151,7 @@ func TestParseOneColours(t *testing.T) {
} }
func parseEscRunes(t *testing.T, ei *escapeInterpreter, runes string) { func parseEscRunes(t *testing.T, ei *escapeInterpreter, runes string) {
t.Helper()
for _, b := range []byte(runes) { for _, b := range []byte(runes) {
isEscape, err := ei.parseOne([]byte{b}) isEscape, err := ei.parseOne([]byte{b})
assert.Equal(t, true, isEscape) assert.Equal(t, true, isEscape)

View file

@ -912,9 +912,9 @@ func calcScrollbarRune(
) rune { ) rune {
if showScrollbar && (position >= scrollbarStart && position <= scrollbarEnd) { if showScrollbar && (position >= scrollbarStart && position <= scrollbarEnd) {
return '▐' return '▐'
} else {
return runeV
} }
return runeV
} }
func calcRealScrollbarStartEnd(v *View) (bool, int, int) { func calcRealScrollbarStartEnd(v *View) (bool, int, int) {

View file

@ -13,9 +13,7 @@ import (
) )
type ( type (
wchar uint16
short int16 short int16
dword uint32
word uint16 word uint16
) )

View file

@ -55,18 +55,21 @@ var runeReplacements = map[rune]string{
func (g *Gui) tcellInit(runeReplacements map[rune]string) error { func (g *Gui) tcellInit(runeReplacements map[rune]string) error {
tcell.SetEncodingFallback(tcell.EncodingFallbackASCII) tcell.SetEncodingFallback(tcell.EncodingFallbackASCII)
if s, e := tcell.NewScreen(); e != nil { s, e := tcell.NewScreen()
if e != nil {
return e return e
} else if e = s.Init(); e != nil { }
if e = s.Init(); e != nil {
return e return e
} else { }
registerRuneFallbacks(s, runeReplacements) registerRuneFallbacks(s, runeReplacements)
g.screen = s g.screen = s
Screen = s Screen = s
return nil return nil
} }
}
func registerRuneFallbacks(s tcell.Screen, additional map[rune]string) { func registerRuneFallbacks(s tcell.Screen, additional map[rune]string) {
for before, after := range runeReplacements { for before, after := range runeReplacements {
@ -83,7 +86,8 @@ func (g *Gui) tcellInitSimulation(width int, height int) error {
s := tcell.NewSimulationScreen("") s := tcell.NewSimulationScreen("")
if e := s.Init(); e != nil { if e := s.Init(); e != nil {
return e return e
} else { }
g.screen = s g.screen = s
Screen = s Screen = s
// setting to a larger value than the typical terminal size // setting to a larger value than the typical terminal size
@ -92,7 +96,6 @@ func (g *Gui) tcellInitSimulation(width int, height int) error {
s.Sync() s.Sync()
return nil return nil
} }
}
// tcellSetCell sets the character cell at a given location to the given // tcellSetCell sets the character cell at a given location to the given
// content (grapheme cluster) and attributes using provided OutputMode // content (grapheme cluster) and attributes using provided OutputMode
@ -194,9 +197,9 @@ const (
var ( var (
lastMouseKey tcell.ButtonMask = tcell.ButtonNone lastMouseKey tcell.ButtonMask = tcell.ButtonNone
lastMouseMod tcell.ModMask = tcell.ModNone lastMouseMod tcell.ModMask = tcell.ModNone
dragState int = NOT_DRAGGING dragState = NOT_DRAGGING
lastX int = 0 lastX = 0
lastY int = 0 lastY = 0
) )
// this wrapper struct has public keys so we can easily serialize/deserialize to JSON // this wrapper struct has public keys so we can easily serialize/deserialize to JSON

View file

@ -1008,7 +1008,7 @@ func Test_AutoWrapContent(t *testing.T) {
} }
} }
var testContent string = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. var testContent = `Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Quisque vehicula mi at elit pellentesque, eu pulvinar ligula molestie. Quisque vehicula mi at elit pellentesque, eu pulvinar ligula molestie.
In vitae orci vitae elit fermentum lobortis sed in nisi. In vitae orci vitae elit fermentum lobortis sed in nisi.
Nam non odio nisi. Nam non odio nisi.

View file

@ -881,9 +881,9 @@ func (v *View) writeString(s string) {
var linkStartChars = []string{"h", "t", "t", "p", "s", ":", "/", "/"} var linkStartChars = []string{"h", "t", "t", "p", "s", ":", "/", "/"}
func findLinkStart(line []cell) int { func findLinkStart(line []cell) int {
for i := 0; i < len(line)-len(linkStartChars); i++ { for i := range len(line) - len(linkStartChars) {
for j := range linkStartChars { for j := range linkStartChars {
if line[i+j].chr != string(linkStartChars[j]) { if line[i+j].chr != linkStartChars[j] {
break break
} }
if j == len(linkStartChars)-1 { if j == len(linkStartChars)-1 {
@ -899,7 +899,7 @@ func findLinkStart(line []cell) int {
// enough, because in markdown it's common to have a hyperlink followed by a // enough, because in markdown it's common to have a hyperlink followed by a
// ')', so we want to stop there. Hopefully URLs containing ')' are uncommon // ')', so we want to stop there. Hopefully URLs containing ')' are uncommon
// enough that this is not a problem. // enough that this is not a problem.
var lineEndCharacters map[string]bool = map[string]bool{ var lineEndCharacters = map[string]bool{
"": true, "": true,
" ": true, " ": true,
"\n": true, "\n": true,
@ -927,7 +927,7 @@ func (v *View) autoRenderHyperlinksInCurrentLine() {
if _, ok := lineEndCharacters[line[linkEnd].chr]; ok { if _, ok := lineEndCharacters[line[linkEnd].chr]; ok {
break break
} }
link.WriteString(string(line[linkEnd].chr)) link.WriteString(line[linkEnd].chr)
} }
for i := linkStart; i < linkEnd; i++ { for i := linkStart; i < linkEnd; i++ {
v.lines[v.wy][i].hyperlink = link.String() v.lines[v.wy][i].hyperlink = link.String()
@ -988,7 +988,7 @@ func (v *View) parseInput(ch []byte, width int, x int, _ int) (bool, []cell) {
chr: string(ch), chr: string(ch),
width: width, width: width,
} }
for i := 0; i < repeatCount; i++ { for range repeatCount {
cells = append(cells, c) cells = append(cells, c)
} }
} }
@ -1265,22 +1265,18 @@ func (v *View) draw() {
cellIdx := 0 cellIdx := 0
var c cell var c cell
for { for x < maxX {
if x >= maxX {
break
}
if x < 0 { if x < 0 {
if cellIdx < len(vline.line) { if cellIdx < len(vline.line) {
x += uniseg.StringWidth(vline.line[cellIdx].chr) x += uniseg.StringWidth(vline.line[cellIdx].chr)
cellIdx++ cellIdx++
continue continue
} else { }
// no more characters to write so we're only going to be printing empty cells // no more characters to write so we're only going to be printing empty cells
// past this point // past this point
x = 0 x = 0
} }
}
// if we're out of cells to write, we'll just print empty cells. // if we're out of cells to write, we'll just print empty cells.
if cellIdx > len(vline.line)-1 { if cellIdx > len(vline.line)-1 {
@ -1424,7 +1420,7 @@ func (v *View) BufferLines() []string {
lines := make([]string, len(v.lines)) lines := make([]string, len(v.lines))
for i, l := range v.lines { for i, l := range v.lines {
str := lineType(l).String() str := lineType(l).String()
str = strings.Replace(str, "\x00", "", -1) str = strings.ReplaceAll(str, "\x00", "")
lines[i] = str lines[i] = str
} }
return lines return lines
@ -1447,7 +1443,7 @@ func (v *View) ViewBufferLines() []string {
lines := make([]string, len(v.viewLines)) lines := make([]string, len(v.viewLines))
for i, l := range v.viewLines { for i, l := range v.viewLines {
str := lineType(l.line).String() str := lineType(l.line).String()
str = strings.Replace(str, "\x00", "", -1) str = strings.ReplaceAll(str, "\x00", "")
lines[i] = str lines[i] = str
} }
return lines return lines
@ -1696,7 +1692,7 @@ func (v *View) SelectedLines() []string {
func (v *View) lineContentAtIdx(idx int) string { func (v *View) lineContentAtIdx(idx int) string {
line := v.lines[idx] line := v.lines[idx]
str := lineType(line).String() str := lineType(line).String()
return strings.Replace(str, "\x00", "", -1) return strings.ReplaceAll(str, "\x00", "")
} }
func (v *View) SelectedPoint() (int, int) { func (v *View) SelectedPoint() (int, int) {
@ -1719,9 +1715,9 @@ func (v *View) SelectedLineRange() (int, int) {
if start > end { if start > end {
return end, start return end, start
} else {
return start, end
} }
return start, end
} }
func (v *View) RenderTextArea() { func (v *View) RenderTextArea() {
@ -1773,7 +1769,7 @@ func (v *View) overwriteLines(y int, content string) {
v.wy = y v.wy = y
v.clearViewLines() v.clearViewLines()
lines := strings.Replace(content, "\n", "\x1b[K\n", -1) lines := strings.ReplaceAll(content, "\n", "\x1b[K\n")
// If the last line doesn't end with a linefeed, add the erase command at // If the last line doesn't end with a linefeed, add the erase command at
// the end too // the end too
if !strings.HasSuffix(lines, "\n") { if !strings.HasSuffix(lines, "\n") {
@ -1799,7 +1795,7 @@ func (v *View) OverwriteLinesAndClearEverythingElse(lineCount int, y int, conten
v.overwriteLines(y, content) v.overwriteLines(y, content)
for i := 0; i < y; i += 1 { for i := range y {
v.lines[i] = nil v.lines[i] = nil
} }
@ -1924,9 +1920,9 @@ func (v *View) adjustDownwardScrollAmount(scrollHeight int) int {
} }
if oy+scrollHeight < 0 { if oy+scrollHeight < 0 {
return 0 return 0
} else {
return scrollHeight
} }
return scrollHeight
} }
// scrollMargin is about how many lines must still appear if you scroll // scrollMargin is about how many lines must still appear if you scroll
@ -1938,9 +1934,9 @@ func (v *View) scrollMargin() int {
// we should make this into a field on the view to be configured by the client. // we should make this into a field on the view to be configured by the client.
// For now we're hardcoding it. // For now we're hardcoding it.
return 2 return 2
} else {
return 0
} }
return 0
} }
// Returns true if the view contains a line containing the given text with the given // Returns true if the view contains a line containing the given text with the given
@ -1966,7 +1962,7 @@ func containsColoredTextInLine(fgColorStr string, text string, line []cell) bool
cellColor := tcell.NewHexColor(cell.fgColor.Hex()) cellColor := tcell.NewHexColor(cell.fgColor.Hex())
if cellColor == fgColor { if cellColor == fgColor {
currentMatch += string(cell.chr) currentMatch += cell.chr
} else if currentMatch != "" { } else if currentMatch != "" {
if strings.Contains(currentMatch, text) { if strings.Contains(currentMatch, text) {
return true return true