Fix Staticcheck errors & minor logic simplification (#967)

Simplify logic in ui.go. In that diff, `st` would already have the
Reversed flag set; there's no need to set it again.

Also, minor changes to remove all the statickcheck errors VS code's
Go extension complains about.
This commit is contained in:
Ilya Grigoriev authored and GitHub committed 2022-10-16 18:50:41 +03:00
1 parent e570d5f65b
commit f1312ca969
3 files changed
+17 -21

No files matched your search

+15 -15
View File
@@ -612,21 +612,17 @@ func (nav *nav) exportFiles() {
func (nav *nav) dirPreviewLoop(ui *ui) {
var prevPath string
for {
select {
case dir := <-nav.dirPreviewChan:
if dir == nil && len(gOpts.previewer) != 0 && len(gOpts.cleaner) != 0 && nav.volatilePreview {
cmd := exec.Command(gOpts.cleaner, prevPath)
if err := cmd.Run(); err != nil {
log.Printf("cleaning preview: %s", err)
}
nav.volatilePreview = false
} else if dir != nil {
win := ui.wins[len(ui.wins)-1]
nav.previewDir(dir, win)
prevPath = dir.path
for dir := range nav.dirPreviewChan {
if dir == nil && len(gOpts.previewer) != 0 && len(gOpts.cleaner) != 0 && nav.volatilePreview {
cmd := exec.Command(gOpts.cleaner, prevPath)
if err := cmd.Run(); err != nil {
log.Printf("cleaning preview: %s", err)
}
nav.volatilePreview = false
} else if dir != nil {
win := ui.wins[len(ui.wins)-1]
nav.previewDir(dir, win)
prevPath = dir.path
}
}
}
@@ -665,6 +661,7 @@ func (nav *nav) previewLoop(ui *ui) {
}
}
//lint:ignore U1000 This function is not used on Windows
func matchPattern(pattern, name, path string) bool {
s := name
@@ -1452,7 +1449,7 @@ func (nav *nav) sync() error {
}
oldmarks := nav.marks
err = nav.readMarks()
errMarks := nav.readMarks()
for _, ch := range gOpts.tempmarks {
tmp := string(ch)
if v, e := oldmarks[tmp]; e {
@@ -1460,6 +1457,9 @@ func (nav *nav) sync() error {
}
}
err = nav.readTags()
if errMarks != nil {
return errMarks
}
return err
}
+1 -1
View File
@@ -61,7 +61,7 @@ func listen(l net.Listener) {
func echoerr(c net.Conn, msg string) {
fmt.Fprintln(c, msg)
log.Printf(msg)
log.Print(msg)
}
func echoerrf(c net.Conn, format string, a ...interface{}) {
+1 -5
View File
@@ -468,7 +468,7 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, selections map[string]in
tag, ok := tags[path]
if ok {
if i == dir.pos {
win.print(screen, lnwidth+1, i, st.Reverse(true), tag)
win.print(screen, lnwidth+1, i, st, tag)
} else {
win.print(screen, lnwidth+1, i, tcell.StyleDefault, fmt.Sprintf(gOpts.tagfmt, tag))
}
@@ -626,10 +626,6 @@ func (ui *ui) echomsg(msg string) {
log.Print(msg)
}
func (ui *ui) echomsgf(format string, a ...interface{}) {
ui.echomsg(fmt.Sprintf(format, a...))
}
func (ui *ui) echoerr(msg string) {
ui.msg = fmt.Sprintf(gOpts.errorfmt, msg)
log.Printf("error: %s", msg)