Comments (14)
And just FYI, this is the vim/nvim color scheme I use, with suport for undercurls, and setting/removing of fg/bg colors in the terminal in pure vimscript:
l
set termguicolors
hi clear
if exists("syntax_on")
syntax reset
endif
set background=dark
let g:colors_name = "kovid"
if has('nvim')
" nvim does not require ctermul and fails if it is present
function! s:h(group, style)
execute "highlight" a:group
\ "guifg=" .(has_key(a:style, "fg") ? a:style.fg : "NONE")
\ "guibg=" .(has_key(a:style, "bg") ? a:style.bg : "NONE")
\ "gui=" .(has_key(a:style, "styles")? a:style.styles : "NONE")
\ "cterm=" .(has_key(a:style, "styles")? a:style.styles : "NONE")
\ "guisp=" .(has_key(a:style, "ul") ? a:style.ul : "fg")
\ "ctermbg=NONE"
endfunction
else
function! s:h(group, style)
execute "highlight" a:group
\ "guifg=" .(has_key(a:style, "fg") ? a:style.fg : "NONE")
\ "guibg=" .(has_key(a:style, "bg") ? a:style.bg : "NONE")
\ "gui=" .(has_key(a:style, "styles")? a:style.styles : "NONE")
\ "cterm=" .(has_key(a:style, "styles")? a:style.styles : "NONE")
\ "guisp=" .(has_key(a:style, "ul") ? a:style.ul : "fg")
\ "ctermul=" .(has_key(a:style, "ul") ? a:style.ul : "NONE")
\ "ctermbg=NONE"
endfunction
endif
" Color definitions
let s:bg = "#242424"
let s:bg_shaded = "#2d2d2d"
let s:bg_intense = "#000000"
let s:bg_highlight = "#ffff66"
let s:bg_fold = "#384048"
let s:cursor = "#656565"
let s:menu = "#444444"
let s:error_color = "darkred" " cant use a hex code for this as it wont work with ctermul
let s:fg = "#e0e0e0"
let s:fg_dull = "#99968b"
let s:fg_inverted = "#000000"
let s:fg_fold = "#a0a8b0"
" General colors
if has('gui_running')
call s:h("Normal", {"bg": s:bg, "fg": s:fg})
else
hi Normal NONE
" Clear the terminal default background and foreground colors, thereby
" improving performance by not needing to set these colors on empty cells.
if has('nvim')
" nvim has no t_ti
call writefile(["\033]10;" . s:fg . "\007\033]11;" . s:bg . "\007"], "/dev/tty", "b")
autocmd VimLeave * call writefile(["\033]110\007\033]111\007"], "/dev/tty", "b")
else
let &t_ti = &t_ti . "\033]10;" . s:fg . "\007\033]11;" . s:bg . "\007"
let &t_te = &t_te . "\033]110\007\033]111\007"
endif
endif
call s:h("Cursor", {"bg": s:cursor})
call s:h("CursorLine", {"bg": s:bg_shaded})
call s:h("CursorColumn", {"bg": s:bg_shaded})
call s:h("ColorColumn", {"bg": s:bg_shaded})
call s:h("NonText", {"fg": s:fg_dull, "bg": s:bg_shaded})
call s:h("StatusLine", {"fg": s:fg, "bg": s:menu})
call s:h("StatusLineNC", {"fg": s:fg_dull, "bg": s:menu})
call s:h("VertSplit", {"bg": s:menu, "fg": s:fg_dull})
call s:h("Folded", {"bg": s:bg_fold, "fg": s:fg_fold})
call s:h("Title", {"fg": s:fg, "styles": "bold"})
call s:h("Visual", {"fg": s:fg, "bg": s:menu})
call s:h("SpecialKey", {"fg": s:fg_dull, "bg": s:menu})
call s:h("MatchParen", {"fg": s:fg, "bg": s:fg_dull, "styles": "bold"})
call s:h("Pmenu", {"fg": s:fg, "bg": s:menu})
call s:h("PmenuSel", {"styles": "reverse"})
call s:h("SpellBad", {"ul": s:error_color, "styles": "undercurl"})
call s:h("Question", {'fg': '#cae682'})
call s:h("LineNr", {"fg": s:fg_dull, "bg": s:bg_intense})
call s:h("CursorLineNr", {"fg": s:fg_inverted, "bg": s:bg_highlight, "styles": "bold"})
" Plugins
call s:h("ALEErrorSign", {"bg": s:bg_intense, "fg": s:fg})
call s:h("ALEWarningSign", {"bg": s:bg_intense, "fg": s:fg})
call s:h("ALEInfoSign", {"bg": s:bg_intense, "fg": s:fg})
call s:h("ALEStyleErrorSign", {"bg": s:bg_intense, "fg": s:fg})
call s:h("ALEStyleWarningSign", {"bg": s:bg_intense, "fg": s:fg})
call s:h("ALEError", {"ul": s:error_color, "styles": "undercurl"})
call s:h("ALEWarning", {"ul": "yellow", "styles": "undercurl"})
call s:h("ALEStyleError", {"ul": "magenta", "styles": "undercurl"})
call s:h("CtrlPLinePre", {"bg": s:bg_highlight})
" Syntax highlighting
call s:h("Todo", {"fg": "orange", 'styles': "italic"})
call s:h("Constant", {"fg": "#e5786d"})
call s:h("String", {"fg": "#95e454"})
call s:h("Identifier", {"fg": "#cae682"})
call s:h("Function", {"fg": "#cae682"})
call s:h("Entity", {"fg": "#cae682"})
call s:h("Type", {"fg": "#cae682"})
call s:h("Statement", {"fg": "#8ac6f2"})
call s:h("Keyword", {"fg": "#8ac6f2"})
call s:h("PreProc", {"fg": "#e5786d"})
call s:h("Number", {"fg": "#e5786d"})
call s:h("Special", {"fg": "#e7f6da"})
call s:h("Include", {"fg": "#facf81"})
call s:h("Comment", {"fg": s:fg_dull, 'styles': "italic"})
from kitty-color-control.
look at hologram.nvim for an example of this.
from kitty-color-control.
Using writefile
seems to work in this plugin: https://github.com/ojroques/vim-oscyank/blob/5d152a9e03ca1c975c1f439456376e01561a02b5/plugin/oscyank.vim#L141
from kitty-color-control.
This works for setting color:
call writefile(["\e]11;blue;\x07"], '/dev/fd/2', 'b')
I do not know if there is a way to get the currently set color back into nvim using escape sequences:
If a ? is given rather than a color specification, kitty will respond with the current value for the specified color.
from kitty-color-control.
You should probably use /dev/tty rather than /dev/fd/2
from kitty-color-control.
You should probably use /dev/tty rather than /dev/fd/2
Thanks for the tip. I tried it, and it works as well. Is there any specific reason why /dev/tty
is preferred?
from kitty-color-control.
I do not know if there is a way to get the currently set color back into nvim using escape sequences:
If a ? is given rather than a color specification, kitty will respond with the current value for the specified color.
@kovidgoyal, what exactly does respond in this case mean? How does kitty put the response in the current window?
I would like to find a way to access the response through nvim, but I am struggling to to get hold of it. If this was possible, I would not need remote control at all.
from kitty-color-control.
from kitty-color-control.
from kitty-color-control.
A naive test:
call writefile(["\x1b]11;?\x1b\\"], '/dev/tty', 'b')
" Also write a newline; as readfile reads lines and kitty’s response does not end with a newline.
"call writefile([''], '/dev/tty', 'a')
echom readfile('/dev/tty', 'b', 1)
This freezes nvim. First I thought it freezes because of the missing newline, so I added it (commented it out again). Then I tried changing the parameters of readfile
('B'
and ''
instead of 'b'
, a higher max
); using the B
flag was the only combination that did not result in freezing, instead 0z
was echoed.
I suspect I would have to start (asynchronously) reading from /dev/tty
before writing to it (and stop afterwards), but I am not aware of any way to achieve this with regular Vimscript.
Maybe nvim’s vim.loop
can provide the necessary means, maybe some kind of file watcher? I will look further into this.
from kitty-color-control.
Just for the record, I also quickly tried the following:
local stdin = vim.loop.new_tty(0, false)
stdin:try_write('\x1b]11;blue\x1b\\')
On macOS it did change the background to blue, and made nvim freeze. On Linux it just outputs x1b]11;bluex1b\
to the terminal.
from kitty-color-control.
I had to use literal ESC characters to make it work on Linux.
local tty = vim.loop.new_tty(0, true)
local osc = [[�]12;blue�\]]
tty:write(osc, function (err)
assert(not err, err)
end)
This still freezes nvim on macOS though.
from kitty-color-control.
I have also thought about directly writing to /dev/tty
like this:
vim.loop.fs_open('/dev/tty', 'r+', 666, function (err, fd)
assert(not error, error)
print(fd)
end)
But on macOS, this crashes nvim.
from kitty-color-control.
This might be useful: https://github.com/ojroques/nvim-osc52/blob/main/lua/osc52.lua#L69
from kitty-color-control.
Related Issues (2)
- How to debug HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kitty-color-control.