-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdired.go
More file actions
53 lines (50 loc) · 1.06 KB
/
dired.go
File metadata and controls
53 lines (50 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"io/ioutil"
"path/filepath"
glisp "github.com/glycerine/zygomys/zygo"
)
func DiredMode(env *glisp.Zlisp) {
dir, perr := filepath.Abs("./")
if perr != nil {
Global.Input = perr.Error()
AddErrorMessage(perr.Error())
return
}
done := false
for !done {
files, err := ioutil.ReadDir(dir)
if err != nil {
Global.Input = err.Error()
AddErrorMessage(err.Error())
return
}
choices := []string{"<Cancel>", "../"}
for _, f := range files {
suffix := ""
if f.IsDir() {
suffix += "/"
}
suffix += " " + f.Mode().String()
choices = append(choices, f.Name()+suffix)
}
choice := editorChoiceIndex("Dired: "+dir, choices, 0)
filechosen := choice - 2
if filechosen == -2 {
return
} else if filechosen == -1 {
dir += "/.."
} else if files[filechosen].IsDir() {
dir += "/" + files[filechosen].Name()
} else {
openFile(dir+"/"+files[filechosen].Name(), env)
done = true
}
dir, err = filepath.Abs(dir)
if err != nil {
Global.Input = err.Error()
AddErrorMessage(err.Error())
return
}
}
}