-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (40 loc) · 859 Bytes
/
main.go
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
package main
import (
"fmt"
"os"
"github.com/gdamore/tcell/v2"
"github.com/jessehorne/jim/jim"
"github.com/rivo/tview"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("Must specify a directory to open.")
os.Exit(1)
}
dir := os.Args[1]
dirFile, err := os.Open(dir)
if err != nil {
panic(err)
}
defer dirFile.Close()
info, err := dirFile.Stat()
if err != nil {
panic(err)
}
if !info.IsDir() {
panic("Not a directory.")
}
app := tview.NewApplication()
editor := jim.NewEditor(app, dirFile)
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyF1 {
return nil
} else if event.Key() == tcell.KeyCtrlS {
editor.SaveCurrentTab()
}
return event
})
if err := app.SetRoot(editor.Grid, true).SetFocus(editor.Grid).EnableMouse(true).Run(); err != nil {
panic(err)
}
}