From a2f70806024a71868b39c818aa4cd4198937d1c3 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Tue, 31 Dec 2019 22:34:43 -0500 Subject: [PATCH] Raw event support with new tcell --- cmd/micro/micro.go | 6 +++--- go.mod | 2 +- go.sum | 4 ++++ internal/action/bindings.go | 3 ++- internal/action/bufpane.go | 12 ++++++------ 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index d1c59136..152681d4 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -7,7 +7,6 @@ import ( "os" "sort" - "github.com/zyedidia/tcell" "github.com/go-errors/errors" isatty "github.com/mattn/go-isatty" "github.com/zyedidia/micro/internal/action" @@ -16,6 +15,7 @@ import ( "github.com/zyedidia/micro/internal/screen" "github.com/zyedidia/micro/internal/shell" "github.com/zyedidia/micro/internal/util" + "github.com/zyedidia/tcell" ) var ( @@ -171,6 +171,8 @@ func main() { } } + screen.Init() + action.InitBindings() action.InitCommands() @@ -188,8 +190,6 @@ func main() { screen.TermMessage(err) } - screen.Init() - // If we have an error, we can exit cleanly and not completely // mess up the terminal being worked in // In other words we need to shut down tcell before the program crashes diff --git a/go.mod b/go.mod index 52dbdd19..a64df3c6 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/zyedidia/glob v0.0.0-20170209203856-dd4023a66dc3 github.com/zyedidia/poller v0.0.0-20170616160828-ab09682913b7 // 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 golang.org/x/text v0.3.2 gopkg.in/yaml.v2 v2.2.7 diff --git a/go.sum b/go.sum index 09d40ed7..2886f78a 100644 --- a/go.sum +++ b/go.sum @@ -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-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-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/go.mod h1:8leT8G0Cm8NoJHdrrKHyR9MirWoF4YW7pZh06B6H+1E= golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/internal/action/bindings.go b/internal/action/bindings.go index 5ffc2eef..3d1162fa 100644 --- a/internal/action/bindings.go +++ b/internal/action/bindings.go @@ -9,9 +9,9 @@ import ( "unicode" "github.com/flynn/json5" - "github.com/zyedidia/tcell" "github.com/zyedidia/micro/internal/config" "github.com/zyedidia/micro/internal/screen" + "github.com/zyedidia/tcell" ) func InitBindings() { @@ -83,6 +83,7 @@ modSearch: k = k[5:] modifiers |= tcell.ModShift case strings.HasPrefix(k, "\x1b"): + screen.Screen.RegisterRawSeq(k) return RawEvent{ esc: k, }, true diff --git a/internal/action/bufpane.go b/internal/action/bufpane.go index 3da74e49..f3a734da 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -6,13 +6,13 @@ import ( luar "layeh.com/gopher-luar" - "github.com/zyedidia/tcell" lua "github.com/yuin/gopher-lua" "github.com/zyedidia/micro/internal/buffer" "github.com/zyedidia/micro/internal/config" "github.com/zyedidia/micro/internal/display" ulua "github.com/zyedidia/micro/internal/lua" "github.com/zyedidia/micro/internal/screen" + "github.com/zyedidia/tcell" ) type BufKeyAction func(*BufPane) bool @@ -261,11 +261,11 @@ func (h *BufPane) HandleEvent(event tcell.Event) { } switch e := event.(type) { - // case *tcell.EventRaw: - // re := RawEvent{ - // esc: e.EscSeq(), - // } - // h.DoKeyEvent(re) + case *tcell.EventRaw: + re := RawEvent{ + esc: e.EscSeq(), + } + h.DoKeyEvent(re) case *tcell.EventPaste: h.paste(e.Text()) h.Relocate()