From a1214eb50750b9d0fb1845cdc67e42b231cbe632 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Wed, 29 May 2024 15:06:35 -0400 Subject: [PATCH] feat: query kitty keyboard at run --- context.go | 2 +- nil_renderer.go | 1 + renderer.go | 4 ++++ screen.go | 3 +++ standard_renderer.go | 6 ++++++ tea.go | 5 +++++ 6 files changed, 20 insertions(+), 1 deletion(-) diff --git a/context.go b/context.go index bbcf5c0b62..2f0c01e8e2 100644 --- a/context.go +++ b/context.go @@ -73,7 +73,7 @@ func newContext(ctx context.Context) *teaContext { c := new(teaContext) c.Context = ctx c.values = make(map[interface{}]interface{}) - // c.kittyFlags = -1 + c.values[ContextKeyKittyFlags] = -1 // Assume no Kitty support by default return c } diff --git a/nil_renderer.go b/nil_renderer.go index 0127477881..e9f8db6b28 100644 --- a/nil_renderer.go +++ b/nil_renderer.go @@ -25,3 +25,4 @@ func (n nilRenderer) bracketedPasteActive() bool { return false } func (n nilRenderer) setWindowTitle(_ string) {} func (n nilRenderer) requestBackgroundColor() {} func (n nilRenderer) requestDeviceAttributes() {} +func (n nilRenderer) requestKittyKeyboard() {} diff --git a/renderer.go b/renderer.go index ee583e9e16..c0ca80ba11 100644 --- a/renderer.go +++ b/renderer.go @@ -77,6 +77,10 @@ type renderer interface { // requestDeviceAttributes requests the terminal to send its device // attributes DA1. requestDeviceAttributes() + + // requestKittyKeyboard sends a request to the terminal to report + // kitty keyboard flags. + requestKittyKeyboard() } // repaintMsg forces a full repaint. diff --git a/screen.go b/screen.go index 8d0370c3a0..6729fe636d 100644 --- a/screen.go +++ b/screen.go @@ -17,6 +17,9 @@ type PasteMsg = input.PasteEvent // using RequestBackgroundColor Cmd. type BackgroundColorMsg = input.BackgroundColorEvent +// KittyKeyboardMsg is used to report Kitty keyboard capabilities. +type KittyKeyboardMsg = input.KittyKeyboardEvent + // PrimaryDeviceAttributesMsg is used to report the terminal's primary device // attributes. type PrimaryDeviceAttributesMsg = input.PrimaryDeviceAttributesEvent diff --git a/standard_renderer.go b/standard_renderer.go index a932b13c7a..fbe345c6d1 100644 --- a/standard_renderer.go +++ b/standard_renderer.go @@ -470,6 +470,12 @@ func (r *standardRenderer) requestDeviceAttributes() { r.execute(ansi.RequestPrimaryDeviceAttributes) } +// requestKittyKeyboard sends a request to the terminal to report +// keyboard events in the Kitty format. +func (r *standardRenderer) requestKittyKeyboard() { + r.execute(ansi.RequestKittyKeyboard) +} + // setIgnoredLines specifies lines not to be touched by the standard Bubble Tea // renderer. func (r *standardRenderer) setIgnoredLines(from int, to int) { diff --git a/tea.go b/tea.go index efe823d2a7..5929b6d5aa 100644 --- a/tea.go +++ b/tea.go @@ -437,6 +437,8 @@ func (p *Program) handleContextMessages(msg Msg) { _, _, l := col.Hsl() p.ctx.hasLightBg = l > 0.5 } + case KittyKeyboardMsg: + p.ctx.SetValue(ContextKeyKittyFlags, int(msg)) } } @@ -548,6 +550,7 @@ func (p *Program) Run() (Model, error) { // Query terminal capabilities. p.renderer.requestBackgroundColor() + p.renderer.requestKittyKeyboard() p.renderer.requestDeviceAttributes() // XXX: Here, we wait for a short period of time to receive terminal @@ -571,6 +574,8 @@ EVENTS: switch msg := msg.(type) { case BackgroundColorMsg: p.handleContextMessages(msg) + case KittyKeyboardMsg: + p.handleContextMessages(msg) case PrimaryDeviceAttributesMsg: break EVENTS }