Miscellaneous tweaks and fixes (#2223)

* Miscellaneous tweaks and fixes

Mostly these were found by running golangci-lint with a bunch of linters
(more than the default set) enabled.

* fmt.Fprint -> fmt.Fprintln where possible

* Remove "nolint:staticcheck" for now
This commit is contained in:
Carlo Teubner authored and GitHub committed 2025-10-28 15:10:32 +11:00
1 parent b12cb33918
commit fc4b3637bb
11 files changed
+105 -108

No files matched your search

+28 -27
View File
@@ -445,7 +445,7 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
if lnwidth > 0 {
var ln string
if gOpts.number && (!gOpts.relativenumber) {
if gOpts.number && !gOpts.relativenumber {
ln = fmt.Sprintf("%*d", lnwidth, i+1+beg)
} else if gOpts.relativenumber {
switch {
@@ -465,23 +465,27 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
path := filepath.Join(dir.path, f.Name())
var fmtStr string
if slices.Contains(visualSelections, path) {
win.print(ui.screen, lnwidth, i, parseEscapeSequence(gOpts.visualfmt), " ")
fmtStr = gOpts.visualfmt
} else if _, ok := context.selections[path]; ok {
win.print(ui.screen, lnwidth, i, parseEscapeSequence(gOpts.selectfmt), " ")
fmtStr = gOpts.selectfmt
} else if slices.Contains(context.clipboard.paths, path) {
if context.clipboard.mode == clipboardCopy {
win.print(ui.screen, lnwidth, i, parseEscapeSequence(gOpts.copyfmt), " ")
fmtStr = gOpts.copyfmt
} else {
win.print(ui.screen, lnwidth, i, parseEscapeSequence(gOpts.cutfmt), " ")
fmtStr = gOpts.cutfmt
}
}
if fmtStr != "" {
win.print(ui.screen, lnwidth, i, parseEscapeSequence(fmtStr), " ")
}
// make space for select marker, and leave another space at the end
maxWidth := win.w - lnwidth - 2
// make extra space to separate windows if drawbox is not enabled
if !gOpts.drawbox {
maxWidth -= 1
maxWidth--
}
tag := " "
@@ -493,8 +497,7 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
var iconDef iconDef
if gOpts.icons {
iconDef = dirStyle.icons.get(f)
icon = append(icon, []rune(iconDef.icon)...)
icon = append(icon, ' ')
icon = slices.Concat([]rune(iconDef.icon), []rune{' '})
}
// subtract space for tag and icon
@@ -531,8 +534,7 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
// print tag separately as it can contain color escape sequences
win.print(ui.screen, lnwidth+1, i, st, fmt.Sprintf(cursorFmt, tag))
line := append(icon, filename...)
line = append(line, ' ')
line := slices.Concat(icon, filename, []rune{' '})
win.print(ui.screen, lnwidth+2, i, st, fmt.Sprintf(cursorFmt, string(line)))
// print over the empty space we reserved for the custom info
@@ -555,7 +557,7 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
win.print(ui.screen, lnwidth+2, i, iconStyle, string(icon))
}
line := append(filename, ' ')
line := slices.Concat(filename, []rune{' '})
win.print(ui.screen, lnwidth+2+runeSliceWidth(icon), i, st, string(line))
// print over the empty space we reserved for the custom info
@@ -948,12 +950,12 @@ func (ui *ui) drawRuler(nav *nav) {
percentage = fmt.Sprintf("%2d%%", beg*100/(tot-nav.height))
}
copy := 0
move := 0
numClipCopy := 0
numClipMove := 0
if nav.clipboard.mode == clipboardCopy {
copy = len(nav.clipboard.paths)
numClipCopy = len(nav.clipboard.paths)
} else {
move = len(nav.clipboard.paths)
numClipMove = len(nav.clipboard.paths)
}
currSelections := nav.currSelections()
@@ -988,9 +990,9 @@ func (ui *ui) drawRuler(nav *nav) {
case "%p":
result = strings.Join(progress, " ")
case "%m":
result = fmt.Sprintf("%.d", move)
result = fmt.Sprintf("%.d", numClipMove)
case "%c":
result = fmt.Sprintf("%.d", copy)
result = fmt.Sprintf("%.d", numClipCopy)
case "%s":
result = fmt.Sprintf("%.d", len(currSelections))
case "%v":
@@ -1079,12 +1081,12 @@ func (ui *ui) drawRulerFile(nav *nav) {
scrollPercentage = fmt.Sprintf("%2d%%", beg*100/(tot-nav.height))
}
var copy []string
var cut []string
var copiedPaths []string
var cutPaths []string
if nav.clipboard.mode == clipboardCopy {
copy = nav.clipboard.paths
copiedPaths = nav.clipboard.paths
} else {
cut = nav.clipboard.paths
cutPaths = nav.clipboard.paths
}
currSelections := nav.currSelections()
@@ -1131,8 +1133,8 @@ func (ui *ui) drawRulerFile(nav *nav) {
Message: ui.msg,
Keys: string(ui.keyCount) + string(ui.keyAcc),
Progress: progress,
Copy: copy,
Cut: cut,
Copy: copiedPaths,
Cut: cutPaths,
Select: currSelections,
Visual: currVSelections,
Index: ind,
@@ -1752,10 +1754,9 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
}
func readCmdEvent(ev tcell.Event) expr {
switch tev := ev.(type) {
case *tcell.EventKey:
if tev, ok := ev.(*tcell.EventKey); ok {
if tev.Key() == tcell.KeyRune {
if tev.Modifiers() == tcell.ModMask(tcell.ModAlt) {
if tev.Modifiers() == tcell.ModAlt {
val := string([]rune{'<', 'a', '-', tev.Rune(), '>'})
if expr, ok := gOpts.cmdkeys[val]; ok {
return expr
@@ -1816,7 +1817,7 @@ func (ui *ui) exportSizes() {
func anyKey() {
fmt.Fprint(os.Stderr, gOpts.waitmsg)
defer fmt.Fprint(os.Stderr, "\n")
defer fmt.Fprintln(os.Stderr)
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
if err != nil {
panic(err)