Add simulation screen tests

This commit is contained in:
Zachary Yedidia
2020-06-20 18:24:12 -04:00
parent a9ca57af6e
commit d0b75bc09f
9 changed files with 389 additions and 17 deletions

View File

@@ -82,7 +82,7 @@ modSearch:
case strings.HasPrefix(k, "-"):
// We optionally support dashes between modifiers
k = k[1:]
case strings.HasPrefix(k, "Ctrl") && k != "Ctrl-h" && k != "CtrlH" && k != "Ctrlh":
case strings.HasPrefix(k, "Ctrl") && k != "CtrlH":
// CtrlH technically does not have a 'Ctrl' modifier because it is really backspace
k = k[4:]
modifiers |= tcell.ModCtrl

View File

@@ -30,8 +30,9 @@ func DefaultBindings() map[string]string {
"Alt-{": "ParagraphPrevious",
"Alt-}": "ParagraphNext",
"Enter": "InsertNewline",
"Ctrl-h": "Backspace",
"CtrlH": "Backspace",
"Backspace": "Backspace",
"OldBackspace": "Backspace",
"Alt-CtrlH": "DeleteWordLeft",
"Alt-Backspace": "DeleteWordLeft",
"Tab": "Autocomplete|IndentSelection|InsertTab",

View File

@@ -32,8 +32,9 @@ func DefaultBindings() map[string]string {
"Alt-{": "ParagraphPrevious",
"Alt-}": "ParagraphNext",
"Enter": "InsertNewline",
"Ctrl-h": "Backspace",
"CtrlH": "Backspace",
"Backspace": "Backspace",
"OldBackspace": "Backspace",
"Alt-CtrlH": "DeleteWordLeft",
"Alt-Backspace": "DeleteWordLeft",
"Tab": "Autocomplete|IndentSelection|InsertTab",

View File

@@ -1,7 +1,7 @@
package screen
import (
"fmt"
"errors"
"os"
"sync"
"unicode"
@@ -131,7 +131,7 @@ func TempStart(screenWasNil bool) {
}
// Init creates and initializes the tcell screen
func Init() {
func Init() error {
drawChan = make(chan bool, 8)
// Should we enable true color?
@@ -151,13 +151,10 @@ func Init() {
var err error
Screen, err = tcell.NewScreen()
if err != nil {
fmt.Println(err)
fmt.Println("Fatal: Micro could not initialize a Screen.")
os.Exit(1)
return err
}
if err = Screen.Init(); err != nil {
fmt.Println(err)
os.Exit(1)
return err
}
// restore TERM
@@ -168,4 +165,30 @@ func Init() {
if config.GetGlobalOption("mouse").(bool) {
Screen.EnableMouse()
}
return nil
}
// InitSimScreen initializes a simulation screen for testing purposes
func InitSimScreen() (tcell.SimulationScreen, error) {
drawChan = make(chan bool, 8)
// Initilize tcell
var err error
s := tcell.NewSimulationScreen("")
if s == nil {
return nil, errors.New("Failed to get a simulation screen")
}
if err = s.Init(); err != nil {
return nil, err
}
s.SetSize(80, 24)
Screen = s
if config.GetGlobalOption("mouse").(bool) {
Screen.EnableMouse()
}
return s, nil
}