dcs_to_kitty.go 571 B

1234567891011121314151617181920212223242526272829
  1. // License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
  2. package tui
  3. import (
  4. "encoding/base64"
  5. "fmt"
  6. "kitty/tools/utils"
  7. )
  8. var _ = fmt.Print
  9. func DCSToKitty(msgtype, payload string) (string, error) {
  10. data := base64.StdEncoding.EncodeToString(utils.UnsafeStringToBytes(payload))
  11. ans := "\x1bP@kitty-" + msgtype + "|" + data
  12. tmux := TmuxSocketAddress()
  13. if tmux != "" {
  14. err := TmuxAllowPassthrough()
  15. if err != nil {
  16. return "", err
  17. }
  18. ans = "\033Ptmux;\033" + ans + "\033\033\\\033\\"
  19. } else {
  20. ans += "\033\\"
  21. }
  22. return ans, nil
  23. }