Raw event support with new tcell

This commit is contained in:
Zachary Yedidia 2019-12-31 22:34:43 -05:00
parent a2916c0e32
commit a2f7080602
5 changed files with 16 additions and 11 deletions

View file

@ -7,7 +7,6 @@ import (
"os" "os"
"sort" "sort"
"github.com/zyedidia/tcell"
"github.com/go-errors/errors" "github.com/go-errors/errors"
isatty "github.com/mattn/go-isatty" isatty "github.com/mattn/go-isatty"
"github.com/zyedidia/micro/internal/action" "github.com/zyedidia/micro/internal/action"
@ -16,6 +15,7 @@ import (
"github.com/zyedidia/micro/internal/screen" "github.com/zyedidia/micro/internal/screen"
"github.com/zyedidia/micro/internal/shell" "github.com/zyedidia/micro/internal/shell"
"github.com/zyedidia/micro/internal/util" "github.com/zyedidia/micro/internal/util"
"github.com/zyedidia/tcell"
) )
var ( var (
@ -171,6 +171,8 @@ func main() {
} }
} }
screen.Init()
action.InitBindings() action.InitBindings()
action.InitCommands() action.InitCommands()
@ -188,8 +190,6 @@ func main() {
screen.TermMessage(err) screen.TermMessage(err)
} }
screen.Init()
// If we have an error, we can exit cleanly and not completely // If we have an error, we can exit cleanly and not completely
// mess up the terminal being worked in // mess up the terminal being worked in
// In other words we need to shut down tcell before the program crashes // In other words we need to shut down tcell before the program crashes

2
go.mod
View file

@ -15,7 +15,7 @@ require (
github.com/zyedidia/glob v0.0.0-20170209203856-dd4023a66dc3 github.com/zyedidia/glob v0.0.0-20170209203856-dd4023a66dc3
github.com/zyedidia/poller v0.0.0-20170616160828-ab09682913b7 // indirect github.com/zyedidia/poller v0.0.0-20170616160828-ab09682913b7 // indirect
github.com/zyedidia/pty v2.0.0+incompatible // indirect github.com/zyedidia/pty v2.0.0+incompatible // indirect
github.com/zyedidia/tcell v0.0.0-20200101010555-3d6f590fde0b github.com/zyedidia/tcell v0.0.0-20200101033337-8f44670b0885
github.com/zyedidia/terminal v0.0.0-20180726154117-533c623e2415 github.com/zyedidia/terminal v0.0.0-20180726154117-533c623e2415
golang.org/x/text v0.3.2 golang.org/x/text v0.3.2
gopkg.in/yaml.v2 v2.2.7 gopkg.in/yaml.v2 v2.2.7

4
go.sum
View file

@ -57,6 +57,10 @@ github.com/zyedidia/tcell v0.0.0-20191228235154-5b9bbc0d56c7 h1:Qw5255OIirY741L/
github.com/zyedidia/tcell v0.0.0-20191228235154-5b9bbc0d56c7/go.mod h1:yXgdp23+aW8OMENYVBvpKoeiBtjaVWJ9HhpPDu6LBfM= github.com/zyedidia/tcell v0.0.0-20191228235154-5b9bbc0d56c7/go.mod h1:yXgdp23+aW8OMENYVBvpKoeiBtjaVWJ9HhpPDu6LBfM=
github.com/zyedidia/tcell v0.0.0-20200101010555-3d6f590fde0b h1:WOYC0HHwRKNvDcvVbm5QXfjD+uoBvnqqSxRdjlsXIq0= github.com/zyedidia/tcell v0.0.0-20200101010555-3d6f590fde0b h1:WOYC0HHwRKNvDcvVbm5QXfjD+uoBvnqqSxRdjlsXIq0=
github.com/zyedidia/tcell v0.0.0-20200101010555-3d6f590fde0b/go.mod h1:b7qO+6WpCTSDPZ3ru7R2FNZeEtcNpo+X8m+5Py0/l64= github.com/zyedidia/tcell v0.0.0-20200101010555-3d6f590fde0b/go.mod h1:b7qO+6WpCTSDPZ3ru7R2FNZeEtcNpo+X8m+5Py0/l64=
github.com/zyedidia/tcell v0.0.0-20200101030217-abaa2102dece h1:Qj15gTpYWVtGA9K7LFkiuBbk5BjMfJJZhrw3e+zKI2k=
github.com/zyedidia/tcell v0.0.0-20200101030217-abaa2102dece/go.mod h1:b7qO+6WpCTSDPZ3ru7R2FNZeEtcNpo+X8m+5Py0/l64=
github.com/zyedidia/tcell v0.0.0-20200101033337-8f44670b0885 h1:BB7VLUCQCQm7vQYrePdVzoCtbacfdiHfGJ7NzkoEYeA=
github.com/zyedidia/tcell v0.0.0-20200101033337-8f44670b0885/go.mod h1:b7qO+6WpCTSDPZ3ru7R2FNZeEtcNpo+X8m+5Py0/l64=
github.com/zyedidia/terminal v0.0.0-20180726154117-533c623e2415 h1:752dTQ5OatJ9M5ULK2+9lor+nzyZz+LYDo3WGngg3Rc= github.com/zyedidia/terminal v0.0.0-20180726154117-533c623e2415 h1:752dTQ5OatJ9M5ULK2+9lor+nzyZz+LYDo3WGngg3Rc=
github.com/zyedidia/terminal v0.0.0-20180726154117-533c623e2415/go.mod h1:8leT8G0Cm8NoJHdrrKHyR9MirWoF4YW7pZh06B6H+1E= github.com/zyedidia/terminal v0.0.0-20180726154117-533c623e2415/go.mod h1:8leT8G0Cm8NoJHdrrKHyR9MirWoF4YW7pZh06B6H+1E=
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

View file

@ -9,9 +9,9 @@ import (
"unicode" "unicode"
"github.com/flynn/json5" "github.com/flynn/json5"
"github.com/zyedidia/tcell"
"github.com/zyedidia/micro/internal/config" "github.com/zyedidia/micro/internal/config"
"github.com/zyedidia/micro/internal/screen" "github.com/zyedidia/micro/internal/screen"
"github.com/zyedidia/tcell"
) )
func InitBindings() { func InitBindings() {
@ -83,6 +83,7 @@ modSearch:
k = k[5:] k = k[5:]
modifiers |= tcell.ModShift modifiers |= tcell.ModShift
case strings.HasPrefix(k, "\x1b"): case strings.HasPrefix(k, "\x1b"):
screen.Screen.RegisterRawSeq(k)
return RawEvent{ return RawEvent{
esc: k, esc: k,
}, true }, true

View file

@ -6,13 +6,13 @@ import (
luar "layeh.com/gopher-luar" luar "layeh.com/gopher-luar"
"github.com/zyedidia/tcell"
lua "github.com/yuin/gopher-lua" lua "github.com/yuin/gopher-lua"
"github.com/zyedidia/micro/internal/buffer" "github.com/zyedidia/micro/internal/buffer"
"github.com/zyedidia/micro/internal/config" "github.com/zyedidia/micro/internal/config"
"github.com/zyedidia/micro/internal/display" "github.com/zyedidia/micro/internal/display"
ulua "github.com/zyedidia/micro/internal/lua" ulua "github.com/zyedidia/micro/internal/lua"
"github.com/zyedidia/micro/internal/screen" "github.com/zyedidia/micro/internal/screen"
"github.com/zyedidia/tcell"
) )
type BufKeyAction func(*BufPane) bool type BufKeyAction func(*BufPane) bool
@ -261,11 +261,11 @@ func (h *BufPane) HandleEvent(event tcell.Event) {
} }
switch e := event.(type) { switch e := event.(type) {
// case *tcell.EventRaw: case *tcell.EventRaw:
// re := RawEvent{ re := RawEvent{
// esc: e.EscSeq(), esc: e.EscSeq(),
// } }
// h.DoKeyEvent(re) h.DoKeyEvent(re)
case *tcell.EventPaste: case *tcell.EventPaste:
h.paste(e.Text()) h.paste(e.Text())
h.Relocate() h.Relocate()