From 96601a915d8bccdd3e3b7336c4ea26154535cc1d Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Sat, 5 Sep 2020 21:59:19 -0400 Subject: [PATCH] Replace meta with alt automatically, update tcell --- go.mod | 3 ++- go.sum | 6 ++++-- internal/action/bufpane.go | 4 ++-- internal/action/events.go | 12 ++++++++++-- internal/action/infopane.go | 2 +- internal/action/termpane.go | 2 +- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 5b81536e..136d901f 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,8 @@ require ( github.com/zyedidia/highlight v0.0.0-20170330143449-201131ce5cf5 github.com/zyedidia/json5 v0.0.0-20200102012142-2da050b1a98d github.com/zyedidia/pty v2.0.0+incompatible // indirect - github.com/zyedidia/tcell/v2 v2.0.0 + github.com/zyedidia/tcell v1.4.12 + github.com/zyedidia/tcell/v2 v2.0.1 github.com/zyedidia/terminal v0.0.0-20180726154117-533c623e2415 golang.org/x/text v0.3.2 gopkg.in/sourcemap.v1 v1.0.5 // indirect diff --git a/go.sum b/go.sum index 9a36f2fb..90c1d596 100644 --- a/go.sum +++ b/go.sum @@ -35,6 +35,8 @@ github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/xo/terminfo v0.0.0-20200218205459-454e5b68f9e8 h1:woqigIZtZUZxws1zZA99nAvuz2mQrxtWsuZSR9c8I/A= +github.com/xo/terminfo v0.0.0-20200218205459-454e5b68f9e8/go.mod h1:6Yhx5ZJl5942QrNRWLwITArVT9okUXc5c3brgWJMoDc= github.com/yuin/gopher-lua v0.0.0-20190206043414-8bfc7677f583/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ= github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb h1:ZkM6LRnq40pR1Ox0hTHlnpkcOTuFIDQpZ1IN8rKKhX0= github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ= @@ -54,8 +56,8 @@ github.com/zyedidia/pty v2.0.0+incompatible h1:Ou5vXL6tvjst+RV8sUFISbuKDnUJPhnpy github.com/zyedidia/pty v2.0.0+incompatible/go.mod h1:4y9l9yJZNxRa7GB/fB+mmDmGkG3CqmzLf4vUxGGotEA= github.com/zyedidia/tcell v1.4.12 h1:PwsWfTKDvgSsMKL8QfFqxrD2qxZk6apxxKOJwjhLbxs= github.com/zyedidia/tcell v1.4.12/go.mod h1:HhlbMSCcGX15rFDB+Q1Lk3pKEOocsCUAQC3zhZ9sadA= -github.com/zyedidia/tcell/v2 v2.0.0 h1:d6q7nFhAkbCdK3znpOfsStRIbavCvHX0wb7h3NJ4Lzc= -github.com/zyedidia/tcell/v2 v2.0.0/go.mod h1:PT4YXe+nkU4iuQAPFfkMAZAYFQEnscyAxKsZ9B5Kl1w= +github.com/zyedidia/tcell/v2 v2.0.1 h1:mGHCwOxIcvd8/x4W4fV+A2Z9pf06sYiepADvyhmD7D8= +github.com/zyedidia/tcell/v2 v2.0.1/go.mod h1:i4NNlquIQXFeNecrOgxDQQJdu+7LmTi3g62asvmwUws= 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/bufpane.go b/internal/action/bufpane.go index 89a372c9..129de8b4 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -345,7 +345,7 @@ func (h *BufPane) HandleEvent(event tcell.Event) { case *tcell.EventKey: ke := KeyEvent{ code: e.Key(), - mod: e.Modifiers(), + mod: metaToAlt(e.Modifiers()), r: e.Rune(), } @@ -395,7 +395,7 @@ func (h *BufPane) HandleEvent(event tcell.Event) { if !cancel { me := MouseEvent{ btn: e.Buttons(), - mod: e.Modifiers(), + mod: metaToAlt(e.Modifiers()), } h.DoMouseEvent(me, e) } diff --git a/internal/action/events.go b/internal/action/events.go index cf86a4ae..3a4834f6 100644 --- a/internal/action/events.go +++ b/internal/action/events.go @@ -36,6 +36,14 @@ type KeyEvent struct { any bool } +func metaToAlt(mod tcell.ModMask) tcell.ModMask { + if mod&tcell.ModMeta != 0 { + mod &= ^tcell.ModMeta + mod |= tcell.ModAlt + } + return mod +} + func (k KeyEvent) Name() string { if k.any { return "" @@ -132,7 +140,7 @@ func ConstructEvent(event tcell.Event) (Event, error) { case *tcell.EventKey: return KeyEvent{ code: e.Key(), - mod: e.Modifiers(), + mod: metaToAlt(e.Modifiers()), r: e.Rune(), }, nil case *tcell.EventRaw: @@ -142,7 +150,7 @@ func ConstructEvent(event tcell.Event) (Event, error) { case *tcell.EventMouse: return MouseEvent{ btn: e.Buttons(), - mod: e.Modifiers(), + mod: metaToAlt(e.Modifiers()), }, nil } return nil, errors.New("No micro event equivalent") diff --git a/internal/action/infopane.go b/internal/action/infopane.go index acf8563d..f1518558 100644 --- a/internal/action/infopane.go +++ b/internal/action/infopane.go @@ -83,7 +83,7 @@ func (h *InfoPane) HandleEvent(event tcell.Event) { case *tcell.EventKey: ke := KeyEvent{ code: e.Key(), - mod: e.Modifiers(), + mod: metaToAlt(e.Modifiers()), r: e.Rune(), } diff --git a/internal/action/termpane.go b/internal/action/termpane.go index cf5e33c4..ec52faff 100644 --- a/internal/action/termpane.go +++ b/internal/action/termpane.go @@ -120,7 +120,7 @@ func (t *TermPane) HandleEvent(event tcell.Event) { if e, ok := event.(*tcell.EventKey); ok { ke := KeyEvent{ code: e.Key(), - mod: e.Modifiers(), + mod: metaToAlt(e.Modifiers()), r: e.Rune(), } action, more := TermBindings.NextEvent(ke, nil)