Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions cursed_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ func (s *cursedRenderer) start() {
// Both can coexist; terminals ignore what they don't support.
_, _ = s.scr.WriteString(ansi.SetModifyOtherKeys2)

kittyFlags := ansi.KittyDisambiguateEscapeCodes
if s.lastView.KeyboardEnhancements.ReportEventTypes {
kittyFlags |= ansi.KittyReportEventTypes
}
kittyFlags := keyboardEnhancementsFlags(s.lastView.KeyboardEnhancements)
_, _ = s.scr.WriteString(ansi.KittyKeyboard(kittyFlags, 1))
}

Expand Down Expand Up @@ -379,10 +376,7 @@ func (s *cursedRenderer) flush(closing bool) error {
// Enable modifyOtherKeys and Kitty keyboard protocol.
_, _ = s.scr.WriteString(ansi.SetModifyOtherKeys2)

kittyFlags := ansi.KittyDisambiguateEscapeCodes // always enable basic key disambiguation
if view.KeyboardEnhancements.ReportEventTypes {
kittyFlags |= ansi.KittyReportEventTypes
}
kittyFlags := keyboardEnhancementsFlags(view.KeyboardEnhancements)
_, _ = s.scr.WriteString(ansi.KittyKeyboard(kittyFlags, 1))
if !closing {
// Request keyboard enhancements when they change
Expand Down Expand Up @@ -828,3 +822,20 @@ func viewEquals(a, b *View) bool {

return true
}

func keyboardEnhancementsFlags(ke KeyboardEnhancements) int {
flags := 1 // always enable basic key disambiguation
if ke.ReportEventTypes {
flags |= ansi.KittyReportEventTypes
}
if ke.ReportAlternateKeys {
flags |= ansi.KittyReportAlternateKeys
}
if ke.ReportAllKeysAsEscapeCodes {
flags |= ansi.KittyReportAllKeysAsEscapeCodes
}
if ke.ReportAssociatedText {
flags |= ansi.KittyReportAssociatedKeys
}
return flags
}
18 changes: 18 additions & 0 deletions keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,21 @@ func (k KeyboardEnhancementsMsg) SupportsKeyDisambiguation() bool {
func (k KeyboardEnhancementsMsg) SupportsEventTypes() bool {
return k.Flags&ansi.KittyReportEventTypes != 0
}

// SupportsAlternateKeys returns whether the terminal supports reporting
// alternate key codes.
func (k KeyboardEnhancementsMsg) SupportsAlternateKeys() bool {
return k.Flags&ansi.KittyReportAlternateKeys != 0
}

// SupportsAllKeysAsEscapeCodes returns whether the terminal supports reporting
// all keys as escape codes.
func (k KeyboardEnhancementsMsg) SupportsAllKeysAsEscapeCodes() bool {
return k.Flags&ansi.KittyReportAllKeysAsEscapeCodes != 0
}

// SupportsAssociatedText returns whether the terminal supports reporting
// associated text with key events.
func (k KeyboardEnhancementsMsg) SupportsAssociatedText() bool {
return k.Flags&ansi.KittyReportAssociatedKeys != 0
}
19 changes: 19 additions & 0 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,25 @@ type KeyboardEnhancements struct {
// [KeyPressMsg] with the [Key.IsRepeat] field set indicating that this is
// a it's part of a key repeat sequence.
ReportEventTypes bool

// ReportAlternateKeys requests the terminal to report alternate key values
// in addition to the main ones.
// Note that only key events represented as escape codes will affected by
// this enhancement.
ReportAlternateKeys bool

// ReportAllKeysAsEscapeCodes requests the terminal to report all key
// events, including plain text keys, as escape codes.
// When this is enabled, text won't be sent as plain text but instead as
// escape codes that encode the key value and modifiers.
ReportAllKeysAsEscapeCodes bool

// ReportAssociatedText requests the terminal to report the text associated
// with key events.
// Note that this is an enhancement to
// [KeyboardEnhancements.ReportAllKeysAsEscapeCodes] and only has an effect
// if that is enabled.
ReportAssociatedText bool
}

// SetContent is a helper method to set the content of a [View] with a styled
Expand Down
Loading