Skip to content

Commit

Permalink
fix: kitty: request protocol flags and rename flag methods
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Aug 14, 2024
1 parent 68fb9aa commit 9e4c646
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
30 changes: 20 additions & 10 deletions kitty.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ func DisableKittyKeyboard() Msg {
return setKittyKeyboardFlagsMsg(0)
}

// requestKittyKeyboardFlagsMsg is a message to request the current Kitty keyboard
// progressive enhancement protocol flags.
type requestKittyKeyboardFlagsMsg struct{}

// RequestKittyKeyboardFlags is a command to request the current Kitty keyboard
// progressive enhancement protocol flags from the terminal.
func RequestKittyKeyboardFlags() Msg {
return requestKittyKeyboardFlagsMsg{}
}

// EnableEnhancedKeyboard is a command to enable enhanced keyboard features.
// This unambiguously reports more key combinations than traditional terminal
// keyboard sequences. This will also enable reporting of release key events.
Expand All @@ -51,28 +61,28 @@ func DisableEnhancedKeyboard() Msg {
// KittyKeyboardMsg represents Kitty keyboard progressive enhancement flags message.
type KittyKeyboardMsg int

// IsDisambiguateEscapeCodes returns true if the DisambiguateEscapeCodes flag is set.
func (e KittyKeyboardMsg) IsDisambiguateEscapeCodes() bool {
// HasDisambiguateEscapeCodes returns true if the DisambiguateEscapeCodes flag is set.
func (e KittyKeyboardMsg) HasDisambiguateEscapeCodes() bool {
return e&ansi.KittyDisambiguateEscapeCodes != 0
}

// IsReportEventTypes returns true if the ReportEventTypes flag is set.
func (e KittyKeyboardMsg) IsReportEventTypes() bool {
// HasReportEventTypes returns true if the ReportEventTypes flag is set.
func (e KittyKeyboardMsg) HasReportEventTypes() bool {
return e&ansi.KittyReportEventTypes != 0
}

// IsReportAlternateKeys returns true if the ReportAlternateKeys flag is set.
func (e KittyKeyboardMsg) IsReportAlternateKeys() bool {
// HasReportAlternateKeys returns true if the ReportAlternateKeys flag is set.
func (e KittyKeyboardMsg) HasReportAlternateKeys() bool {
return e&ansi.KittyReportAlternateKeys != 0
}

// IsReportAllKeys returns true if the ReportAllKeys flag is set.
func (e KittyKeyboardMsg) IsReportAllKeys() bool {
// HasReportAllKeys returns true if the ReportAllKeys flag is set.
func (e KittyKeyboardMsg) HasReportAllKeys() bool {
return e&ansi.KittyReportAllKeys != 0
}

// IsReportAssociatedKeys returns true if the ReportAssociatedKeys flag is set.
func (e KittyKeyboardMsg) IsReportAssociatedKeys() bool {
// HasReportAssociatedKeys returns true if the ReportAssociatedKeys flag is set.
func (e KittyKeyboardMsg) HasReportAssociatedKeys() bool {
return e&ansi.KittyReportAssociatedKeys != 0
}

Expand Down
7 changes: 7 additions & 0 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,17 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) {
p.renderer.execute(ansi.DisableBracketedPaste)
p.bpActive = false

case KittyKeyboardMsg:
// Store the kitty flags whenever they are queried.
p.kittyFlags = int(msg)

case setKittyKeyboardFlagsMsg:
p.kittyFlags = int(msg)
p.renderer.execute(ansi.PushKittyKeyboard(p.kittyFlags))

case requestKittyKeyboardFlagsMsg:
p.renderer.execute(ansi.RequestKittyKeyboard)

case execMsg:
// NB: this blocks.
p.exec(msg.cmd, msg.fn)
Expand Down

0 comments on commit 9e4c646

Please sign in to comment.