diff --git a/ansicolors.go b/ansicolors.go index ee303e2..1a301b0 100644 --- a/ansicolors.go +++ b/ansicolors.go @@ -1,6 +1,6 @@ package termenv -// ANSI color codes +// ANSI color codes. const ( ANSIBlack ANSIColor = iota ANSIRed diff --git a/color.go b/color.go index 1a216e9..eb4f988 100644 --- a/color.go +++ b/color.go @@ -14,7 +14,7 @@ var ( ErrInvalidColor = errors.New("invalid color") ) -// Foreground and Background sequence codes +// Foreground and Background sequence codes. const ( Foreground = "38" Background = "48" diff --git a/output.go b/output.go index ebe48fe..53fcdae 100644 --- a/output.go +++ b/output.go @@ -35,6 +35,8 @@ type Output struct { fgColor Color bgSync *sync.Once bgColor Color + kkpFlags byte + kkpSync *sync.Once } // Environ is an interface for getting environment variables. @@ -205,3 +207,33 @@ func (o Output) Write(p []byte) (int, error) { func (o Output) WriteString(s string) (int, error) { return o.Write([]byte(s)) } + +// KittyKeyboardProtocolSupport returns which progressive enhancements the +// terminal supports for the kitty keyboard protocol. +// +// https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement +// +// The byte returned represents the bitset of supported flags. +// +// 0b1 (01) — Disambiguate escape codes +// 0b10 (02) — Report event types +// 0b100 (04) — Report alternate keys +// 0b1000 (08) — Report all keys as escape codes +// 0b10000 (16) — Report associated text. +func (o Output) KittyKeyboardProtocolSupport() byte { + f := func() { + if !o.isTTY() { + return + } + + o.kkpFlags = o.kittyKeyboardProtocolSupport() + } + + if o.cache { + o.kkpSync.Do(f) + } else { + f() + } + + return o.kkpFlags +} diff --git a/profile.go b/profile.go index fa128e2..17a730f 100644 --- a/profile.go +++ b/profile.go @@ -12,13 +12,13 @@ import ( type Profile int const ( - // TrueColor, 24-bit color profile + // TrueColor, 24-bit color profile. TrueColor = Profile(iota) - // ANSI256, 8-bit color profile + // ANSI256, 8-bit color profile. ANSI256 - // ANSI, 4-bit color profile + // ANSI, 4-bit color profile. ANSI - // Ascii, uncolored profile + // Ascii, uncolored profile. Ascii //nolint:revive ) diff --git a/screen.go b/screen.go index 19f28dc..b7be7af 100644 --- a/screen.go +++ b/screen.go @@ -60,6 +60,11 @@ const ( StartBracketedPasteSeq = "200~" EndBracketedPasteSeq = "201~" + // Kitty Keyboard Protocol. + // https://sw.kovidgoyal.net/kitty/keyboard-protocol + EnableKittyKeyboardProtocol = ">1u" + DisableKittyKeyboardProtocol = " 38 { + break + } + } + + return response, isAttrs, nil +} + // readNextResponse reads either an OSC response or a cursor position response: // - OSC response: "\x1b]11;rgb:1111/1111/1111\x1b\\" // - cursor position response: "\x1b[42;1R" diff --git a/termenv_windows.go b/termenv_windows.go index f9b1def..03bc886 100644 --- a/termenv_windows.go +++ b/termenv_windows.go @@ -54,6 +54,11 @@ func (o Output) backgroundColor() Color { return ANSIColor(0) } +func (o Output) kittyKeyboardProtocolSupport() byte { + // default byte + return 0b00000 +} + // EnableWindowsANSIConsole enables virtual terminal processing on Windows // platforms. This allows the use of ANSI escape sequences in Windows console // applications. Ensure this gets called before anything gets rendered with