Skip to content

Commit

Permalink
feat: query kitty keyboard at run
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed May 29, 2024
1 parent e1f9060 commit a1214eb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions nil_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
4 changes: 4 additions & 0 deletions renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions standard_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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
Expand All @@ -571,6 +574,8 @@ EVENTS:
switch msg := msg.(type) {
case BackgroundColorMsg:
p.handleContextMessages(msg)
case KittyKeyboardMsg:
p.handleContextMessages(msg)
case PrimaryDeviceAttributesMsg:
break EVENTS
}
Expand Down

0 comments on commit a1214eb

Please sign in to comment.