-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (51 loc) · 1.28 KB
/
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"github.com/gdamore/tcell/v2"
)
const tabWidth = 8
func main() {
log.SetOutput(io.Discard)
logFile := flag.String("log", "", "if not empty, debug log output is written to this file")
flag.Parse()
if *logFile != "" {
f, err := os.OpenFile(*logFile, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
fmt.Printf("Failed to open log file %s for writing: %v\n", *logFile, err)
os.Exit(1)
}
defer f.Close()
log.SetOutput(f)
}
scr, err := tcell.NewScreen()
if err != nil {
fmt.Printf("Couldn't create new screen: %v\n", err)
os.Exit(1)
}
width, height := scr.Size()
log.Printf("Created new screen %dx%d charset = %s", width, height, scr.CharacterSet())
ed := newEditor(scr)
for _, arg := range flag.Args() {
if err := ed.loadBufferFromFile(arg); err != nil {
fmt.Printf("Failed to load file %s: %v\n", arg, err)
os.Exit(1)
}
log.Printf("Loaded file %s into new buffer", arg)
}
if len(flag.Args()) == 0 {
ed.addNewBuffer()
log.Printf("No files provided, created empty buffer")
}
if err := scr.Init(); err != nil {
fmt.Printf("Couldn't init screen: %v\n", err)
os.Exit(1)
}
defer scr.Fini()
log.Printf("Starting editor input loop...")
ed.inputLoop()
log.Printf("Quitting")
}