From a29dab672bf211d25779fcbbc939fb6174776cbf Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 13 Aug 2024 16:47:30 -0400 Subject: [PATCH] feat: add kitty keyboard set flags sequence --- ansi/kitty.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/ansi/kitty.go b/ansi/kitty.go index 5bf89814..b0f40b20 100644 --- a/ansi/kitty.go +++ b/ansi/kitty.go @@ -21,6 +21,47 @@ const ( // See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/ const RequestKittyKeyboard = "\x1b[?u" +// KittyKeyboard returns a sequence to request keyboard enhancements from the terminal. +// The flags argument is a bitmask of the Kitty keyboard protocol flags. While +// mode specifies how the flags should be interpreted. +// +// Possible values for flags mask: +// +// 0: Disable all features +// 1: Disambiguate escape codes +// 2: Report event types +// 4: Report alternate keys +// 8: Report all keys as escape codes +// 16: Report associated text +// +// Possible values for mode: +// +// 1: Set given flags and unset all others +// 2: Set given flags and keep existing flags unchanged +// 3: Unset given flags and keep existing flags unchanged +// +// See https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement +func KittyKeyboard(flags, mode int) string { + return "\x1b[=" + strconv.Itoa(flags) + ";" + strconv.Itoa(mode) + "u" +} + +// SetKittyKeyboard returns a sequence to set the terminal Kitty keyboard +// enhancement flags. +// +// Possible values for flags mask: +// +// 0: Disable all features +// 1: Disambiguate escape codes +// 2: Report event types +// 4: Report alternate keys +// 8: Report all keys as escape codes +// 16: Report associated text +// +// This is equivalent to KittyKeyboard(flags, 1). +func SetKittyKeyboard(flags int) string { + return KittyKeyboard(flags, 1) +} + // PushKittyKeyboard returns a sequence to push the given flags to the terminal // Kitty Keyboard stack. //