fix ineffective breaks, remove unused parameters (#210)

While at it, simplify a few pieces of code.
This commit is contained in:
Daniel Martí 2019-08-12 13:52:27 +02:00 committed by gokcehan
parent 3b34b20cb8
commit 50ac367626
9 changed files with 31 additions and 35 deletions

View File

@ -52,7 +52,7 @@ func readExpr() <-chan expr {
c, err := net.Dial(gSocketProt, gSocketPath)
for err != nil {
log.Printf(fmt.Sprintf("connecting server: %s", err))
log.Printf("connecting server: %s", err)
time.Sleep(duration)
duration *= 2
c, err = net.Dial(gSocketProt, gSocketPath)

View File

@ -21,7 +21,6 @@ func init() {
"áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ",
"aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd",
)
}
func appendTransliterate(base, norm string) {

View File

@ -480,7 +480,7 @@ func insert(app *app, arg string) {
normal(app)
if arg == "y" {
if err := app.nav.rename(app.ui); err != nil {
if err := app.nav.rename(); err != nil {
app.ui.echoerrf("rename: %s", err)
return
}
@ -716,7 +716,6 @@ func (e *callExpr) eval(app *app, args []string) {
}
} else {
fileOrSelections, err := app.nav.currFileOrSelections()
if err != nil {
app.ui.echoerrf("delete: %s", err)
return
@ -1098,7 +1097,7 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
if err := app.nav.rename(app.ui); err != nil {
if err := app.nav.rename(); err != nil {
app.ui.echoerrf("rename: %s", err)
return
}

View File

@ -298,13 +298,17 @@ var gEvalTests = []struct {
cd ~
set hidden
}}`,
[]string{"cmd", "gohome", ":", "{{",
[]string{
"cmd", "gohome", ":", "{{",
"cd", "~", "\n",
"set", "hidden", "\n",
"}}", "\n"},
[]expr{&cmdExpr{"gohome", &listExpr{[]expr{
&callExpr{"cd", []string{"~"}, 1},
&setExpr{"hidden", ""}}},
"}}", "\n",
},
[]expr{&cmdExpr{
"gohome", &listExpr{[]expr{
&callExpr{"cd", []string{"~"}, 1},
&setExpr{"hidden", ""},
}},
}},
},
@ -313,13 +317,17 @@ var gEvalTests = []struct {
cd ~
set hidden
}}`,
[]string{"map", "gh", ":", "{{",
[]string{
"map", "gh", ":", "{{",
"cd", "~", "\n",
"set", "hidden", "\n",
"}}", "\n"},
[]expr{&mapExpr{"gh", &listExpr{[]expr{
&callExpr{"cd", []string{"~"}, 1},
&setExpr{"hidden", ""}}},
"}}", "\n",
},
[]expr{&mapExpr{
"gh", &listExpr{[]expr{
&callExpr{"cd", []string{"~"}, 1},
&setExpr{"hidden", ""},
}},
}},
},

4
go.sum
View File

@ -1,8 +1,4 @@
github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4=
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/nsf/termbox-go v0.0.0-20180613055208-5c94acc5e6eb h1:YahEjAGkJtCrkqgVHhX6n8ZX+CZ3hDRL9fjLYugLfSs=
github.com/nsf/termbox-go v0.0.0-20180613055208-5c94acc5e6eb/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e h1:Vbib8wJAaMEF9jusI/kMSYMr/LtRzM7+F9MJgt/nH8k=
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=

9
nav.go
View File

@ -415,7 +415,7 @@ func (nav *nav) preview() {
nav.regChan <- reg
}
func (nav *nav) loadReg(ui *ui, path string) *reg {
func (nav *nav) loadReg(path string) *reg {
r, ok := nav.regCache[path]
if !ok {
go nav.preview()
@ -726,7 +726,6 @@ func (nav *nav) paste(ui *ui) error {
func (nav *nav) del() error {
list, err := nav.currFileOrSelections()
if err != nil {
return err
}
@ -740,7 +739,7 @@ func (nav *nav) del() error {
return nil
}
func (nav *nav) rename(ui *ui) error {
func (nav *nav) rename() error {
oldPath := nav.renameCache[0]
newPath := nav.renameCache[1]
dir, _ := filepath.Split(newPath)
@ -828,7 +827,6 @@ func (nav *nav) globSel(pattern string, invert bool) error {
for i := 0; i < len(curDir.files); i++ {
match, err := filepath.Match(pattern, curDir.files[i].Name())
if err != nil {
return fmt.Errorf("glob-select: %s", err)
}
@ -1007,9 +1005,8 @@ func (nav *nav) removeMark(mark string) error {
if _, ok := nav.marks[mark]; ok {
delete(nav.marks, mark)
return nil
} else {
return fmt.Errorf("no such mark")
}
return fmt.Errorf("no such mark")
}
func (nav *nav) readMarks() error {

View File

@ -18,9 +18,7 @@ var (
envShell = os.Getenv("SHELL")
)
var (
envPathExt = os.Getenv("PATHEXT")
)
var envPathExt = os.Getenv("PATHEXT")
var (
gDefaultShell = "cmd"

View File

@ -58,6 +58,7 @@ func listen(l net.Listener) {
func handleConn(c net.Conn) {
s := bufio.NewScanner(c)
Loop:
for s.Scan() {
log.Printf("listen: %s", s.Text())
word, rest := splitWord(s.Text())
@ -71,7 +72,7 @@ func handleConn(c net.Conn) {
gCopyFile = false
default:
log.Printf("unexpected option to copy file(s): %s", s.Text())
break
break Loop
}
gFileList = nil
for s.Scan() && s.Text() != "" {
@ -120,7 +121,7 @@ func handleConn(c net.Conn) {
c.Close()
}
gListener.Close()
break
break Loop
default:
log.Printf("listen: unexpected command: %s", word)
}

8
ui.go
View File

@ -190,8 +190,6 @@ func (win *win) printReg(reg *reg) {
for i, l := range reg.lines {
fg, bg = win.print(2, i, fg, bg, l)
}
return
}
func fileInfo(f *file, d *dir) string {
@ -539,7 +537,7 @@ func (ui *ui) loadFile(nav *nav) {
if curr.IsDir() {
ui.dirPrev = nav.loadDir(curr.path)
} else if curr.Mode().IsRegular() {
ui.regPrev = nav.loadReg(ui, curr.path)
ui.regPrev = nav.loadReg(curr.path)
}
}
@ -617,7 +615,7 @@ func (ui *ui) drawStatLine(nav *nav) {
ui.msgWin.printRight(0, fg, bg, ruler)
}
func (ui *ui) drawBox(nav *nav) {
func (ui *ui) drawBox() {
fg, bg := termbox.ColorDefault, termbox.ColorDefault
w, h := termbox.Size()
@ -699,7 +697,7 @@ func (ui *ui) draw(nav *nav) {
}
if gOpts.drawbox {
ui.drawBox(nav)
ui.drawBox()
}
if ui.menuBuf != nil {