Added StartOfLine and EndOfLine actions

This commit also adds error reporting for invalid json.

Fixes #36.
This commit is contained in:
Zachary Yedidia
2016-04-24 09:01:01 -04:00
parent d088b7c2df
commit 8807ede224
3 changed files with 35 additions and 4 deletions

View File

@@ -48,6 +48,8 @@ func InitBindings() {
"PageDown": PageDown,
"HalfPageUp": HalfPageUp,
"HalfPageDown": HalfPageDown,
"StartOfLine": StartOfLine,
"EndOfLine": EndOfLine,
"ToggleRuler": ToggleRuler,
}
@@ -186,11 +188,14 @@ func InitBindings() {
if _, e := os.Stat(filename); e == nil {
input, err := ioutil.ReadFile(filename)
if err != nil {
TermMessage("Error reading settings.json file: " + err.Error())
TermMessage("Error reading bindings.json file: " + err.Error())
return
}
json.Unmarshal(input, &parsed)
err = json.Unmarshal(input, &parsed)
if err != nil {
TermMessage("Error reading bindings.json:", err.Error())
}
}
for k, v := range defaults {
@@ -393,6 +398,8 @@ func Save(v *View) bool {
return true
}
// GoSave saves the current file (must be a go file) and runs goimports or gofmt
// depending on the user's configuration
func GoSave(v *View) {
if settings.GoImports == true {
messenger.Message("Running goimports...")
@@ -474,7 +481,7 @@ func Copy(v *View) bool {
return true
}
// AddCopy appends to the clipboard
// CutLine cuts the current line to the clipboard
func CutLine(v *View) bool {
v.cursor.SelectLine()
if v.freshClip == true {
@@ -622,6 +629,18 @@ func ToggleRuler(v *View) bool {
return false
}
// StartOfLine moves the cursor to the start of the line
func StartOfLine(v *View) bool {
v.cursor.Start()
return true
}
// EndOfLine moves the cursor to the end of the line
func EndOfLine(v *View) bool {
v.cursor.End()
return true
}
// None is no action
func None() bool {
return false

View File

@@ -17,11 +17,20 @@ import (
// This will write the message, and wait for the user
// to press and key to continue
func TermMessage(msg ...interface{}) {
screenWasNil := screen == nil
if !screenWasNil {
screen.Fini()
}
fmt.Println(msg...)
fmt.Print("\nPress enter to continue")
reader := bufio.NewReader(os.Stdin)
reader.ReadString('\n')
if !screenWasNil {
InitScreen()
}
}
// TermError sends an error to the user in the terminal. Like TermMessage except formatted

View File

@@ -36,7 +36,10 @@ func InitSettings() {
return
}
json.Unmarshal(input, &settings)
err = json.Unmarshal(input, &settings)
if err != nil {
TermMessage("Error reading settings.json:", err.Error())
}
} else {
settings = DefaultSettings()
err := WriteSettings(filename)