-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
88 lines (74 loc) · 1.5 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"bufio"
"golang.org/x/sys/unix"
"os"
"time"
)
// Erow stands for “editor row”,
//and stores a line of text as a pointer to character data and a length
type Erow struct {
size int
bytes []byte
highlights []byte
}
type EditorConfig struct {
cx int
cy int
rowOff int
colOff int
screenRows int
screenCols int
numRows int
row []Erow
dirty int
fileName string
statusMsg string
statusMsgTime time.Time
origTermios unix.Termios
}
var (
E EditorConfig
)
func init() {
w, err := unix.IoctlGetWinsize(int(os.Stdin.Fd()), unix.TIOCGWINSZ)
if err != nil {
panic(err)
}
// set cursor initial positions to 0
E.cx = 0
E.cy = 0
E.rowOff = 0
E.colOff = 0
E.numRows = 0
E.dirty = 0
E.row = nil
E.fileName = ""
E.statusMsg = ""
E.statusMsgTime = time.Time{}
E.screenCols = int(w.Col)
E.screenRows = int(w.Row) - 1
}
func main() {
reader := bufio.NewReader(os.Stdin)
defer clearEntireScreen()
defer getCursorToBegin()
defer disableRawMode()
enableRawMode()
if len(os.Args) > 1 {
fileName := os.Args[1]
E.fileName = fileName
editorOpen(fileName)
}
editorSetStatusMessage("HELP: Ctrl-S = save | Ctrl-Q = quit | Ctrl-F = find")
for {
editorRefreshScreen()
c := editorReadKey(reader)
editorProcessKeypress(c)
}
}
func ctrlKey(c byte) int {
// The CTRL_KEY macro bitwise-ANDs a character with the value 00011111, in binary.
ctrlKey := (c) & 0x1f
return int(ctrlKey)
}