Skip to content
Myr

keyboard.go

This file

Path

keyboard.go

59 lines · 1.9 KiB · Go

Last changed by

feat: support extended keyboard enhancements (#1626)Ayman Bagabasbefore adoption05df5ae

History of this file

Take it

1package tea23import (4	"github.com/charmbracelet/x/ansi"5)67// KeyboardEnhancementsMsg is a message that gets sent when the terminal8// supports keyboard enhancements.9type KeyboardEnhancementsMsg struct {10	// Flags is a bitmask of enabled keyboard enhancement features. A non-zero11	// value indicates that at least we have key disambiguation support.12	//13	// See [ansi.KittyReportEventTypes] and other constants for details.14	//15	// Example:16	//17	//  ```go18	//  // The hard way19	//  if msg.Flags&ansi.KittyReportEventTypes != 0 {20	//     // Terminal supports reporting different key event types21	//  }22	//23	//  // The easy way24	//  if msg.SupportsEventTypes() {25	//     // Terminal supports reporting different key event types26	//  }27	//  ```28	Flags int29}3031// SupportsKeyDisambiguation returns whether the terminal supports key32// disambiguation (e.g., distinguishing between different modifier keys).33func (k KeyboardEnhancementsMsg) SupportsKeyDisambiguation() bool {34	return k.Flags > 035}3637// SupportsEventTypes returns whether the terminal supports reporting38// different types of key events (press, release, and repeat).39func (k KeyboardEnhancementsMsg) SupportsEventTypes() bool {40	return k.Flags&ansi.KittyReportEventTypes != 041}4243// SupportsAlternateKeys returns whether the terminal supports reporting44// alternate key codes.45func (k KeyboardEnhancementsMsg) SupportsAlternateKeys() bool {46	return k.Flags&ansi.KittyReportAlternateKeys != 047}4849// SupportsAllKeysAsEscapeCodes returns whether the terminal supports reporting50// all keys as escape codes.51func (k KeyboardEnhancementsMsg) SupportsAllKeysAsEscapeCodes() bool {52	return k.Flags&ansi.KittyReportAllKeysAsEscapeCodes != 053}5455// SupportsAssociatedText returns whether the terminal supports reporting56// associated text with key events.57func (k KeyboardEnhancementsMsg) SupportsAssociatedText() bool {58	return k.Flags&ansi.KittyReportAssociatedKeys != 059}