osc52.lua 911 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. local tty = false
  2. for _, ui in ipairs(vim.api.nvim_list_uis()) do
  3. if ui.chan == 1 and ui.stdout_tty then
  4. tty = true
  5. break
  6. end
  7. end
  8. -- Do not query when any of the following is true:
  9. -- * TUI is not attached
  10. -- * OSC 52 support is explicitly disabled via g:termfeatures
  11. -- * Using a badly behaved terminal
  12. if
  13. not tty
  14. or (vim.g.termfeatures ~= nil and vim.g.termfeatures.osc52 == false)
  15. or vim.env.TERM_PROGRAM == 'Apple_Terminal'
  16. then
  17. return
  18. end
  19. require('vim.termcap').query('Ms', function(cap, found, seq)
  20. if not found then
  21. return
  22. end
  23. assert(cap == 'Ms')
  24. -- If the terminal reports a sequence other than OSC 52 for the Ms capability
  25. -- then ignore it. We only support OSC 52 (for now)
  26. if not seq or not seq:match('^\027%]52') then
  27. return
  28. end
  29. local termfeatures = vim.g.termfeatures or {}
  30. termfeatures.osc52 = true
  31. vim.g.termfeatures = termfeatures
  32. end)