You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
1.3 KiB
82 lines
1.3 KiB
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"syscall"
|
|
)
|
|
|
|
var Version = "0.0.0-dev"
|
|
|
|
var state editorState
|
|
|
|
type editorState struct {
|
|
orig syscall.Termios
|
|
Buffer *bytes.Buffer
|
|
Cx int
|
|
Cy int
|
|
Rows int
|
|
Cols int
|
|
StatusLines [2]string
|
|
DebugLine string
|
|
rows []string
|
|
rowOffset int
|
|
colOffset int
|
|
file string
|
|
}
|
|
|
|
func (es editorState) getCurrentRowLen() int {
|
|
return es.getRowLen(es.Cy)
|
|
}
|
|
|
|
func (es editorState) getRowLen(lineNumber int) int {
|
|
if lineNumber >= len(es.rows) {
|
|
return 0
|
|
}
|
|
|
|
row := es.rows[lineNumber]
|
|
_, l := renderLine(row)
|
|
|
|
return l
|
|
}
|
|
|
|
func main() {
|
|
defer cleanup()
|
|
enableRawMode()
|
|
initEditor()
|
|
if len(os.Args) > 1 {
|
|
fileOpen(os.Args[1])
|
|
}
|
|
|
|
uiRefresh()
|
|
for editorKeyPresses() {
|
|
uiRefresh()
|
|
}
|
|
}
|
|
|
|
func initEditor() {
|
|
var err error
|
|
if state.Rows, state.Cols, err = getWindowSize(); err != nil {
|
|
log.Fatalf("COULD NOT GET WINDOW SIZE: %v", err)
|
|
}
|
|
|
|
state.Cx = 0
|
|
state.Buffer = &bytes.Buffer{}
|
|
state.rows = []string{fmt.Sprintf("Pound Ed %s", Version)}
|
|
state.file = ""
|
|
state.StatusLines = [2]string{}
|
|
}
|
|
|
|
func cleanup() {
|
|
disableRawMode()
|
|
uiClearScreen()
|
|
|
|
return
|
|
if r := recover(); r != nil {
|
|
fmt.Fprintf(os.Stderr, "Unrecoverable error:\n\t%+v\n", r)
|
|
os.Exit(-1)
|
|
}
|
|
}
|