mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-25 03:02:21 +08:00
Compare commits
28 Commits
49cee0362f
...
3ed7c00d06
Author | SHA1 | Date | |
---|---|---|---|
|
3ed7c00d06 | ||
|
fd8c555c88 | ||
|
e291cd136e | ||
|
32f30ddb78 | ||
|
e17ac3c1a6 | ||
|
8ff37e2a98 | ||
|
b0f1e65b35 | ||
|
85f97eedb2 | ||
|
e8da1052d4 | ||
|
5bc06e128b | ||
|
3c87db406c | ||
|
e143116bc5 | ||
|
f6deb0bd9a | ||
|
dcde04c454 | ||
|
f35e0da911 | ||
|
a9a14ff85b | ||
|
98e67a214c | ||
|
cd08e2430b | ||
|
b4e860322d | ||
|
856f19e9c1 | ||
|
7a46d76135 | ||
|
d8524a61d8 | ||
|
ff20c0284b | ||
|
0d84d91b4e | ||
|
6a303b7896 | ||
|
9df25cac4c | ||
|
b6ccf093cd | ||
|
c4a7b0f7c1 |
35
README.md
35
README.md
@ -1,29 +1,26 @@
|
||||
<h1 align="center">
|
||||
<a href="https://github.com/SpaceVim/SpaceVim#readme">
|
||||
<a href="https://spacevim.org">
|
||||
<img src="https://spacevim.org/logo.png" width="440" alt="SpaceVim"/>
|
||||
</a>
|
||||
</h1>
|
||||
|
||||
[Quick Start Guide](https://spacevim.org/quick-start-guide/) \|
|
||||
[FAQ](https://spacevim.org/faq/)
|
||||
[](https://app.element.io/#/room/#spacevim:matrix.org)
|
||||
[](https://t.me/SpaceVim/)
|
||||
[](https://twitter.com/SpaceVim)
|
||||
[](development/#license)
|
||||
[](https://www.reddit.com/r/SpaceVim/)
|
||||
|
||||
[](https://github.com/SpaceVim/SpaceVim/actions/workflows/check.yml?query=branch%3Amaster)
|
||||
[](https://codecov.io/gh/SpaceVim/SpaceVim)
|
||||
[](https://github.com/SpaceVim/SpaceVim/blob/master/LICENSE)
|
||||
[](https://hub.docker.com/r/spacevim/spacevim)
|
||||

|
||||
|
||||
SpaceVim is a (neo)vim configuration inspired by spacemacs.
|
||||
SpaceVim is a modular configuration of Vim and Neovim.
|
||||
It's inspired by spacemacs. It manages collections of plugins in layers,
|
||||
which help to collect related packages together to provide features.
|
||||
This approach helps keep the configuration organized and reduces
|
||||
overhead for the user by keeping them from having to think about
|
||||
what packages to install.
|
||||
|
||||
## Features
|
||||
|
||||
- **Modularization:** plugins and functions are organized in [layers](https://spacevim.org/layers/).
|
||||
- **Compatible api:** a series of [compatible APIs](https://spacevim.org/api/) for Vim/Neovim.
|
||||
- **Great documentation:** online [documentation](https://spacevim.org/documentation/) and `:h SpaceVim`.
|
||||
- **Better experience:** [Use lua to implement core plugins](https://spacevim.org/use-lua-to-reimplement-core-plugins/)
|
||||
- **Beautiful UI:** you'll love the awesome UI and its useful features.
|
||||
- **Mnemonic key bindings:** key binding guide will be displayed automatically
|
||||
- **Fast boot time:** Lazy-load 90% of plugins with [dein.vim](https://github.com/Shougo/dein.vim)
|
||||
- **Lower the risk of RSI:** by heavily using the space bar instead of modifiers.
|
||||
- **Consistent experience:** consistent experience between terminal and gui
|
||||
- [Quick start guide](https://spacevim.org/quick-start-guide/): installation, configuration, and learning resources for SpaceVim
|
||||
- [Documentation](https://spacevim.org/documentation/): the primary official documentation of SpaceVim
|
||||
- [Available layers](https://spacevim.org/layers/): a list of available layers which can be used in SpaceVim
|
||||
|
||||
<!-- vim:set nowrap: -->
|
||||
|
@ -1771,6 +1771,11 @@ let g:_spacevim_mappings_space.d = {'name' : '+Debug'}
|
||||
let g:_spacevim_mappings_space.e = {'name' : '+Errors/Encoding'}
|
||||
let g:_spacevim_mappings_space.B = {'name' : '+Global buffers'}
|
||||
let g:_spacevim_mappings_space.f.v = {'name' : '+Vim/SpaceVim'}
|
||||
let g:_spacevim_mappings_space.i = {'name' : '+Insertion'}
|
||||
let g:_spacevim_mappings_space.i = {'name' : '+Insertion'}
|
||||
let g:_spacevim_mappings_space.i.l = {'name' : '+Lorem-ipsum'}
|
||||
let g:_spacevim_mappings_space.i.p = {'name' : '+Passwords/Picker'}
|
||||
let g:_spacevim_mappings_space.i.U = {'name' : '+UUID'}
|
||||
|
||||
function! SpaceVim#end() abort
|
||||
let &tabline = ' '
|
||||
|
@ -358,44 +358,44 @@ function! SpaceVim#layers#core#config() abort
|
||||
\ . string(s:_function('s:buffer_transient_state')) . ', [])',
|
||||
\ ['buffer-transient-state',
|
||||
\ [
|
||||
\ '[SPC b .] is to open the buffer transient state',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:filename . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
\ , 1)
|
||||
\ '[SPC b .] is to open the buffer transient state',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:filename . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
\ , 1)
|
||||
let lnum = expand('<slnum>') + s:lnum - 1
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['h', 'g'], 'call SpaceVim#plugins#helpgrep#help()',
|
||||
\ ['asynchronous-helpgrep',
|
||||
\ [
|
||||
\ '[SPC h g] is to run helpgrep asynchronously',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:filename . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
\ , 1)
|
||||
\ '[SPC h g] is to run helpgrep asynchronously',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:filename . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
\ , 1)
|
||||
let lnum = expand('<slnum>') + s:lnum - 1
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['h', 'G'],
|
||||
\ 'call SpaceVim#plugins#helpgrep#help(expand("<cword>"))',
|
||||
\ ['asynchronous-helpgrep-with-cword',
|
||||
\ [
|
||||
\ '[SPC h g] is to run helpgrep asynchronously with cword',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:filename . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
\ , 1)
|
||||
\ '[SPC h g] is to run helpgrep asynchronously with cword',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:filename . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
\ , 1)
|
||||
let lnum = expand('<slnum>') + s:lnum - 1
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['b', 'd'],
|
||||
\ 'call SpaceVim#mapping#close_current_buffer()',
|
||||
\ ['delete-this-buffer',
|
||||
\ [
|
||||
\ '[SPC b d] is to delete current buffer',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:filename . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
\ , 1)
|
||||
\ '[SPC b d] is to delete current buffer',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:filename . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
\ , 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['b', 'D'],
|
||||
\ 'call SpaceVim#mapping#kill_visible_buffer_choosewin()',
|
||||
\ 'delete-the-selected-buffer', 1)
|
||||
@ -478,36 +478,48 @@ function! SpaceVim#layers#core#config() abort
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['f', 'v', 'd'], 'SPConfig',
|
||||
\ ['open-custom-configuration',
|
||||
\ [
|
||||
\ '[SPC f v d] is to open the custom configuration file for SpaceVim',
|
||||
\ '[SPC f v d] is to open the custom configuration file for SpaceVim',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:filename . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
\ , 1)
|
||||
if has('nvim-0.10.0')
|
||||
let lnum = expand('<slnum>') + s:lnum - 1
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['f', 'v', 'l'], 'lua require("spacevim.plugin.logevents").toggle()',
|
||||
\ ['toggle-log-events',
|
||||
\ [
|
||||
\ '[SPC f v l] is to toggle log autocmd events. requires neovim 0.10.0+',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:filename . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
\ , 1)
|
||||
endif
|
||||
let lnum = expand('<slnum>') + s:lnum - 1
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['n', '-'], 'call call('
|
||||
\ . string(s:_function('s:number_transient_state')) . ', ["-"])',
|
||||
\ ['decrease-number-under-cursor',
|
||||
\ [
|
||||
\ '[SPC n -] is to decrease the number under the cursor, and open',
|
||||
\ 'the number translate state buffer',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:filename . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
\ , 1)
|
||||
\ '[SPC n -] is to decrease the number under the cursor, and open',
|
||||
\ 'the number translate state buffer',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:filename . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
\ , 1)
|
||||
let lnum = expand('<slnum>') + s:lnum - 1
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['n', '+'], 'call call('
|
||||
\ . string(s:_function('s:number_transient_state')) . ', ["+"])',
|
||||
\ ['increase-number-under-cursor',
|
||||
\ [
|
||||
\ '[SPC n +] is to increase the number under the cursor, and open',
|
||||
\ 'the number translate state buffer',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:filename . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
\ , 1)
|
||||
\ '[SPC n +] is to increase the number under the cursor, and open',
|
||||
\ 'the number translate state buffer',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:filename . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
\ , 1)
|
||||
let g:vimproc#download_windows_dll = 1
|
||||
" call SpaceVim#mapping#space#def('nnoremap', ['p', 't'], 'call SpaceVim#plugins#projectmanager#current_root()', 'find-project-root', 1)
|
||||
let g:_spacevim_mappings_space.p.t = {'name' : '+Tasks'}
|
||||
@ -544,12 +556,12 @@ function! SpaceVim#layers#core#config() abort
|
||||
\ . string(s:_function('s:close_current_tab')) . ', [])',
|
||||
\ ['close-current-tab',
|
||||
\ [
|
||||
\ '[SPC q t] is to close the current tab, if it is the last tab, do nothing.',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:filename . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
\ , 1)
|
||||
\ '[SPC q t] is to close the current tab, if it is the last tab, do nothing.',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:filename . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
\ , 1)
|
||||
call SpaceVim#mapping#gd#add('HelpDescribe', function('s:gotodef'))
|
||||
|
||||
let g:_spacevim_mappings_space.c = {'name' : '+Comments'}
|
||||
@ -677,23 +689,23 @@ endfunction
|
||||
|
||||
let g:string_info = {
|
||||
\ 'vim' : {
|
||||
\ 'connect' : '.',
|
||||
\ 'line_prefix' : '\',
|
||||
\ },
|
||||
\ 'java' : {
|
||||
\ 'connect' : '+',
|
||||
\ 'line_prefix' : '',
|
||||
\ },
|
||||
\ 'perl' : {
|
||||
\ 'connect' : '.',
|
||||
\ 'line_prefix' : '\',
|
||||
\ },
|
||||
\ 'python' : {
|
||||
\ 'connect' : '+',
|
||||
\ 'line_prefix' : '\',
|
||||
\ 'quotes_hi' : ['pythonQuotes']
|
||||
\ },
|
||||
\ }
|
||||
\ 'connect' : '.',
|
||||
\ 'line_prefix' : '\',
|
||||
\ },
|
||||
\ 'java' : {
|
||||
\ 'connect' : '+',
|
||||
\ 'line_prefix' : '',
|
||||
\ },
|
||||
\ 'perl' : {
|
||||
\ 'connect' : '.',
|
||||
\ 'line_prefix' : '\',
|
||||
\ },
|
||||
\ 'python' : {
|
||||
\ 'connect' : '+',
|
||||
\ 'line_prefix' : '\',
|
||||
\ 'quotes_hi' : ['pythonQuotes']
|
||||
\ },
|
||||
\ }
|
||||
|
||||
function! s:jump_last_change() abort
|
||||
let [bufnum, lnum, col, off] = getpos("'.")
|
||||
@ -848,104 +860,104 @@ function! s:buffer_transient_state() abort
|
||||
call state.set_title('Buffer Selection Transient State')
|
||||
call state.defind_keys(
|
||||
\ {
|
||||
\ 'layout' : 'vertical split',
|
||||
\ 'left' : [
|
||||
\ {
|
||||
\ 'key' : {
|
||||
\ 'name' : 'C-1..C-9',
|
||||
\ 'pos' : [[1,4], [6,9]],
|
||||
\ 'handles' : [
|
||||
\ ["\<C-1>" , ''],
|
||||
\ ["\<C-2>" , ''],
|
||||
\ ["\<C-3>" , ''],
|
||||
\ ["\<C-4>" , ''],
|
||||
\ ["\<C-5>" , ''],
|
||||
\ ["\<C-6>" , ''],
|
||||
\ ["\<C-7>" , ''],
|
||||
\ ["\<C-8>" , ''],
|
||||
\ ["\<C-9>" , ''],
|
||||
\ ],
|
||||
\ },
|
||||
\ 'desc' : 'goto nth window',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : '',
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ {
|
||||
\ 'key' : {
|
||||
\ 'name' : '1..9',
|
||||
\ 'pos' : [[1,2], [4,5]],
|
||||
\ 'handles' : [
|
||||
\ ['1' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [1])'],
|
||||
\ ['2' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [2])'],
|
||||
\ ['3' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [3])'],
|
||||
\ ['4' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [4])'],
|
||||
\ ['5' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [5])'],
|
||||
\ ['6' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [6])'],
|
||||
\ ['7' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [7])'],
|
||||
\ ['8' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [8])'],
|
||||
\ ['9' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [9])'],
|
||||
\ ],
|
||||
\ },
|
||||
\ 'desc' : 'move buffer to nth window',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : '',
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ {
|
||||
\ 'key' : {
|
||||
\ 'name' : 'M-1..M-9',
|
||||
\ 'pos' : [[1,4], [6,9]],
|
||||
\ 'handles' : [
|
||||
\ ["\<M-1>" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [1])'],
|
||||
\ ["\<M-2>" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [2])'],
|
||||
\ ["\<M-3>" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [3])'],
|
||||
\ ["\<M-4>" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [4])'],
|
||||
\ ["\<M-5>" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [5])'],
|
||||
\ ["\<M-6>" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [6])'],
|
||||
\ ["\<M-7>" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [7])'],
|
||||
\ ["\<M-8>" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [8])'],
|
||||
\ ["\<M-9>" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [9])'],
|
||||
\ ],
|
||||
\ },
|
||||
\ 'desc' : 'swap buffer with nth window',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : '',
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ ],
|
||||
\ 'right' : [
|
||||
\ {
|
||||
\ 'key' : 'n',
|
||||
\ 'desc' : 'next buffer',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : 'bnext',
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ {
|
||||
\ 'key' : ['N', 'p'],
|
||||
\ 'desc' : 'previous buffer',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : 'bp',
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ {
|
||||
\ 'key' : 'd',
|
||||
\ 'desc' : 'kill buffer',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : 'call SpaceVim#mapping#close_current_buffer()',
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ {
|
||||
\ 'key' : 'q',
|
||||
\ 'desc' : 'quit',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : '',
|
||||
\ 'exit' : 1,
|
||||
\ },
|
||||
\ ],
|
||||
\ }
|
||||
\ )
|
||||
\ 'layout' : 'vertical split',
|
||||
\ 'left' : [
|
||||
\ {
|
||||
\ 'key' : {
|
||||
\ 'name' : 'C-1..C-9',
|
||||
\ 'pos' : [[1,4], [6,9]],
|
||||
\ 'handles' : [
|
||||
\ ["\<C-1>" , ''],
|
||||
\ ["\<C-2>" , ''],
|
||||
\ ["\<C-3>" , ''],
|
||||
\ ["\<C-4>" , ''],
|
||||
\ ["\<C-5>" , ''],
|
||||
\ ["\<C-6>" , ''],
|
||||
\ ["\<C-7>" , ''],
|
||||
\ ["\<C-8>" , ''],
|
||||
\ ["\<C-9>" , ''],
|
||||
\ ],
|
||||
\ },
|
||||
\ 'desc' : 'goto nth window',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : '',
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ {
|
||||
\ 'key' : {
|
||||
\ 'name' : '1..9',
|
||||
\ 'pos' : [[1,2], [4,5]],
|
||||
\ 'handles' : [
|
||||
\ ['1' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [1])'],
|
||||
\ ['2' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [2])'],
|
||||
\ ['3' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [3])'],
|
||||
\ ['4' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [4])'],
|
||||
\ ['5' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [5])'],
|
||||
\ ['6' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [6])'],
|
||||
\ ['7' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [7])'],
|
||||
\ ['8' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [8])'],
|
||||
\ ['9' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [9])'],
|
||||
\ ],
|
||||
\ },
|
||||
\ 'desc' : 'move buffer to nth window',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : '',
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ {
|
||||
\ 'key' : {
|
||||
\ 'name' : 'M-1..M-9',
|
||||
\ 'pos' : [[1,4], [6,9]],
|
||||
\ 'handles' : [
|
||||
\ ["\<M-1>" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [1])'],
|
||||
\ ["\<M-2>" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [2])'],
|
||||
\ ["\<M-3>" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [3])'],
|
||||
\ ["\<M-4>" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [4])'],
|
||||
\ ["\<M-5>" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [5])'],
|
||||
\ ["\<M-6>" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [6])'],
|
||||
\ ["\<M-7>" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [7])'],
|
||||
\ ["\<M-8>" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [8])'],
|
||||
\ ["\<M-9>" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [9])'],
|
||||
\ ],
|
||||
\ },
|
||||
\ 'desc' : 'swap buffer with nth window',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : '',
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ ],
|
||||
\ 'right' : [
|
||||
\ {
|
||||
\ 'key' : 'n',
|
||||
\ 'desc' : 'next buffer',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : 'bnext',
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ {
|
||||
\ 'key' : ['N', 'p'],
|
||||
\ 'desc' : 'previous buffer',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : 'bp',
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ {
|
||||
\ 'key' : 'd',
|
||||
\ 'desc' : 'kill buffer',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : 'call SpaceVim#mapping#close_current_buffer()',
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ {
|
||||
\ 'key' : 'q',
|
||||
\ 'desc' : 'quit',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : '',
|
||||
\ 'exit' : 1,
|
||||
\ },
|
||||
\ ],
|
||||
\ }
|
||||
\ )
|
||||
call state.open()
|
||||
endfunction
|
||||
|
||||
@ -1019,48 +1031,48 @@ function! s:jump_transient_state() abort
|
||||
call state.set_title('Jump Transient State')
|
||||
call state.defind_keys(
|
||||
\ {
|
||||
\ 'layout' : 'vertical split',
|
||||
\ 'left' : [
|
||||
\ {
|
||||
\ 'key' : 'j',
|
||||
\ 'desc' : 'next jump',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : 'try | exe "norm! \<C-i>"| catch | endtry ',
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ {
|
||||
\ 'key' : 'J',
|
||||
\ 'desc' : 'previous jump',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : 'try | exe "norm! \<c-o>" | catch | endtry',
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ ],
|
||||
\ 'right' : [
|
||||
\ {
|
||||
\ 'key' : 'c',
|
||||
\ 'desc' : 'next change',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : "try | exe 'norm! g,' | catch | endtry",
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ {
|
||||
\ 'key' : 'C',
|
||||
\ 'desc' : 'previous change',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : "try | exe 'norm! g;' | catch | endtry",
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ {
|
||||
\ 'key' : 'q',
|
||||
\ 'desc' : 'quit',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : '',
|
||||
\ 'exit' : 1,
|
||||
\ },
|
||||
\ ],
|
||||
\ }
|
||||
\ )
|
||||
\ 'layout' : 'vertical split',
|
||||
\ 'left' : [
|
||||
\ {
|
||||
\ 'key' : 'j',
|
||||
\ 'desc' : 'next jump',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : 'try | exe "norm! \<C-i>"| catch | endtry ',
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ {
|
||||
\ 'key' : 'J',
|
||||
\ 'desc' : 'previous jump',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : 'try | exe "norm! \<c-o>" | catch | endtry',
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ ],
|
||||
\ 'right' : [
|
||||
\ {
|
||||
\ 'key' : 'c',
|
||||
\ 'desc' : 'next change',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : "try | exe 'norm! g,' | catch | endtry",
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ {
|
||||
\ 'key' : 'C',
|
||||
\ 'desc' : 'previous change',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : "try | exe 'norm! g;' | catch | endtry",
|
||||
\ 'exit' : 0,
|
||||
\ },
|
||||
\ {
|
||||
\ 'key' : 'q',
|
||||
\ 'desc' : 'quit',
|
||||
\ 'func' : '',
|
||||
\ 'cmd' : '',
|
||||
\ 'exit' : 1,
|
||||
\ },
|
||||
\ ],
|
||||
\ }
|
||||
\ )
|
||||
call state.open()
|
||||
endfunction
|
||||
|
||||
@ -1204,18 +1216,18 @@ function! SpaceVim#layers#core#set_variable(var) abort
|
||||
endfunction
|
||||
|
||||
function! s:defx_find_current_file() abort
|
||||
let current_file = s:FILE.unify_path(expand('%'), ':p')
|
||||
let current_dir = s:FILE.unify_path(getcwd())
|
||||
let current_file = s:FILE.unify_path(expand('%'), ':p')
|
||||
let current_dir = s:FILE.unify_path(getcwd())
|
||||
|
||||
let command = "Defx -no-toggle -search=`expand('%:p')` "
|
||||
if stridx(current_file, current_dir) < 0
|
||||
let command .= expand('%:p:h')
|
||||
else
|
||||
let command .= getcwd()
|
||||
endif
|
||||
let command = "Defx -no-toggle -search=`expand('%:p')` "
|
||||
if stridx(current_file, current_dir) < 0
|
||||
let command .= expand('%:p:h')
|
||||
else
|
||||
let command .= getcwd()
|
||||
endif
|
||||
|
||||
call execute(command)
|
||||
|
||||
call execute(command)
|
||||
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#layers#core#get_options() abort
|
||||
|
@ -35,7 +35,6 @@ let s:filename = expand('<sfile>:~')
|
||||
let s:lnum = expand('<slnum>') + 2
|
||||
function! SpaceVim#layers#denite#config() abort
|
||||
|
||||
let g:_spacevim_mappings_space.i = {'name' : '+Insertion'}
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['i', 'u'], 'Denite unicode', 'search-and-insert-unicode', 1)
|
||||
if g:spacevim_snippet_engine ==# 'neosnippet'
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['i', 's'], 'Denite neosnippet', 'insert snippets', 1)
|
||||
|
@ -321,10 +321,6 @@ function! SpaceVim#layers#edit#config() abort
|
||||
call SpaceVim#mapping#space#def('nmap', ['x', 'g', 'n'], '<Plug>(grammarous-move-to-next-error)', 'move-cursor-to-next-error', 0, 1)
|
||||
call SpaceVim#mapping#space#def('nmap', ['x', 'g', 'p'], '<Plug>(grammarous-move-to-previous-error)', 'move-cursor-to-previous-error', 0, 1)
|
||||
|
||||
let g:_spacevim_mappings_space.i = {'name' : '+Insertion'}
|
||||
let g:_spacevim_mappings_space.i.l = {'name' : '+Lorem-ipsum'}
|
||||
let g:_spacevim_mappings_space.i.p = {'name' : '+Passwords'}
|
||||
let g:_spacevim_mappings_space.i.U = {'name' : '+UUID'}
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['i', 'p', 1], 'call call('
|
||||
\ . string(s:_function('s:insert_simple_password')) . ', [])',
|
||||
\ 'insert-simple-password', 1)
|
||||
|
@ -243,7 +243,6 @@ function! SpaceVim#layers#leaderf#config() abort
|
||||
\ 'after_enter' : string(s:_function('s:init_leaderf_win', 1))[10:-3]
|
||||
\ }
|
||||
|
||||
let g:_spacevim_mappings_space.i = {'name' : '+Insertion'}
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['i', 'u'], 'Leaderf unicode', 'search-and-insert-unicode', 1)
|
||||
if g:spacevim_snippet_engine ==# 'neosnippet'
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['i', 's'], 'Leaderf neosnippet', 'insert snippets', 1)
|
||||
|
71
autoload/SpaceVim/layers/tools/cpicker.vim
Normal file
71
autoload/SpaceVim/layers/tools/cpicker.vim
Normal file
@ -0,0 +1,71 @@
|
||||
"=============================================================================
|
||||
" cpicker.vim
|
||||
" Copyright (c) 2016-2019 Wang Shidong & Contributors
|
||||
" Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
" URL: https://spacevim.org
|
||||
" License: GPLv3
|
||||
"=============================================================================
|
||||
|
||||
""
|
||||
" @section tools#cpicker, layers-tools-cpicker
|
||||
" @parentsection layers
|
||||
" The `tools#cpicker` layer provides a color picker.
|
||||
" this layer is disabled by default, to enable this layer, add following
|
||||
" snippet to your SpaceVim configuration file.
|
||||
" >
|
||||
" [[layers]]
|
||||
" name = 'tools#cpicker'
|
||||
" <
|
||||
"
|
||||
" @subsection layer options
|
||||
" 1. default_spaces: set the default color spaces, the default value is `['rgb', 'hsl']`
|
||||
"
|
||||
" @subsection Key bindings
|
||||
" >
|
||||
" Key Function
|
||||
" ---------------------------------------------
|
||||
" SPC i p c open color picker
|
||||
" <
|
||||
"
|
||||
" Key bindings in cpicker:
|
||||
" >
|
||||
" Key Function
|
||||
" ---------------------------------------------
|
||||
" <Enter> copy color
|
||||
" j/<Down> move cursor down
|
||||
" k/<Up> move cursor up
|
||||
" h/<Left> reduce
|
||||
" l/<Right> increase
|
||||
" <
|
||||
" @subsection commands
|
||||
" Instead of using key Binding, this layer also provides a Neovim command `:Cpicker` which can be used in cmdline. For example:
|
||||
" >
|
||||
" :Cpicker rgb cmyk
|
||||
" <
|
||||
|
||||
let s:default_spaces = ['rgb', 'hsl']
|
||||
|
||||
function! SpaceVim#layers#tools#cpicker#plugins() abort
|
||||
|
||||
return [
|
||||
\ [g:_spacevim_root_dir . 'bundle/cpicker.nvim', {'merged' : 0, 'loadconf' : 1, 'on_cmd' : ['Cpicker', 'CpickerCursorForeground', 'CpickerColorMix']}],
|
||||
\ ]
|
||||
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#layers#tools#cpicker#config() abort
|
||||
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['i', 'p', 'c'], 'Cpicker ' . join(s:default_spaces, ' '),
|
||||
\ 'insert-color-with-picker', 1)
|
||||
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#layers#tools#cpicker#set_variable(var) abort
|
||||
let s:default_spaces = get(a:var, 'default_spaces', s:default_spaces)
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#layers#tools#cpicker#loadeable() abort
|
||||
|
||||
return has('nvim-0.10.0')
|
||||
|
||||
endfunction
|
@ -82,7 +82,6 @@ function! SpaceVim#layers#unite#config() abort
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['i', 'u'], 'Unite unicode', 'search-and-insert-unicode', 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['f', 'r'], 'Unite file_mru', 'open-recent-file', 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['r', 'l'], 'Unite resume', 'resume unite buffer', 1)
|
||||
let g:_spacevim_mappings_space.i = {'name' : '+Insertion'}
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['i', 'u'], 'Unite unicode', 'search-and-insert-unicode', 1)
|
||||
if g:spacevim_snippet_engine ==# 'neosnippet'
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['i', 's'], 'Unite neosnippet', 'insert snippets', 1)
|
||||
|
@ -676,13 +676,13 @@ function! SpaceVim#mapping#space#init() abort
|
||||
\ ]
|
||||
\ , 1)
|
||||
if has('nvim-0.7.0')
|
||||
call SpaceVim#custom#SPC('nnoremap', ['a', 'o'], 'lua require("spacevim.plugin.todo").list()', 'open-todo-manager', 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['a', 'o'], 'lua require("spacevim.plugin.todo").list()', 'open-todo-manager', 1)
|
||||
else
|
||||
call SpaceVim#custom#SPC('nnoremap', ['a', 'o'], 'call SpaceVim#plugins#todo#list()', 'open-todo-manager', 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['a', 'o'], 'call SpaceVim#plugins#todo#list()', 'open-todo-manager', 1)
|
||||
endif
|
||||
|
||||
if has('nvim-0.9.5')
|
||||
call SpaceVim#custom#SPC('nnoremap', ['a', 'r'], 'lua require("spacevim.plugin.record-key").toggle()', 'toggle-record-keyboard', 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['a', 'r'], 'lua require("spacevim.plugin.record-key").toggle()', 'toggle-record-keyboard', 1)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
191
bundle/cpicker.nvim/lua/cpicker.lua
Normal file
191
bundle/cpicker.nvim/lua/cpicker.lua
Normal file
@ -0,0 +1,191 @@
|
||||
--=============================================================================
|
||||
-- cpicker.lua
|
||||
-- Copyright (c) 2019-2024 Wang Shidong & Contributors
|
||||
-- Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
-- URL: https://spacevim.org
|
||||
-- License: GPLv3
|
||||
--=============================================================================
|
||||
|
||||
local M = {}
|
||||
|
||||
local winid
|
||||
local bufnr
|
||||
local color_hi = '#000000'
|
||||
|
||||
local hi = require('spacevim.api.vim.highlight')
|
||||
local notify = require('spacevim.api.notify')
|
||||
local log = require('spacevim.logger').derive('cpicker')
|
||||
local util = require('cpicker.util')
|
||||
|
||||
local enabled_formats = {}
|
||||
local increase_keys = {}
|
||||
local reduce_keys = {}
|
||||
local color_code_regex = {}
|
||||
|
||||
local function update_buf_text()
|
||||
local rst = {}
|
||||
for _, format in ipairs(enabled_formats) do
|
||||
local ok, f = pcall(require, 'cpicker.formats.' .. format)
|
||||
if ok then
|
||||
local funcs = f.increase_reduce_functions()
|
||||
for i, text in ipairs(f.buf_text()) do
|
||||
table.insert(rst, text)
|
||||
increase_keys[#rst] = funcs[i][1]
|
||||
reduce_keys[#rst] = funcs[i][2]
|
||||
end
|
||||
end
|
||||
end
|
||||
table.insert(rst, '')
|
||||
color_code_regex = {}
|
||||
for _, format in ipairs(enabled_formats) do
|
||||
local ok, f = pcall(require, 'cpicker.formats.' .. format)
|
||||
if ok then
|
||||
table.insert(rst, f.color_code() .. string.rep(' ', 20))
|
||||
table.insert(color_code_regex, { #f.color_code(), f.color_code_regex })
|
||||
end
|
||||
end
|
||||
util.update_color_code_syntax(color_code_regex)
|
||||
local normal_bg = hi.group2dict('Normal').guibg
|
||||
local normal_fg = hi.group2dict('Normal').guifg
|
||||
if
|
||||
math.abs(util.get_hsl_l(normal_bg) - util.get_hsl_l(color_hi))
|
||||
> math.abs(util.get_hsl_l(color_hi) - util.get_hsl_l(normal_fg))
|
||||
then
|
||||
hi.hi({
|
||||
name = 'SpaceVimPickerCode',
|
||||
guifg = color_hi,
|
||||
guibg = normal_bg,
|
||||
bold = 1,
|
||||
})
|
||||
else
|
||||
hi.hi({
|
||||
name = 'SpaceVimPickerCode',
|
||||
guifg = color_hi,
|
||||
guibg = normal_fg,
|
||||
bold = 1,
|
||||
})
|
||||
end
|
||||
hi.hi({
|
||||
name = 'SpaceVimPickerBackground',
|
||||
guibg = color_hi,
|
||||
guifg = color_hi,
|
||||
})
|
||||
|
||||
vim.api.nvim_set_option_value('modifiable', true, {
|
||||
buf = bufnr,
|
||||
})
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, rst)
|
||||
vim.api.nvim_set_option_value('modifiable', false, {
|
||||
buf = bufnr,
|
||||
})
|
||||
vim.api.nvim_win_set_config(winid, {
|
||||
height = #rst + 1,
|
||||
})
|
||||
end
|
||||
|
||||
-- https://zenn.dev/kawarimidoll/articles/a8ac50a17477bd
|
||||
|
||||
local function copy_color()
|
||||
local from, to = vim.regex(table.concat(vim.tbl_map(function(t) return t[2] end, color_code_regex), '\\|')):match_str(vim.fn.getline('.'))
|
||||
if from then
|
||||
vim.fn.setreg('+', string.sub(vim.fn.getline('.'), from, to))
|
||||
notify.notify('copied:' .. string.sub(vim.fn.getline('.'), from, to))
|
||||
end
|
||||
end
|
||||
|
||||
local function increase()
|
||||
if increase_keys[vim.fn.line('.')] then
|
||||
local t, code = increase_keys[vim.fn.line('.')]()
|
||||
color_hi = util.get_hex_code(t, code)
|
||||
for _, format in ipairs(enabled_formats) do
|
||||
local ok, f = pcall(require, 'cpicker.formats.' .. format)
|
||||
if ok then
|
||||
f.on_change(t, code)
|
||||
end
|
||||
end
|
||||
end
|
||||
update_buf_text()
|
||||
end
|
||||
|
||||
local function reduce()
|
||||
if reduce_keys[vim.fn.line('.')] then
|
||||
local t, code = reduce_keys[vim.fn.line('.')]()
|
||||
color_hi = util.get_hex_code(t, code)
|
||||
for _, format in ipairs(enabled_formats) do
|
||||
local ok, f = pcall(require, 'cpicker.formats.' .. format)
|
||||
if ok then
|
||||
f.on_change(t, code)
|
||||
end
|
||||
end
|
||||
end
|
||||
update_buf_text()
|
||||
end
|
||||
|
||||
M.picker = function(formats)
|
||||
if #formats == 0 then
|
||||
enabled_formats = { 'rgb', 'hsl' }
|
||||
else
|
||||
enabled_formats = formats
|
||||
end
|
||||
log.info(vim.inspect(enabled_formats))
|
||||
if not bufnr or not vim.api.nvim_win_is_valid(bufnr) then
|
||||
bufnr = vim.api.nvim_create_buf(false, false)
|
||||
vim.api.nvim_set_option_value('buftype', 'nofile', {
|
||||
buf = bufnr,
|
||||
})
|
||||
-- use set syntax instead of filetype
|
||||
-- if using filetype, when open cpicker first time the SpaceVimPickerCode syntax is cleared
|
||||
vim.api.nvim_set_option_value('syntax', 'spacevim_cpicker', {
|
||||
buf = bufnr,
|
||||
})
|
||||
vim.api.nvim_set_option_value('bufhidden', 'wipe', {
|
||||
buf = bufnr,
|
||||
})
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'l', '', {
|
||||
callback = increase,
|
||||
})
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'h', '', {
|
||||
callback = reduce,
|
||||
})
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Right>', '', {
|
||||
callback = increase,
|
||||
})
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Left>', '', {
|
||||
callback = reduce,
|
||||
})
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'q', '', {
|
||||
callback = function()
|
||||
vim.api.nvim_win_close(winid, true)
|
||||
end,
|
||||
})
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Cr>', '', {
|
||||
callback = copy_color,
|
||||
})
|
||||
end
|
||||
if not winid or not vim.api.nvim_win_is_valid(winid) then
|
||||
winid = vim.api.nvim_open_win(bufnr, true, {
|
||||
relative = 'cursor',
|
||||
border = 'single',
|
||||
width = 44,
|
||||
height = 10,
|
||||
row = 1,
|
||||
col = 1,
|
||||
})
|
||||
end
|
||||
vim.api.nvim_set_option_value('number', false, {
|
||||
win = winid,
|
||||
})
|
||||
vim.api.nvim_set_option_value('winhighlight', 'NormalFloat:Normal,FloatBorder:WinSeparator', {
|
||||
win = winid,
|
||||
})
|
||||
vim.api.nvim_set_option_value('modifiable', false, {
|
||||
buf = bufnr,
|
||||
})
|
||||
update_buf_text()
|
||||
end
|
||||
|
||||
M.set_default_color = function(hex)
|
||||
color_hi = hex
|
||||
end
|
||||
|
||||
return M
|
129
bundle/cpicker.nvim/lua/cpicker/formats/cmyk.lua
Normal file
129
bundle/cpicker.nvim/lua/cpicker/formats/cmyk.lua
Normal file
@ -0,0 +1,129 @@
|
||||
--=============================================================================
|
||||
-- cmyk.lua ---
|
||||
-- Copyright (c) 2019-2024 Wang Shidong & Contributors
|
||||
-- Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
-- URL: https://spacevim.org
|
||||
-- License: GPLv3
|
||||
--=============================================================================
|
||||
local M = {}
|
||||
|
||||
local color = require('spacevim.api.color')
|
||||
local util = require('cpicker.util')
|
||||
|
||||
local cyan = 0
|
||||
local magenta = 0
|
||||
local yellow = 0
|
||||
local black = 0
|
||||
|
||||
M.color_code_regex = [[\scmyk(\d\+%,\s\d\+%,\s\d\+%,\s\d\+%)]]
|
||||
|
||||
local function on_change_argv()
|
||||
return 'cmyk', { cyan, magenta, yellow, black }
|
||||
end
|
||||
|
||||
function M.buf_text()
|
||||
local rst = {}
|
||||
local c_bar = util.generate_bar(cyan, '+')
|
||||
local m_bar = util.generate_bar(magenta, '+')
|
||||
local y_bar = util.generate_bar(yellow, '+')
|
||||
local k_bar = util.generate_bar(black, '+')
|
||||
table.insert(rst, 'CMYK: C: ' .. string.format('%4s', math.floor(cyan * 100 + 0.5)) .. ' ' .. c_bar)
|
||||
table.insert(rst, ' M: ' .. string.format('%4s', math.floor(magenta * 100 + 0.5)) .. ' ' .. m_bar)
|
||||
table.insert(rst, ' Y: ' .. string.format('%4s', math.floor(yellow * 100 + 0.5)) .. ' ' .. y_bar)
|
||||
table.insert(rst, ' K: ' .. string.format('%4s', math.floor(black * 100 + 0.5)) .. ' ' .. k_bar)
|
||||
return rst
|
||||
end
|
||||
|
||||
function M.color_code()
|
||||
return
|
||||
' =========' .. string.format(
|
||||
' cmyk(%s%%, %s%%, %s%%, %s%%)',
|
||||
math.floor(cyan * 100 + 0.5),
|
||||
math.floor(magenta * 100 + 0.5),
|
||||
math.floor(yellow * 100 + 0.5),
|
||||
math.floor(black * 100 + 0.5)
|
||||
)
|
||||
end
|
||||
|
||||
local function increase_cyan()
|
||||
if cyan <= 0.99 then
|
||||
cyan = cyan + 0.01
|
||||
elseif cyan < 1 then
|
||||
cyan = 1
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_cyan()
|
||||
if cyan > 0.01 then
|
||||
cyan = cyan - 0.01
|
||||
elseif cyan > 0 then
|
||||
cyan = 0
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function increase_magenta()
|
||||
if magenta <= 0.99 then
|
||||
magenta = magenta + 0.01
|
||||
elseif magenta < 1 then
|
||||
magenta = 1
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_magenta()
|
||||
if magenta > 0.01 then
|
||||
magenta = magenta - 0.01
|
||||
elseif magenta > 0 then
|
||||
magenta = 0
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function increase_yellow()
|
||||
if yellow <= 0.99 then
|
||||
yellow = yellow + 0.01
|
||||
elseif yellow < 1 then
|
||||
yellow = 1
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_yellow()
|
||||
if yellow > 0.01 then
|
||||
yellow = yellow - 0.01
|
||||
elseif yellow > 0 then
|
||||
yellow = 0
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function increase_black()
|
||||
if black <= 0.99 then
|
||||
black = black + 0.01
|
||||
elseif black < 1 then
|
||||
black = 1
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_black()
|
||||
if black > 0.01 then
|
||||
black = black - 0.01
|
||||
elseif black > 0 then
|
||||
black = 0
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
function M.increase_reduce_functions()
|
||||
return {
|
||||
{ increase_cyan, reduce_cyan },
|
||||
{ increase_magenta, reduce_magenta },
|
||||
{ increase_yellow, reduce_yellow },
|
||||
{ increase_black, reduce_black },
|
||||
}
|
||||
end
|
||||
|
||||
function M.on_change(f, code)
|
||||
if f == 'cmyk' then
|
||||
cyan, magenta, yellow, black = unpack(code)
|
||||
return
|
||||
end
|
||||
cyan, magenta, yellow, black = color[f .. '2cmyk'](unpack(code))
|
||||
end
|
||||
|
||||
return M
|
114
bundle/cpicker.nvim/lua/cpicker/formats/hsl.lua
Normal file
114
bundle/cpicker.nvim/lua/cpicker/formats/hsl.lua
Normal file
@ -0,0 +1,114 @@
|
||||
--=============================================================================
|
||||
-- hsl.lua
|
||||
-- Copyright (c) 2019-2024 Wang Shidong & Contributors
|
||||
-- Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
-- URL: https://spacevim.org
|
||||
-- License: GPLv3
|
||||
--=============================================================================
|
||||
local M = {}
|
||||
|
||||
local color = require('spacevim.api.color')
|
||||
local util = require('cpicker.util')
|
||||
|
||||
local hue = 0 -- [0, 360]
|
||||
local saturation = 0 -- [0, 100%]
|
||||
local lightness = 0 -- [0, 100%]
|
||||
|
||||
M.color_code_regex = [[\shsl(\d\+,\s\d\+%,\s\d\+%)]]
|
||||
|
||||
local function on_change_argv()
|
||||
return 'hsl', { hue, saturation, lightness }
|
||||
end
|
||||
|
||||
function M.buf_text()
|
||||
local rst = {}
|
||||
local h_bar = util.generate_bar(hue, '+', 360)
|
||||
local s_bar = util.generate_bar(saturation, '+')
|
||||
local l_bar = util.generate_bar(lightness, '+')
|
||||
table.insert(rst, 'HSL: H: ' .. string.format('%4s', math.floor(hue + 0.5)) .. ' ' .. h_bar)
|
||||
table.insert(
|
||||
rst,
|
||||
' S: ' .. string.format('%3s', math.floor(saturation * 100 + 0.5)) .. '% ' .. s_bar
|
||||
)
|
||||
table.insert(
|
||||
rst,
|
||||
' L: ' .. string.format('%3s', math.floor(lightness * 100 + 0.5)) .. '% ' .. l_bar
|
||||
)
|
||||
return rst
|
||||
end
|
||||
|
||||
function M.color_code()
|
||||
return
|
||||
' =========' .. string.format(
|
||||
' hsl(%s, %s%%, %s%%)',
|
||||
math.floor(hue + 0.5),
|
||||
math.floor(saturation * 100 + 0.5),
|
||||
math.floor(lightness * 100 + 0.5)
|
||||
)
|
||||
end
|
||||
|
||||
local function increase_hsl_h()
|
||||
if hue <= 359 then
|
||||
hue = hue + 1
|
||||
elseif hue < 360 then
|
||||
hue = 360
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_hsl_h()
|
||||
if hue >= 1 then
|
||||
hue = hue - 1
|
||||
elseif hue > 0 then
|
||||
hue = 0
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function increase_hsl_s()
|
||||
if saturation <= 0.99 then
|
||||
saturation = saturation + 0.01
|
||||
elseif saturation < 1 then
|
||||
saturation = 1
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_hsl_s()
|
||||
if saturation >= 0.01 then
|
||||
saturation = saturation - 0.01
|
||||
elseif saturation > 0 and saturation < 0.01 then
|
||||
saturation = 0
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function increase_hsl_l()
|
||||
if lightness <= 0.99 then
|
||||
lightness = lightness + 0.01
|
||||
elseif lightness < 1 then
|
||||
lightness = 1
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_hsl_l()
|
||||
if lightness >= 0.01 then
|
||||
lightness = lightness - 0.01
|
||||
elseif lightness > 0 and lightness < 0.01 then
|
||||
lightness = 0
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
function M.increase_reduce_functions()
|
||||
return {
|
||||
{ increase_hsl_h, reduce_hsl_h },
|
||||
{ increase_hsl_s, reduce_hsl_s },
|
||||
{ increase_hsl_l, reduce_hsl_l },
|
||||
}
|
||||
end
|
||||
|
||||
function M.on_change(f, code)
|
||||
if f == 'hsl' then
|
||||
hue, saturation, lightness = unpack(code)
|
||||
return
|
||||
end
|
||||
hue, saturation, lightness = color[f .. '2hsl'](unpack(code))
|
||||
end
|
||||
|
||||
return M
|
114
bundle/cpicker.nvim/lua/cpicker/formats/hsv.lua
Normal file
114
bundle/cpicker.nvim/lua/cpicker/formats/hsv.lua
Normal file
@ -0,0 +1,114 @@
|
||||
--=============================================================================
|
||||
-- hsv.lua ---
|
||||
-- Copyright (c) 2019-2024 Wang Shidong & Contributors
|
||||
-- Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
-- URL: https://spacevim.org
|
||||
-- License: GPLv3
|
||||
--=============================================================================
|
||||
local M = {}
|
||||
|
||||
local color = require('spacevim.api.color')
|
||||
local util = require('cpicker.util')
|
||||
|
||||
local hue = 0
|
||||
local saturation = 0
|
||||
local value = 0
|
||||
|
||||
M.color_code_regex = [[\shsv(\d\+,\s\d\+%,\s\d\+%)]]
|
||||
|
||||
local function on_change_argv()
|
||||
return 'hsv', {hue, saturation, value}
|
||||
end
|
||||
|
||||
function M.buf_text()
|
||||
|
||||
local rst = {}
|
||||
local h_bar = util.generate_bar(hue, '+', 360)
|
||||
local s_bar = util.generate_bar(saturation, '+')
|
||||
local l_bar = util.generate_bar(value, '+')
|
||||
table.insert(rst, 'HSV: H: ' .. string.format('%4s', math.floor(hue + 0.5)) .. ' ' .. h_bar)
|
||||
table.insert(
|
||||
rst,
|
||||
' S: ' .. string.format('%3s', math.floor(saturation * 100 + 0.5)) .. '% ' .. s_bar
|
||||
)
|
||||
table.insert(
|
||||
rst,
|
||||
' V: ' .. string.format('%3s', math.floor(value * 100 + 0.5)) .. '% ' .. l_bar
|
||||
)
|
||||
return rst
|
||||
end
|
||||
|
||||
function M.color_code()
|
||||
return
|
||||
' =========' .. string.format(
|
||||
' hsv(%s, %s%%, %s%%)',
|
||||
math.floor(hue + 0.5),
|
||||
math.floor(saturation * 100 + 0.5),
|
||||
math.floor(value * 100 + 0.5)
|
||||
)
|
||||
|
||||
end
|
||||
local function increase_hsl_h()
|
||||
if hue <= 359 then
|
||||
hue = hue + 1
|
||||
elseif hue < 360 then hue = 360
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_hsl_h()
|
||||
if hue >= 1 then
|
||||
hue = hue - 1
|
||||
elseif hue > 0 then
|
||||
hue = 0
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function increase_hsl_s()
|
||||
if saturation <= 0.99 then
|
||||
saturation = saturation + 0.01
|
||||
elseif saturation < 1 then
|
||||
saturation = 1
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_hsl_s()
|
||||
if saturation >= 0.01 then
|
||||
saturation = saturation - 0.01
|
||||
elseif saturation > 0 and saturation < 0.01 then
|
||||
saturation = 0
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function increase_hsl_v()
|
||||
if value <= 0.99 then
|
||||
value = value + 0.01
|
||||
elseif value < 1 then
|
||||
value = 1
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_hsl_v()
|
||||
if value >= 0.01 then
|
||||
value = value - 0.01
|
||||
elseif value > 0 and value < 0.01 then
|
||||
value = 0
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
function M.increase_reduce_functions()
|
||||
return {
|
||||
{ increase_hsl_h, reduce_hsl_h },
|
||||
{ increase_hsl_s, reduce_hsl_s },
|
||||
{ increase_hsl_v, reduce_hsl_v },
|
||||
}
|
||||
end
|
||||
|
||||
function M.on_change(f, code)
|
||||
if f == 'hsv' then
|
||||
hue, saturation, value = unpack(code)
|
||||
return
|
||||
end
|
||||
hue, saturation, value = color[f .. '2hsv'](unpack(code))
|
||||
end
|
||||
|
||||
return M
|
115
bundle/cpicker.nvim/lua/cpicker/formats/hwb.lua
Normal file
115
bundle/cpicker.nvim/lua/cpicker/formats/hwb.lua
Normal file
@ -0,0 +1,115 @@
|
||||
--=============================================================================
|
||||
-- hwb.lua
|
||||
-- Copyright (c) 2019-2024 Wang Shidong & Contributors
|
||||
-- Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
-- URL: https://spacevim.org
|
||||
-- License: GPLv3
|
||||
--=============================================================================
|
||||
local M = {}
|
||||
|
||||
local color = require('spacevim.api.color')
|
||||
local util = require('cpicker.util')
|
||||
|
||||
local hue = 0 -- [0, 360]
|
||||
local whiteness = 0 -- [0, 100%]
|
||||
local blackness = 0 -- [0, 100%]
|
||||
|
||||
M.color_code_regex = [[\shwb(\d\+,\s\d\+%,\s\d\+%)]]
|
||||
|
||||
local function on_change_argv()
|
||||
return 'hwb', { hue, whiteness, blackness }
|
||||
end
|
||||
|
||||
function M.buf_text()
|
||||
local rst = {}
|
||||
local h_bar = util.generate_bar(hue, '+', 360)
|
||||
local w_bar = util.generate_bar(whiteness, '+')
|
||||
local b_bar = util.generate_bar(blackness, '+')
|
||||
table.insert(rst, 'HWB: H: ' .. string.format('%4s', math.floor(hue + 0.5)) .. ' ' .. h_bar)
|
||||
table.insert(
|
||||
rst,
|
||||
' W: ' .. string.format('%3s', math.floor(whiteness * 100 + 0.5)) .. '% ' .. w_bar
|
||||
)
|
||||
table.insert(
|
||||
rst,
|
||||
' B: ' .. string.format('%3s', math.floor(blackness * 100 + 0.5)) .. '% ' .. b_bar
|
||||
)
|
||||
return rst
|
||||
end
|
||||
|
||||
function M.color_code()
|
||||
return
|
||||
' =========' .. string.format(
|
||||
' hwb(%s, %s%%, %s%%)',
|
||||
math.floor(hue + 0.5),
|
||||
math.floor(whiteness * 100 + 0.5),
|
||||
math.floor(blackness * 100 + 0.5)
|
||||
)
|
||||
end
|
||||
|
||||
local function increase_hwb_h()
|
||||
if hue <= 359 then
|
||||
hue = hue + 1
|
||||
elseif hue < 360 then
|
||||
hue = 360
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_hwb_h()
|
||||
if hue >= 1 then
|
||||
hue = hue - 1
|
||||
elseif hue > 0 then
|
||||
hue = 0
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function increase_hwb_w()
|
||||
if whiteness <= 0.99 then
|
||||
whiteness = whiteness + 0.01
|
||||
elseif whiteness < 1 then
|
||||
whiteness = 1
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_hwb_w()
|
||||
if whiteness >= 0.01 then
|
||||
whiteness = whiteness - 0.01
|
||||
elseif whiteness > 0 and whiteness < 0.01 then
|
||||
whiteness = 0
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function increase_hwb_b()
|
||||
if blackness <= 0.99 then
|
||||
blackness = blackness + 0.01
|
||||
elseif blackness < 1 then
|
||||
blackness = 1
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_hwb_b()
|
||||
if blackness >= 0.01 then
|
||||
blackness = blackness - 0.01
|
||||
elseif blackness > 0 and blackness < 0.01 then
|
||||
blackness = 0
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
function M.increase_reduce_functions()
|
||||
return {
|
||||
{ increase_hwb_h, reduce_hwb_h },
|
||||
{ increase_hwb_w, reduce_hwb_w },
|
||||
{ increase_hwb_b, reduce_hwb_b },
|
||||
}
|
||||
end
|
||||
|
||||
function M.on_change(f, code)
|
||||
if f == 'hwb' then
|
||||
hue, whiteness, blackness = unpack(code)
|
||||
return
|
||||
end
|
||||
hue, whiteness, blackness = color[f .. '2hwb'](unpack(code))
|
||||
end
|
||||
|
||||
return M
|
||||
|
108
bundle/cpicker.nvim/lua/cpicker/formats/lab.lua
Normal file
108
bundle/cpicker.nvim/lua/cpicker/formats/lab.lua
Normal file
@ -0,0 +1,108 @@
|
||||
--=============================================================================
|
||||
-- lab.lua
|
||||
-- Copyright (c) 2019-2024 Wang Shidong & Contributors
|
||||
-- Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
-- URL: https://spacevim.org
|
||||
-- License: GPLv3
|
||||
--=============================================================================
|
||||
local M = {}
|
||||
|
||||
local color = require('spacevim.api.color')
|
||||
local util = require('cpicker.util')
|
||||
|
||||
local l = 0 -- [0, 360]
|
||||
local a = 0 -- [0, 100%]
|
||||
local b = 0 -- [0, 100%]
|
||||
|
||||
M.color_code_regex = [[\slab(\d\+,\s-\?\d\+%,\s-\?\d\+%)]]
|
||||
|
||||
local function on_change_argv()
|
||||
return 'lab', { l, a, b }
|
||||
end
|
||||
|
||||
function M.buf_text()
|
||||
local rst = {}
|
||||
local h_bar = util.generate_bar(l, '+', 100)
|
||||
local s_bar = util.generate_bar(a, '+', 250)
|
||||
local l_bar = util.generate_bar(b, '+', 250)
|
||||
table.insert(rst, 'Lab: L: ' .. string.format('%3s', math.floor(l + 0.5)) .. ' ' .. h_bar)
|
||||
table.insert(rst, ' a: ' .. string.format('%3s', math.floor(a + 0.5)) .. '% ' .. s_bar)
|
||||
table.insert(rst, ' b: ' .. string.format('%3s', math.floor(b + 0.5)) .. '% ' .. l_bar)
|
||||
return rst
|
||||
end
|
||||
|
||||
function M.color_code()
|
||||
return
|
||||
' =========' .. string.format(
|
||||
' lab(%s, %s%%, %s%%)',
|
||||
math.floor(l + 0.5),
|
||||
math.floor(a + 0.5),
|
||||
math.floor(b + 0.5)
|
||||
)
|
||||
end
|
||||
|
||||
local function increase_l()
|
||||
if l <= 99 then
|
||||
l = l + 1
|
||||
elseif l < 100 then
|
||||
l = 100
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_l()
|
||||
if l >= 1 then
|
||||
l = l - 1
|
||||
elseif l > 0 then
|
||||
l = 0
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function increase_a()
|
||||
if a <= 99 then
|
||||
a = a + 1
|
||||
elseif a < 100 then
|
||||
a = 100
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_a()
|
||||
if a >= -99 then
|
||||
a = a - 1
|
||||
elseif a > -100 then
|
||||
a = -100
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function increase_b()
|
||||
if b <= 99 then
|
||||
b = b + 1
|
||||
elseif b < 100 then
|
||||
b = 100
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_b()
|
||||
if b >= -99 then
|
||||
b = b - 1
|
||||
elseif b > -100 then
|
||||
b = -100
|
||||
end
|
||||
return on_change_argv()
|
||||
end
|
||||
function M.increase_reduce_functions()
|
||||
return {
|
||||
{ increase_l, reduce_l },
|
||||
{ increase_a, reduce_a },
|
||||
{ increase_b, reduce_b },
|
||||
}
|
||||
end
|
||||
|
||||
function M.on_change(f, code)
|
||||
if f == 'lab' then
|
||||
l, a, b = unpack(code)
|
||||
return
|
||||
end
|
||||
l, a, b = color[f .. '2lab'](unpack(code))
|
||||
end
|
||||
|
||||
return M
|
108
bundle/cpicker.nvim/lua/cpicker/formats/linear.lua
Normal file
108
bundle/cpicker.nvim/lua/cpicker/formats/linear.lua
Normal file
@ -0,0 +1,108 @@
|
||||
--=============================================================================
|
||||
-- rgb-linear
|
||||
-- Copyright (c) 2019-2024 Wang Shidong & Contributors
|
||||
-- Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
-- URL: https://spacevim.org
|
||||
-- License: GPLv3
|
||||
--=============================================================================
|
||||
local M = {}
|
||||
|
||||
local color = require('spacevim.api.color')
|
||||
local util = require('cpicker.util')
|
||||
|
||||
local red = 0 -- [0, 1]
|
||||
local green = 0 -- [0, 1]
|
||||
local blue = 0 -- [0, 1]
|
||||
|
||||
M.color_code_regex = [[\s#[0123456789ABCDEF]\+]]
|
||||
|
||||
local function on_change_argv()
|
||||
return 'linear', { red, green, blue }
|
||||
end
|
||||
|
||||
function M.buf_text()
|
||||
local rst = {}
|
||||
local r_bar = util.generate_bar(red, '+')
|
||||
local g_bar = util.generate_bar(green, '+')
|
||||
local b_bar = util.generate_bar(blue, '+')
|
||||
table.insert(
|
||||
rst,
|
||||
'Linear: R: ' .. string.format('%4s', math.floor(red * 255 + 0.5)) .. ' ' .. r_bar
|
||||
)
|
||||
table.insert(
|
||||
rst,
|
||||
' G: ' .. string.format('%4s', math.floor(green * 255 + 0.5)) .. ' ' .. g_bar
|
||||
)
|
||||
table.insert(
|
||||
rst,
|
||||
' B: ' .. string.format('%4s', math.floor(blue * 255 + 0.5)) .. ' ' .. b_bar
|
||||
)
|
||||
return rst
|
||||
end
|
||||
|
||||
function M.color_code()
|
||||
return ' =========' .. ' ' .. color.linear2hex(red, green, blue)
|
||||
end
|
||||
|
||||
local function increase(c)
|
||||
if c <= 1 - 1 / 255 then
|
||||
c = c + 1 / 255
|
||||
elseif c < 1 then
|
||||
c = 1
|
||||
end
|
||||
return c
|
||||
end
|
||||
|
||||
local function reduce(c)
|
||||
if c >= 1 / 255 then
|
||||
c = c - 1 / 255
|
||||
elseif c > 0 then
|
||||
c = 0
|
||||
end
|
||||
return c
|
||||
end
|
||||
|
||||
local function increase_rgb_red()
|
||||
red = increase(red)
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_rgb_red()
|
||||
red = reduce(red)
|
||||
return on_change_argv()
|
||||
end
|
||||
local function increase_rgb_green()
|
||||
green = increase(green)
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_rgb_green()
|
||||
green = reduce(green)
|
||||
return on_change_argv()
|
||||
end
|
||||
|
||||
local function increase_rgb_blue()
|
||||
blue = increase(blue)
|
||||
return on_change_argv()
|
||||
end
|
||||
|
||||
local function reduce_rgb_blue()
|
||||
blue = reduce(blue)
|
||||
return on_change_argv()
|
||||
end
|
||||
function M.increase_reduce_functions()
|
||||
return {
|
||||
{ increase_rgb_red, reduce_rgb_red },
|
||||
{ increase_rgb_green, reduce_rgb_green },
|
||||
{ increase_rgb_blue, reduce_rgb_blue },
|
||||
}
|
||||
end
|
||||
|
||||
function M.on_change(f, code)
|
||||
if f == 'linear' then
|
||||
red, green, blue = unpack(code)
|
||||
return
|
||||
end
|
||||
red, green, blue = color[f .. '2linear'](unpack(code))
|
||||
end
|
||||
|
||||
return M
|
||||
|
89
bundle/cpicker.nvim/lua/cpicker/formats/rgb.lua
Normal file
89
bundle/cpicker.nvim/lua/cpicker/formats/rgb.lua
Normal file
@ -0,0 +1,89 @@
|
||||
--=============================================================================
|
||||
-- rgb.lua ---
|
||||
-- Copyright (c) 2019-2024 Wang Shidong & Contributors
|
||||
-- Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
-- URL: https://spacevim.org
|
||||
-- License: GPLv3
|
||||
--=============================================================================
|
||||
local M = {}
|
||||
|
||||
local color = require('spacevim.api.color')
|
||||
local util = require('cpicker.util')
|
||||
|
||||
local red = 0 -- [0, 1]
|
||||
local green = 0 -- [0, 1]
|
||||
local blue = 0 -- [0, 1]
|
||||
|
||||
M.color_code_regex = [[\s#[0123456789ABCDEF]\+]]
|
||||
|
||||
local function on_change_argv()
|
||||
return 'rgb', { red, green, blue }
|
||||
end
|
||||
|
||||
function M.buf_text()
|
||||
local rst = {}
|
||||
local r_bar = util.generate_bar(red, '+')
|
||||
local g_bar = util.generate_bar(green, '+')
|
||||
local b_bar = util.generate_bar(blue, '+')
|
||||
table.insert(
|
||||
rst,
|
||||
'RGB: R: ' .. string.format('%4s', math.floor(red * 255 + 0.5)) .. ' ' .. r_bar
|
||||
)
|
||||
table.insert(
|
||||
rst,
|
||||
' G: ' .. string.format('%4s', math.floor(green * 255 + 0.5)) .. ' ' .. g_bar
|
||||
)
|
||||
table.insert(
|
||||
rst,
|
||||
' B: ' .. string.format('%4s', math.floor(blue * 255 + 0.5)) .. ' ' .. b_bar
|
||||
)
|
||||
return rst
|
||||
end
|
||||
|
||||
function M.color_code()
|
||||
return ' =========' .. ' ' .. color.rgb2hex(red, green, blue)
|
||||
end
|
||||
|
||||
local function increase_rgb_red()
|
||||
red = util.increase(red, 255)
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_rgb_red()
|
||||
red = util.reduce(red, 255)
|
||||
return on_change_argv()
|
||||
end
|
||||
local function increase_rgb_green()
|
||||
green = util.increase(green, 255)
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_rgb_green()
|
||||
green = util.reduce(green, 255)
|
||||
return on_change_argv()
|
||||
end
|
||||
|
||||
local function increase_rgb_blue()
|
||||
blue = util.increase(blue, 255)
|
||||
return on_change_argv()
|
||||
end
|
||||
|
||||
local function reduce_rgb_blue()
|
||||
blue = util.reduce(blue, 255)
|
||||
return on_change_argv()
|
||||
end
|
||||
function M.increase_reduce_functions()
|
||||
return {
|
||||
{ increase_rgb_red, reduce_rgb_red },
|
||||
{ increase_rgb_green, reduce_rgb_green },
|
||||
{ increase_rgb_blue, reduce_rgb_blue },
|
||||
}
|
||||
end
|
||||
|
||||
function M.on_change(f, code)
|
||||
if f == 'rgb' then
|
||||
red, green, blue = unpack(code)
|
||||
return
|
||||
end
|
||||
red, green, blue = color[f .. '2rgb'](unpack(code))
|
||||
end
|
||||
|
||||
return M
|
92
bundle/cpicker.nvim/lua/cpicker/formats/xyz.lua
Normal file
92
bundle/cpicker.nvim/lua/cpicker/formats/xyz.lua
Normal file
@ -0,0 +1,92 @@
|
||||
--=============================================================================
|
||||
-- xyz.lua ---
|
||||
-- Copyright (c) 2019-2024 Wang Shidong & Contributors
|
||||
-- Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
-- URL: https://spacevim.org
|
||||
-- License: GPLv3
|
||||
--=============================================================================
|
||||
local M = {}
|
||||
|
||||
local color = require('spacevim.api.color')
|
||||
local util = require('cpicker.util')
|
||||
|
||||
local x = 0
|
||||
local y = 0
|
||||
local z = 0
|
||||
|
||||
M.color_code_regex = [[\scolor(xyz,\s\d\+%,\s\d\+%,\s\d\+%)]]
|
||||
|
||||
local function on_change_argv()
|
||||
return 'xyz', { x, y, z }
|
||||
end
|
||||
|
||||
function M.buf_text()
|
||||
local rst = {}
|
||||
local h_bar = util.generate_bar(x, '+')
|
||||
local s_bar = util.generate_bar(y, '+')
|
||||
local l_bar = util.generate_bar(z, '+')
|
||||
table.insert(
|
||||
rst,
|
||||
'XYZ: X: ' .. string.format('%3s', math.floor(x * 100 + 0.5)) .. '% ' .. h_bar
|
||||
)
|
||||
table.insert(
|
||||
rst,
|
||||
' Y: ' .. string.format('%3s', math.floor(y * 100 + 0.5)) .. '% ' .. s_bar
|
||||
)
|
||||
table.insert(
|
||||
rst,
|
||||
' Z: ' .. string.format('%3s', math.floor(z * 100 + 0.5)) .. '% ' .. l_bar
|
||||
)
|
||||
return rst
|
||||
end
|
||||
|
||||
function M.color_code()
|
||||
return
|
||||
' =========' .. string.format(
|
||||
' color(xyz, %s%%, %s%%, %s%%)',
|
||||
math.floor(x * 100 + 0.5),
|
||||
math.floor(y * 100 + 0.5),
|
||||
math.floor(z * 100 + 0.5)
|
||||
)
|
||||
end
|
||||
local function increase_x()
|
||||
x = util.increase(x)
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_x()
|
||||
x = util.reduce(x)
|
||||
return on_change_argv()
|
||||
end
|
||||
local function increase_y()
|
||||
y = util.increase(y)
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_y()
|
||||
y = util.reduce(y)
|
||||
return on_change_argv()
|
||||
end
|
||||
local function increase_z()
|
||||
z = util.increase(z)
|
||||
return on_change_argv()
|
||||
end
|
||||
local function reduce_z()
|
||||
z = util.reduce(z)
|
||||
return on_change_argv()
|
||||
end
|
||||
function M.increase_reduce_functions()
|
||||
return {
|
||||
{ increase_x, reduce_x },
|
||||
{ increase_y, reduce_y },
|
||||
{ increase_z, reduce_z },
|
||||
}
|
||||
end
|
||||
|
||||
function M.on_change(f, code)
|
||||
if f == 'xyz' then
|
||||
x, y, z = unpack(code)
|
||||
return
|
||||
end
|
||||
x, y, z = color[f .. '2xyz'](unpack(code))
|
||||
end
|
||||
|
||||
return M
|
379
bundle/cpicker.nvim/lua/cpicker/mix.lua
Normal file
379
bundle/cpicker.nvim/lua/cpicker/mix.lua
Normal file
@ -0,0 +1,379 @@
|
||||
local M = {}
|
||||
local color_mix_buf
|
||||
local color_mix_win
|
||||
local color_mix_color1
|
||||
local color_mix_color2
|
||||
local color_mix_color3
|
||||
local color_mix_p1 = 0.5
|
||||
local color_mix_p2 = 0.5
|
||||
-- https://developer.mozilla.org/en-US/docs/Web/CSS/color-interpolation-method
|
||||
local available_methods = { 'srgb', 'hsl', 'hwb' }
|
||||
local available_hue_methods = { 'shorter', 'longer', 'increasing', 'decreasing' }
|
||||
local method = 'srgb'
|
||||
local hue_interpolation_method = 'shorter'
|
||||
local hi = require('spacevim.api.vim.highlight')
|
||||
local notify = require('spacevim.api.notify')
|
||||
local util = require('cpicker.util')
|
||||
local color = require('spacevim.api.color')
|
||||
|
||||
local function get_mix_method()
|
||||
if method == 'hsl' then
|
||||
return 'hsl ' .. hue_interpolation_method
|
||||
else
|
||||
return method
|
||||
end
|
||||
end
|
||||
|
||||
local function get_method()
|
||||
local rst = ''
|
||||
for _, m in ipairs(available_methods) do
|
||||
if m == method then
|
||||
rst = rst .. '<' .. m .. '>'
|
||||
else
|
||||
rst = rst .. ' ' .. m .. ' '
|
||||
end
|
||||
end
|
||||
return rst
|
||||
end
|
||||
|
||||
local function get_hue_method()
|
||||
local rst = ''
|
||||
for _, m in ipairs(available_hue_methods) do
|
||||
if m == hue_interpolation_method then
|
||||
rst = rst .. '<' .. m .. '>'
|
||||
else
|
||||
rst = rst .. ' ' .. m .. ' '
|
||||
end
|
||||
end
|
||||
return rst
|
||||
end
|
||||
|
||||
local function update_color_mix_buftext()
|
||||
local r3, g3, b3
|
||||
if method == 'srgb' then
|
||||
local r1, g1, b1 = color.hex2rgb(color_mix_color1)
|
||||
local r2, g2, b2 = color.hex2rgb(color_mix_color2)
|
||||
local p1, p2
|
||||
if color_mix_p1 == 0 and color_mix_p2 == 0 then
|
||||
p1 = 0.5
|
||||
p2 = 0.5
|
||||
else
|
||||
p1 = color_mix_p1 / (color_mix_p1 + color_mix_p2)
|
||||
p2 = color_mix_p2 / (color_mix_p1 + color_mix_p2)
|
||||
end
|
||||
r3, g3, b3 = r1 * p1 + r2 * p2, g1 * p1 + g2 * p2, b1 * p1 + b2 * p2
|
||||
elseif method == 'hsl' or method == 'hwb' then
|
||||
local h1, s1, l1, w1, b1
|
||||
local h2, s2, l2, w2, b2
|
||||
if method == 'hsl' then
|
||||
h1, s1, l1 = color.rgb2hsl(color.hex2rgb(color_mix_color1))
|
||||
h2, s2, l2 = color.rgb2hsl(color.hex2rgb(color_mix_color2))
|
||||
elseif method == 'hwb' then
|
||||
h1, w1, b1 = color.rgb2hwb(color.hex2rgb(color_mix_color1))
|
||||
h2, w2, b2 = color.rgb2hwb(color.hex2rgb(color_mix_color2))
|
||||
end
|
||||
local h3
|
||||
local p1, p2
|
||||
if color_mix_p1 == 0 and color_mix_p2 == 0 then
|
||||
p1 = 0.5
|
||||
p2 = 0.5
|
||||
else
|
||||
p1 = color_mix_p1 / (color_mix_p1 + color_mix_p2)
|
||||
p2 = color_mix_p2 / (color_mix_p1 + color_mix_p2)
|
||||
end
|
||||
if hue_interpolation_method == 'shorter' then
|
||||
if h2 >= h1 then
|
||||
if h2 - h1 <= 180 then
|
||||
h3 = h1 * p1 + h2 * p2
|
||||
else
|
||||
h3 = (h1 + 360) * p1 + h2 * p2
|
||||
end
|
||||
else
|
||||
if h1 - h2 <= 180 then
|
||||
h3 = h1 * p1 + h2 * p2
|
||||
else
|
||||
h3 = h1 * p1 + (h2 + 360) * p2
|
||||
end
|
||||
end
|
||||
elseif hue_interpolation_method == 'longer' then
|
||||
if h2 >= h1 then
|
||||
if h2 - h1 >= 180 then
|
||||
h3 = h1 * p1 + h2 * p2
|
||||
else
|
||||
h3 = (h1 + 360) * p1 + h2 * p2
|
||||
end
|
||||
else
|
||||
if h1 - h2 >= 180 then
|
||||
h3 = h1 * p1 + h2 * p2
|
||||
else
|
||||
h3 = h1 * p1 + (h2 + 360) * p2
|
||||
end
|
||||
end
|
||||
elseif hue_interpolation_method == 'increasing' then
|
||||
if h1 <= h2 then
|
||||
h3 = h1 * p1 + h2 * p2
|
||||
else
|
||||
h3 = h1 * p1 + (h2 + 360) * p2
|
||||
end
|
||||
elseif hue_interpolation_method == 'decreasing' then
|
||||
if h1 >= h2 then
|
||||
h3 = h1 * p1 + h2 * p2
|
||||
else
|
||||
h3 = (h1 + 360) * p1 + h2 * p2
|
||||
end
|
||||
end
|
||||
if h3 >= 360 then
|
||||
h3 = h3 - 360
|
||||
end
|
||||
if method == 'hsl' then
|
||||
r3, g3, b3 = color.hsl2rgb(h3, s1 * p1 + s2 * p2, l1 * p1 + l2 * p2)
|
||||
elseif method == 'hwb' then
|
||||
r3, g3, b3 = color.hwb2rgb(h3, w1 * p1 + w2 * p2, b1 * p1 + b2 * p2)
|
||||
end
|
||||
end
|
||||
-- 验证结果 https://products.aspose.app/svg/zh/color-mixer
|
||||
color_mix_color3 = color.rgb2hex(r3, g3, b3)
|
||||
local normal_bg = hi.group2dict('Normal').guibg
|
||||
local normal_fg = hi.group2dict('Normal').guifg
|
||||
if
|
||||
math.abs(util.get_hsl_l(normal_bg) - util.get_hsl_l(color_mix_color3))
|
||||
> math.abs(util.get_hsl_l(color_mix_color3) - util.get_hsl_l(normal_fg))
|
||||
then
|
||||
hi.hi({
|
||||
name = 'SpaceVimPickerMixColor3Code',
|
||||
guifg = color_mix_color3,
|
||||
guibg = normal_bg,
|
||||
bold = 1,
|
||||
})
|
||||
else
|
||||
hi.hi({
|
||||
name = 'SpaceVimPickerMixColor3Code',
|
||||
guifg = color_mix_color3,
|
||||
guibg = normal_fg,
|
||||
bold = 1,
|
||||
})
|
||||
end
|
||||
hi.hi({
|
||||
name = 'SpaceVimPickerMixColor3Background',
|
||||
guibg = color_mix_color3,
|
||||
guifg = color_mix_color3,
|
||||
})
|
||||
local rst = {}
|
||||
table.insert(
|
||||
rst,
|
||||
' '
|
||||
.. color_mix_color1
|
||||
.. ' '
|
||||
.. 'P1:'
|
||||
.. string.format(' %3s%%', math.floor(color_mix_p1 * 100 + 0.5))
|
||||
.. ' '
|
||||
.. util.generate_bar(color_mix_p1, '+')
|
||||
)
|
||||
table.insert(
|
||||
rst,
|
||||
' '
|
||||
.. color_mix_color2
|
||||
.. ' '
|
||||
.. 'P2:'
|
||||
.. string.format(' %3s%%', math.floor(color_mix_p2 * 100 + 0.5))
|
||||
.. ' '
|
||||
.. util.generate_bar(color_mix_p2, '+')
|
||||
)
|
||||
table.insert(rst, ' method:' .. get_method())
|
||||
table.insert(rst, ' hue:' .. get_hue_method())
|
||||
table.insert(rst, ' ')
|
||||
table.insert(
|
||||
rst,
|
||||
' ======= '
|
||||
.. color_mix_color3
|
||||
.. ' '
|
||||
)
|
||||
table.insert(
|
||||
rst,
|
||||
' ======= '
|
||||
.. string.format(
|
||||
'color-mix(in %s, %s %3s%%, %3s %3s%%) ',
|
||||
get_mix_method(),
|
||||
color_mix_color1,
|
||||
math.floor(color_mix_p1 * 100 + 0.5),
|
||||
color_mix_color2,
|
||||
math.floor(color_mix_p2 * 100 + 0.5)
|
||||
)
|
||||
)
|
||||
vim.api.nvim_set_option_value('modifiable', true, {
|
||||
buf = color_mix_buf,
|
||||
})
|
||||
vim.api.nvim_buf_set_lines(color_mix_buf, 0, -1, false, rst)
|
||||
vim.api.nvim_set_option_value('modifiable', false, {
|
||||
buf = color_mix_buf,
|
||||
})
|
||||
end
|
||||
|
||||
local function increase_p_f(p)
|
||||
if p <= 0.99 then
|
||||
p = p + 0.01
|
||||
elseif p < 1 then
|
||||
p = 1
|
||||
end
|
||||
return p
|
||||
end
|
||||
|
||||
local function reduce_p_f(p)
|
||||
if p >= 0.01 then
|
||||
p = p - 0.01
|
||||
elseif p > 0 then
|
||||
p = 0
|
||||
end
|
||||
return p
|
||||
end
|
||||
|
||||
local function next_hue_method()
|
||||
for i, v in ipairs(available_hue_methods) do
|
||||
if v == hue_interpolation_method then
|
||||
if i == #available_hue_methods then
|
||||
return available_hue_methods[1]
|
||||
else
|
||||
return available_hue_methods[i + 1]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function previous_hue_method()
|
||||
for i, v in ipairs(available_hue_methods) do
|
||||
if v == hue_interpolation_method then
|
||||
if i == 1 then
|
||||
return available_hue_methods[#available_hue_methods]
|
||||
else
|
||||
return available_hue_methods[i - 1]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function next_mix_method()
|
||||
for i, v in ipairs(available_methods) do
|
||||
if v == method then
|
||||
if i == #available_methods then
|
||||
return available_methods[1]
|
||||
else
|
||||
return available_methods[i + 1]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function previous_mix_method()
|
||||
for i, v in ipairs(available_methods) do
|
||||
if v == method then
|
||||
if i == 1 then
|
||||
return available_methods[#available_methods]
|
||||
else
|
||||
return available_methods[i - 1]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function increase_p()
|
||||
if vim.fn.line('.') == 1 then
|
||||
color_mix_p1 = increase_p_f(color_mix_p1)
|
||||
elseif vim.fn.line('.') == 2 then
|
||||
color_mix_p2 = increase_p_f(color_mix_p2)
|
||||
elseif vim.fn.line('.') == 3 then
|
||||
method = next_mix_method()
|
||||
elseif vim.fn.line('.') == 4 then
|
||||
hue_interpolation_method = next_hue_method()
|
||||
end
|
||||
update_color_mix_buftext()
|
||||
end
|
||||
|
||||
local function reduce_p()
|
||||
if vim.fn.line('.') == 1 then
|
||||
color_mix_p1 = reduce_p_f(color_mix_p1)
|
||||
elseif vim.fn.line('.') == 2 then
|
||||
color_mix_p2 = reduce_p_f(color_mix_p2)
|
||||
elseif vim.fn.line('.') == 3 then
|
||||
method = previous_mix_method()
|
||||
elseif vim.fn.line('.') == 4 then
|
||||
hue_interpolation_method = previous_hue_method()
|
||||
end
|
||||
update_color_mix_buftext()
|
||||
end
|
||||
|
||||
local function copy_color_mix()
|
||||
local from, to =
|
||||
vim.regex([[#[0123456789ABCDEF]\+\|color-mix([^)]*)]]):match_str(vim.fn.getline('.'))
|
||||
if from then
|
||||
vim.fn.setreg('+', string.sub(vim.fn.getline('.'), from, to + 1))
|
||||
notify.notify('copied:' .. string.sub(vim.fn.getline('.'), from, to + 1))
|
||||
end
|
||||
end
|
||||
|
||||
M.color_mix = function(hex1, hex2)
|
||||
color_mix_color1 = hex1 or '#000000'
|
||||
color_mix_color2 = hex2 or '#FFFFFF'
|
||||
hi.hi({
|
||||
name = 'SpaceVimPickerMixColor1',
|
||||
guifg = color_mix_color1,
|
||||
bold = 1,
|
||||
})
|
||||
hi.hi({
|
||||
name = 'SpaceVimPickerMixColor2',
|
||||
guifg = color_mix_color2,
|
||||
bold = 1,
|
||||
})
|
||||
if not color_mix_buf or not vim.api.nvim_win_is_valid(color_mix_buf) then
|
||||
color_mix_buf = vim.api.nvim_create_buf(false, false)
|
||||
vim.api.nvim_set_option_value('buftype', 'nofile', {
|
||||
buf = color_mix_buf,
|
||||
})
|
||||
vim.api.nvim_set_option_value('filetype', 'spacevim_cpicker_mix', {
|
||||
buf = color_mix_buf,
|
||||
})
|
||||
vim.api.nvim_set_option_value('bufhidden', 'wipe', {
|
||||
buf = color_mix_buf,
|
||||
})
|
||||
vim.api.nvim_buf_set_keymap(color_mix_buf, 'n', 'l', '', {
|
||||
callback = increase_p,
|
||||
})
|
||||
vim.api.nvim_buf_set_keymap(color_mix_buf, 'n', 'h', '', {
|
||||
callback = reduce_p,
|
||||
})
|
||||
vim.api.nvim_buf_set_keymap(color_mix_buf, 'n', '<Right>', '', {
|
||||
callback = increase_p,
|
||||
})
|
||||
vim.api.nvim_buf_set_keymap(color_mix_buf, 'n', '<Left>', '', {
|
||||
callback = reduce_p,
|
||||
})
|
||||
vim.api.nvim_buf_set_keymap(color_mix_buf, 'n', 'q', '', {
|
||||
callback = function()
|
||||
vim.api.nvim_win_close(color_mix_win, true)
|
||||
end,
|
||||
})
|
||||
vim.api.nvim_buf_set_keymap(color_mix_buf, 'n', '<Cr>', '', {
|
||||
callback = copy_color_mix,
|
||||
})
|
||||
end
|
||||
if not color_mix_win or not vim.api.nvim_win_is_valid(color_mix_win) then
|
||||
color_mix_win = vim.api.nvim_open_win(color_mix_buf, true, {
|
||||
relative = 'cursor',
|
||||
border = 'single',
|
||||
width = 75,
|
||||
height = 7,
|
||||
row = 1,
|
||||
col = 1,
|
||||
})
|
||||
end
|
||||
vim.api.nvim_set_option_value('number', false, {
|
||||
win = color_mix_win,
|
||||
})
|
||||
vim.api.nvim_set_option_value('winhighlight', 'NormalFloat:Normal,FloatBorder:WinSeparator', {
|
||||
win = color_mix_win,
|
||||
})
|
||||
vim.api.nvim_set_option_value('modifiable', false, {
|
||||
buf = color_mix_buf,
|
||||
})
|
||||
update_color_mix_buftext()
|
||||
end
|
||||
return M
|
128
bundle/cpicker.nvim/lua/cpicker/util.lua
Normal file
128
bundle/cpicker.nvim/lua/cpicker/util.lua
Normal file
@ -0,0 +1,128 @@
|
||||
--=============================================================================
|
||||
-- util.lua
|
||||
-- Copyright (c) 2019-2024 Wang Shidong & Contributors
|
||||
-- Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
-- URL: https://spacevim.org
|
||||
-- License: GPLv3
|
||||
--=============================================================================
|
||||
|
||||
local M = {}
|
||||
|
||||
local color = require('spacevim.api.color')
|
||||
|
||||
function M.generate_bar(n, char, m)
|
||||
return string.rep(char, math.floor(24 * n / (m or 1)))
|
||||
end
|
||||
|
||||
function M.get_hex_code(t, code)
|
||||
return color[t .. '2hex'](unpack(code))
|
||||
end
|
||||
|
||||
function M.get_hsl_l(hex)
|
||||
local _, _, l = color.rgb2hsl(color.hex2rgb(hex))
|
||||
return l
|
||||
end
|
||||
|
||||
function M.increase(v, step, min, max)
|
||||
step = step or 100
|
||||
min = min or 0
|
||||
max = max or 1
|
||||
local sep = (max - min) / step
|
||||
v = (math.floor(v / sep + 0.5) + 1) * sep
|
||||
if v >= max then
|
||||
return max
|
||||
elseif v <= min then
|
||||
return min
|
||||
else
|
||||
return v
|
||||
end
|
||||
end
|
||||
|
||||
function M.reduce(v, step, min, max)
|
||||
step = step or 100
|
||||
min = min or 0
|
||||
max = max or 1
|
||||
local sep = (max - min) / step
|
||||
v = (math.floor(v / sep + 0.5) - 1) * sep
|
||||
if v >= max then
|
||||
return max
|
||||
elseif v <= min then
|
||||
return min
|
||||
else
|
||||
return v
|
||||
end
|
||||
end
|
||||
|
||||
function M.update_color_code_syntax(r)
|
||||
local max = 0
|
||||
local regexes = {}
|
||||
for _, v in ipairs(r) do
|
||||
max = math.max(max, v[1])
|
||||
end
|
||||
regexes = vim.tbl_map(function(val)
|
||||
return val[2] .. string.rep('\\s', max - val[1])
|
||||
end, r)
|
||||
vim.cmd('syn match SpaceVimPickerCode /' .. table.concat(regexes, '\\|') .. '/')
|
||||
end
|
||||
|
||||
local function get_color(name)
|
||||
local c = vim.api.nvim_get_hl(0, { name = name })
|
||||
|
||||
if c.link then
|
||||
return get_color(c.link)
|
||||
else
|
||||
return c
|
||||
end
|
||||
end
|
||||
|
||||
function M.set_default_color(formats)
|
||||
if #formats == 0 then
|
||||
formats = { 'rgb', 'hsl' }
|
||||
else
|
||||
formats = formats
|
||||
end
|
||||
local inspect = vim.inspect_pos()
|
||||
local hex
|
||||
if #inspect.semantic_tokens > 0 then
|
||||
local token, priority = {}, 0
|
||||
for _, semantic_token in ipairs(inspect.semantic_tokens) do
|
||||
if semantic_token.opts.priority > priority then
|
||||
priority = semantic_token.opts.priority
|
||||
token = semantic_token
|
||||
end
|
||||
end
|
||||
if token then
|
||||
local fg = vim.api.nvim_get_hl(0, { name = token.opts.hl_group_link }).fg
|
||||
if fg then
|
||||
hex = string.format('#%06X', fg)
|
||||
end
|
||||
end
|
||||
elseif #inspect.treesitter > 0 then
|
||||
for i = #inspect.treesitter, 1, -1 do
|
||||
local fg = vim.api.nvim_get_hl(0, { name = inspect.treesitter[i].hl_group_link }).fg
|
||||
if fg then
|
||||
hex = string.format('#%06X', fg)
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
local name = vim.fn.synIDattr(vim.fn.synID(vim.fn.line('.'), vim.fn.col('.'), 1), 'name', 'gui')
|
||||
local fg = get_color(name).fg
|
||||
if fg then
|
||||
hex = string.format('#%06X', fg)
|
||||
end
|
||||
end
|
||||
|
||||
if hex then
|
||||
require('cpicker').set_default_color(hex)
|
||||
local r, g, b = color.hex2rgb(hex)
|
||||
for _, format in ipairs(formats) do
|
||||
local ok, f = pcall(require, 'cpicker.formats.' .. format)
|
||||
if ok then
|
||||
f.on_change('rgb', { r, g, b })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
23
bundle/cpicker.nvim/plugin/cpicker.lua
Normal file
23
bundle/cpicker.nvim/plugin/cpicker.lua
Normal file
@ -0,0 +1,23 @@
|
||||
--=============================================================================
|
||||
-- cpicker.lua
|
||||
-- Copyright (c) 2019-2024 Wang Shidong & Contributors
|
||||
-- Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
-- URL: https://spacevim.org
|
||||
-- License: GPLv3
|
||||
--=============================================================================
|
||||
|
||||
if vim.api.nvim_create_user_command then
|
||||
local function complete()
|
||||
return { 'rgb', 'hsl', 'hsv', 'cmyk', 'hwb', 'linear', 'lab' }
|
||||
end
|
||||
vim.api.nvim_create_user_command('Cpicker', function(opt)
|
||||
require('cpicker').picker(opt.fargs)
|
||||
end, { nargs = '*', complete = complete })
|
||||
vim.api.nvim_create_user_command('CpickerCursorForeground', function(opt)
|
||||
require('cpicker.util').set_default_color(opt.fargs)
|
||||
require('cpicker').picker(opt.fargs)
|
||||
end, { nargs = '*', complete = complete })
|
||||
vim.api.nvim_create_user_command('CpickerColorMix', function(opt)
|
||||
require('cpicker.mix').color_mix(unpack(opt.fargs))
|
||||
end, { nargs = '*', complete = complete })
|
||||
end
|
13
bundle/cpicker.nvim/syntax/spacevim_cpicker.vim
Normal file
13
bundle/cpicker.nvim/syntax/spacevim_cpicker.vim
Normal file
@ -0,0 +1,13 @@
|
||||
if exists('b:current_syntax') && b:current_syntax ==# 'spacevim_cpicker'
|
||||
finish
|
||||
endif
|
||||
let b:current_syntax = 'spacevim_cpicker'
|
||||
syntax case ignore
|
||||
|
||||
syn match ProcessBar /[?=+]\+/
|
||||
" syn match SpaceVimPickerCode /\s#[0123456789ABCDEF]\+\|\srgb(\d\+,\s\d\+,\s\d\+)\|\shsl(\d\+,\s\d\+%,\s\d\+%)\|\shsv(\d\+,\s\d\+%,\s\d\+%)\|\scmyk(\d\+%,\s\d\+%,\s\d\+%,\s\d\+%)\|\shwb(\d\+,\s\d\+%,\s\d\+%)/
|
||||
syn match SpaceVimPickerBackground /=\+\s/
|
||||
|
||||
highlight ProcessBar ctermfg=Gray ctermbg=Gray guifg=Gray guibg=Gray
|
||||
|
||||
|
23
bundle/cpicker.nvim/syntax/spacevim_cpicker_mix.vim
Normal file
23
bundle/cpicker.nvim/syntax/spacevim_cpicker_mix.vim
Normal file
@ -0,0 +1,23 @@
|
||||
if exists('b:current_syntax') && b:current_syntax ==# 'spacevim_cpicker_mix'
|
||||
finish
|
||||
endif
|
||||
let b:current_syntax = 'spacevim_cpicker_mix'
|
||||
syntax case ignore
|
||||
|
||||
syn match SpaceVimPickerMixProcessBar /[?=+]\+/
|
||||
syn match SpaceVimPickerMixColor1P /P1/ contained
|
||||
syn match SpaceVimPickerMixColor2P /P2/ contained
|
||||
syn match SpaceVimPickerMixColor1 /#[0123456789ABCDEF]\+\s\+P1/ contains=SpaceVimPickerMixColor1P
|
||||
syn match SpaceVimPickerMixColor2 /#[0123456789ABCDEF]\+\s\+P2/ contains=SpaceVimPickerMixColor2P
|
||||
syn match SpaceVimPickerMixColor3 /=\+\s/
|
||||
syn match SpaceVimPickerMixColor3Background /\s=\+\s/
|
||||
syn match SpaceVimPickerMixColor3Code /\scolor-mix...............................................\|\s#......\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s/
|
||||
syn match SpaceVimPickerMixMethodFlag /[<>]/ contained
|
||||
syn match SpaceVimPickerMixMethod /[<>].\+[<>]/ contains=SpaceVimPickerMixMethodFlag
|
||||
|
||||
highlight SpaceVimPickerMixProcessBar ctermfg=Gray ctermbg=Gray guifg=Gray guibg=Gray
|
||||
highlight link SpaceVimPickerMixMethodFlag EndOfBuffer
|
||||
highlight SpaceVimPickerMixMethod ctermfg=Black ctermbg=Gray guifg=Black guibg=Gray
|
||||
highlight link SpaceVimPickerMixColor1P Normal
|
||||
highlight link SpaceVimPickerMixColor2P Normal
|
||||
|
@ -243,14 +243,15 @@ CONTENTS *SpaceVim-contents*
|
||||
139. telescope................................ |SpaceVim-layers-telescope|
|
||||
140. test.......................................... |SpaceVim-layers-test|
|
||||
141. tmux.......................................... |SpaceVim-layers-tmux|
|
||||
142. tools#dash.............................. |SpaceVim-layers-tools-dash|
|
||||
143. tools#mpv................................ |SpaceVim-layers-tools-mpv|
|
||||
144. tools#screensaver................ |SpaceVim-layers-tools-screensaver|
|
||||
145. tools#zeal.............................. |SpaceVim-layers-tools-zeal|
|
||||
146. treesitter.............................. |SpaceVim-layers-treesitter|
|
||||
147. ui.............................................. |SpaceVim-layers-ui|
|
||||
148. unite........................................ |SpaceVim-layers-unite|
|
||||
149. xmake........................................ |SpaceVim-layers-xmake|
|
||||
142. tools#cpicker........................ |SpaceVim-layers-tools-cpicker|
|
||||
143. tools#dash.............................. |SpaceVim-layers-tools-dash|
|
||||
144. tools#mpv................................ |SpaceVim-layers-tools-mpv|
|
||||
145. tools#screensaver................ |SpaceVim-layers-tools-screensaver|
|
||||
146. tools#zeal.............................. |SpaceVim-layers-tools-zeal|
|
||||
147. treesitter.............................. |SpaceVim-layers-treesitter|
|
||||
148. ui.............................................. |SpaceVim-layers-ui|
|
||||
149. unite........................................ |SpaceVim-layers-unite|
|
||||
150. xmake........................................ |SpaceVim-layers-xmake|
|
||||
7. Usage..................................................... |SpaceVim-usage|
|
||||
1. Editing....................................... |SpaceVim-usage-editing|
|
||||
2. Error handling......................... |SpaceVim-usage-error-handling|
|
||||
@ -6290,6 +6291,46 @@ MAPPINGS
|
||||
<C-l> normal Switch to vim/tmux pane in right direction
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
TOOLS#CPICKER *SpaceVim-layers-tools-cpicker*
|
||||
|
||||
The `tools#cpicker` layer provides a color picker. this layer is disabled by
|
||||
default, to enable this layer, add following snippet to your SpaceVim
|
||||
configuration file.
|
||||
>
|
||||
[[layers]]
|
||||
name = 'tools#cpicker'
|
||||
<
|
||||
|
||||
LAYER OPTIONS
|
||||
1. default_spaces: set the default color spaces, the default value is
|
||||
`['rgb', 'hsl']`
|
||||
|
||||
KEY BINDINGS
|
||||
|
||||
>
|
||||
Key Function
|
||||
---------------------------------------------
|
||||
SPC i p c open color picker
|
||||
<
|
||||
|
||||
Key bindings in cpicker:
|
||||
>
|
||||
Key Function
|
||||
---------------------------------------------
|
||||
<Enter> copy color
|
||||
j/<Down> move cursor down
|
||||
k/<Up> move cursor up
|
||||
h/<Left> reduce
|
||||
l/<Right> increase
|
||||
<
|
||||
COMMANDS
|
||||
Instead of using key Binding, this layer also provides a Neovim command
|
||||
`:Cpicker` which can be used in cmdline. For example:
|
||||
>
|
||||
:Cpicker rgb cmyk
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
TOOLS#DASH *SpaceVim-layers-tools-dash*
|
||||
|
||||
|
@ -31,6 +31,34 @@ call SpaceVim#dev#followHEAD#update('cn')
|
||||
<!-- SpaceVim follow HEAD start -->
|
||||
## 新特性
|
||||
|
||||
- feat(cpicker): add tools#cpicker layer
|
||||
- feat(core): add logevent plugin
|
||||
- feat(github): add ci files
|
||||
- feat(github): enable github action
|
||||
- perf(core): add opt for lazy load config
|
||||
- perf(tabline): use BufAdd instead of BufNew
|
||||
- perf(lazy): lazy load plugins
|
||||
- perf(dein): skip type checking
|
||||
- perf(layer): lazy load layer config
|
||||
- perf(neo-tree): use lua notify
|
||||
- perf(plugins): lazy load plugins
|
||||
- perf(git): add key binding `v` to view log
|
||||
- feat(qml): add `lang#qml` layer
|
||||
- perf(buf): open buf in best win
|
||||
- perf(nvimtree): use nvim-web-devicons
|
||||
- perf(markdown): lazy load toc plugin
|
||||
- perf(core): lazy load core plugins
|
||||
- perf(edit): lazy load grammarous and tabular
|
||||
- perf(checkers): lazy load neomake
|
||||
- feat(autocmd): add SpaceVimLspSetup autocmd
|
||||
- perf(start): lazy load plugins
|
||||
- perf(cmp): lazy load nvim-cmp
|
||||
- perf(telescope): lazy load telescope
|
||||
- perf(co-author): complete co-author info
|
||||
- perf(gtags): make gtags and ctags lazy loaded
|
||||
- perf(default): remove unused var & functions
|
||||
- perf(neovim): use nvim-cmp & skip checking python
|
||||
- perf(guide): remove debug info
|
||||
- perf(statusline): support quickfix & loclist
|
||||
- perf(install): clone repo with --depth 1
|
||||
- perf(stl): add input_method function
|
||||
@ -90,6 +118,23 @@ call SpaceVim#dev#followHEAD#update('cn')
|
||||
|
||||
## 问题修复
|
||||
|
||||
- fix(mapping): fix SPC a r/o
|
||||
- fix(mapping): fix SPC b d key binding
|
||||
- fix(tabline): update tabline on buflisted changed
|
||||
- fix(custom): fix unknown key
|
||||
- fix(mirror): remove `-f` opt
|
||||
- fix(tabline): handle `BufNew` event
|
||||
- fix(menu): fix unite menu
|
||||
- fix(tasks): fix task status
|
||||
- fix(format): format code in visual mode
|
||||
- fix(git): fix git lazy command
|
||||
- fix(projectmanager): skip when &autochdir is true
|
||||
- fix(lsp): fix lua lsp WarningMsg
|
||||
- fix(guide): fix prompt of flygrep
|
||||
- fix(markdown): lazy load toc plugin on_ft
|
||||
- fix(layer): fix all unknown functions
|
||||
- fix(notify): fix unknown functions
|
||||
- fix(find): fix find statusline
|
||||
- fix(file): fix file api
|
||||
- fix(python): add debug info for Shebang_to_cmd
|
||||
- fix(compatible): fix nvim-0.5.0 support
|
||||
@ -142,6 +187,25 @@ call SpaceVim#dev#followHEAD#update('cn')
|
||||
|
||||
## 文档更新
|
||||
|
||||
- docs(readme): update readme
|
||||
- docs(bundle-plugins): add neo-tree link
|
||||
- docs(autocomplete): update doc
|
||||
- docs(opt): update doc of filemanager
|
||||
- docs(help): update and rollback
|
||||
- docs(help): update doc for editing
|
||||
- docs(about): remove support email
|
||||
- docs(help): update doc for tabline
|
||||
- docs(help): update doc for filetree
|
||||
- docs(typo): fix typo in post
|
||||
- docs(help): add windows and ui doc
|
||||
- docs(error): update doc for error handling
|
||||
- docs(help): update buffer/file doc
|
||||
- docs(highlighter): add doc for SPC s h
|
||||
- docs(help): update help SpaceVim-options
|
||||
- docs(guide): update help doc for mapping guide
|
||||
- docs(help): update doc
|
||||
- docs(help): add `:h SpaceVim-roadmap/community`
|
||||
- docs(website): update following head and roadmap
|
||||
- docs(scrollbar): add doc
|
||||
- docs(tabline): add doc for ctrl-shift-letf/right
|
||||
- docs(nerdtree): update doc for `ctrl-h`
|
||||
@ -164,9 +228,15 @@ call SpaceVim#dev#followHEAD#update('cn')
|
||||
|
||||
## 测试
|
||||
|
||||
- test(vader): fix vader test
|
||||
|
||||
## 其他
|
||||
|
||||
- build(docker): use new docker repo
|
||||
- build(makefile): update makefile
|
||||
- chore(colorscheme): use bundle vim-hybrid
|
||||
- chore(pydocstring): use bundle pydocstring
|
||||
- chore(bundle): use bundle splitjoin
|
||||
- chore(bundle): update helpful.vim
|
||||
- revert(html): remove copy button
|
||||
- refactor(format): refactor on_exit function
|
||||
|
@ -1,10 +1,10 @@
|
||||
---
|
||||
title: "源代码"
|
||||
title: "源码仓库"
|
||||
description: "SpaceVim 源代码"
|
||||
lang: zh
|
||||
---
|
||||
|
||||
# SpaceVim 源代码
|
||||
# [开发者文档](../../../development/) > 源码仓库
|
||||
|
||||
SpaceVim 的源码托管于在线仓库,可以克隆至本地查看源码。
|
||||
|
||||
|
@ -63,7 +63,9 @@ Vim 插件以及相关配置。而 SpaceVim 是以模块的方式来组织和管
|
||||
enable = false
|
||||
```
|
||||
|
||||
<!-- 更新模块列表: call SpaceVim#dev#layers#updateCn() -->
|
||||
<!-- 更新模块列表:
|
||||
call SpaceVim#dev#layers#updateCn()
|
||||
-->
|
||||
|
||||
<!-- SpaceVim layer cn list start -->
|
||||
|
||||
@ -130,7 +132,7 @@ Vim 插件以及相关配置。而 SpaceVim 是以模块的方式来组织和管
|
||||
| [lang#hy](lang/hy/) | 这一模块为 hy 开发提供支持,包括交互式编程、一键运行等特性。 |
|
||||
| [lang#idris](lang/idris/) | 这一模块为 idris 开发提供支持,包括交互式编程、一键运行等特性。 |
|
||||
| [lang#io](lang/io/) | 这一模块为 io 开发提供支持,包括交互式编程、一键运行等特性。 |
|
||||
| [lang#ipynb](lang/ipynb/) | 该模块为 SpaceVim 添加了 Jupyter Notebook 支持,包括语法高亮、代码折叠等特点。 |
|
||||
| [lang#ipynb](lang/ipynb/) | 该模块为SpaceVim添加了 Jupyter Notebook 支持,包括语法高亮、代码折叠等特点。 |
|
||||
| [lang#j](lang/j/) | 这一模块为 j 开发提供支持,包括交互式编程和语法高亮。 |
|
||||
| [lang#janet](lang/janet/) | 这一模块为 janet 开发提供支持,包括交互式编程、一键运行等特性。 |
|
||||
| [lang#java](lang/java/) | 这一模块为 Java 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 |
|
||||
@ -192,13 +194,15 @@ Vim 插件以及相关配置。而 SpaceVim 是以模块的方式来组织和管
|
||||
| [sudo](sudo/) | 这一模块为 SpaceVim 提供了以管理员身份读写文件的功能。 |
|
||||
| [test](test/) | 这一模块为 SpaceVim 提供了一个测试框架,支持快速运行多种语言的单元测试。 |
|
||||
| [tmux](tmux/) | 这一模块为 SpaceVim 提供了一些在 Vim 内操作 tmux 的功能,使得在 tmux 窗口之间跳转更加便捷。 |
|
||||
| [tools#cpicker](tools/cpicker/) | 这一模块为 SpaceVim 提供了调色板功能,可以快速调配颜色。 |
|
||||
| [tools#dash](tools/dash/) | 这一模块为 SpaceVim 提供了 Dash 支持,可快速查找光标位置的单词。 |
|
||||
| [tools#mpv](tools/mpv/) | 这一模块为 SpaceVim 提供了 mpv 支持,可快速查找光标位置的单词。 |
|
||||
| [tools#mpv](tools/mpv/) | 这一模块为 SpaceVim 提供了mpv支持,可快速查找光标位置的单词。 |
|
||||
| [tools](tools/) | 这一模块为 SpaceVim 提供了多种常用工具,包括日历、计算器等多种工具类插件,并针对 Vim8 以及 Neovim 提供了更好的插件选择。 |
|
||||
| [treesitter](treesitter/) | 这一模块为 SpaceVim 提供了一些在 Vim 内操作 treesitter 的功能 |
|
||||
| [ui](ui/) | 这一模块为 SpaceVim 提供了 IDE-like 的界面,包括状态栏、文件树、语法树等等特性。 |
|
||||
| [unite](unite/) | 这一模块为 SpaceVim 提供以 Unite 为核心的模糊查找机制,支持模糊搜索文件、历史纪录、函数列表等。 |
|
||||
| [VersionControl](VersionControl/) | 这一模块为 SpaceVim 提供了通用的代码版本控制支持,该模块支持 Git、Mercurial、Bazaar、SVN 等等多种后台工具。 |
|
||||
| [xmake](xmake/) | 这一模块为 SpaceVim 提供了一些在 Vim 内操作 xmake 的功能。 |
|
||||
|
||||
<!-- SpaceVim layer cn list end -->
|
||||
|
||||
|
34
docs/cn/layers/tools/cpicker.md
Normal file
34
docs/cn/layers/tools/cpicker.md
Normal file
@ -0,0 +1,34 @@
|
||||
---
|
||||
title: "SpaceVim tools#cpicker 模块"
|
||||
description: "这一模块为 SpaceVim 提供了调色板功能,可以快速调配颜色。"
|
||||
lang: zh
|
||||
---
|
||||
|
||||
# [可用模块](../../) >> tools#cpicker
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [模块描述](#模块描述)
|
||||
- [启用模块](#启用模块)
|
||||
- [快捷键](#快捷键)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
## 模块描述
|
||||
|
||||
该模块为 SpaceVim 提供了调色板功能, 需要 Neovim 0.10+。
|
||||
|
||||
## 启用模块
|
||||
|
||||
tools#mpv 模块默认并未启用,如果需要启用该模块,需要在配置文件里面加入:
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = "tools#cpicker"
|
||||
```
|
||||
|
||||
## 快捷键
|
||||
|
||||
| 快捷键 | 功能描述 |
|
||||
| ----------- | ---------- |
|
||||
| `SPC i p c` | 打开调色板 |
|
@ -1,53 +1,53 @@
|
||||
---
|
||||
title: "SpaceVim tools#mpv 模块"
|
||||
description: "这一模块为 SpaceVim 提供了mpv支持,可快速查找光标位置的单词。"
|
||||
lang: zh
|
||||
---
|
||||
|
||||
# [可用模块](../) >> tools#mpv
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [模块描述](#模块描述)
|
||||
- [启用模块](#启用模块)
|
||||
- [模块选项](#模块选项)
|
||||
- [快捷键](#快捷键)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
## 模块描述
|
||||
|
||||
该模块为 SpaceVim 提供了 mpv 集成。
|
||||
|
||||
## 启用模块
|
||||
|
||||
tools#mpv 模块默认并未启用,如果需要启用该模块,需要在配置文件里面加入:
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = "tools#mpv"
|
||||
```
|
||||
|
||||
## 模块选项
|
||||
|
||||
- `musics_directory`: 设置音乐存放文件夹,默认的文件夹是`~/Music`。
|
||||
- `mpv_interpreter`: mpv 可执行命令路径
|
||||
- `loop_mode`: 循环模式,默认是 `random`
|
||||
|
||||
example:
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = 'tools#mpv'
|
||||
mpv_interpreter = 'D:\Program Files\mpv\mpv.exe'
|
||||
musics_directory = 'F:\other\musics'
|
||||
```
|
||||
|
||||
|
||||
## 快捷键
|
||||
|
||||
| 快捷键 | 功能描述 |
|
||||
| ----------- | ---------------- |
|
||||
| `SPC m m l` | 模糊搜索音乐列表 |
|
||||
| `SPC m m n` | 下一首 |
|
||||
| `SPC m m s` | 停止播放 |
|
||||
---
|
||||
title: "SpaceVim tools#mpv 模块"
|
||||
description: "这一模块为 SpaceVim 提供了mpv支持,可快速查找光标位置的单词。"
|
||||
lang: zh
|
||||
---
|
||||
|
||||
# [可用模块](../../) >> tools#mpv
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [模块描述](#模块描述)
|
||||
- [启用模块](#启用模块)
|
||||
- [模块选项](#模块选项)
|
||||
- [快捷键](#快捷键)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
## 模块描述
|
||||
|
||||
该模块为 SpaceVim 提供了 mpv 集成。
|
||||
|
||||
## 启用模块
|
||||
|
||||
tools#mpv 模块默认并未启用,如果需要启用该模块,需要在配置文件里面加入:
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = "tools#mpv"
|
||||
```
|
||||
|
||||
## 模块选项
|
||||
|
||||
- `musics_directory`: 设置音乐存放文件夹,默认的文件夹是`~/Music`。
|
||||
- `mpv_interpreter`: mpv 可执行命令路径
|
||||
- `loop_mode`: 循环模式,默认是 `random`
|
||||
|
||||
example:
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = 'tools#mpv'
|
||||
mpv_interpreter = 'D:\Program Files\mpv\mpv.exe'
|
||||
musics_directory = 'F:\other\musics'
|
||||
```
|
||||
|
||||
|
||||
## 快捷键
|
||||
|
||||
| 快捷键 | 功能描述 |
|
||||
| ----------- | ---------------- |
|
||||
| `SPC m m l` | 模糊搜索音乐列表 |
|
||||
| `SPC m m n` | 下一首 |
|
||||
| `SPC m m s` | 停止播放 |
|
||||
|
@ -30,6 +30,34 @@ call SpaceVim#dev#followHEAD#update('en')
|
||||
<!-- SpaceVim follow HEAD start -->
|
||||
## New features
|
||||
|
||||
- feat(cpicker): add tools#cpicker layer
|
||||
- feat(core): add logevent plugin
|
||||
- feat(github): add ci files
|
||||
- feat(github): enable github action
|
||||
- perf(core): add opt for lazy load config
|
||||
- perf(tabline): use BufAdd instead of BufNew
|
||||
- perf(lazy): lazy load plugins
|
||||
- perf(dein): skip type checking
|
||||
- perf(layer): lazy load layer config
|
||||
- perf(neo-tree): use lua notify
|
||||
- perf(plugins): lazy load plugins
|
||||
- perf(git): add key binding `v` to view log
|
||||
- feat(qml): add `lang#qml` layer
|
||||
- perf(buf): open buf in best win
|
||||
- perf(nvimtree): use nvim-web-devicons
|
||||
- perf(markdown): lazy load toc plugin
|
||||
- perf(core): lazy load core plugins
|
||||
- perf(edit): lazy load grammarous and tabular
|
||||
- perf(checkers): lazy load neomake
|
||||
- feat(autocmd): add SpaceVimLspSetup autocmd
|
||||
- perf(start): lazy load plugins
|
||||
- perf(cmp): lazy load nvim-cmp
|
||||
- perf(telescope): lazy load telescope
|
||||
- perf(co-author): complete co-author info
|
||||
- perf(gtags): make gtags and ctags lazy loaded
|
||||
- perf(default): remove unused var & functions
|
||||
- perf(neovim): use nvim-cmp & skip checking python
|
||||
- perf(guide): remove debug info
|
||||
- perf(statusline): support quickfix & loclist
|
||||
- perf(install): clone repo with --depth 1
|
||||
- perf(stl): add input_method function
|
||||
@ -89,6 +117,23 @@ call SpaceVim#dev#followHEAD#update('en')
|
||||
|
||||
## Bugfixs
|
||||
|
||||
- fix(mapping): fix SPC a r/o
|
||||
- fix(mapping): fix SPC b d key binding
|
||||
- fix(tabline): update tabline on buflisted changed
|
||||
- fix(custom): fix unknown key
|
||||
- fix(mirror): remove `-f` opt
|
||||
- fix(tabline): handle `BufNew` event
|
||||
- fix(menu): fix unite menu
|
||||
- fix(tasks): fix task status
|
||||
- fix(format): format code in visual mode
|
||||
- fix(git): fix git lazy command
|
||||
- fix(projectmanager): skip when &autochdir is true
|
||||
- fix(lsp): fix lua lsp WarningMsg
|
||||
- fix(guide): fix prompt of flygrep
|
||||
- fix(markdown): lazy load toc plugin on_ft
|
||||
- fix(layer): fix all unknown functions
|
||||
- fix(notify): fix unknown functions
|
||||
- fix(find): fix find statusline
|
||||
- fix(file): fix file api
|
||||
- fix(python): add debug info for Shebang_to_cmd
|
||||
- fix(compatible): fix nvim-0.5.0 support
|
||||
@ -141,6 +186,25 @@ call SpaceVim#dev#followHEAD#update('en')
|
||||
|
||||
## Docs
|
||||
|
||||
- docs(readme): update readme
|
||||
- docs(bundle-plugins): add neo-tree link
|
||||
- docs(autocomplete): update doc
|
||||
- docs(opt): update doc of filemanager
|
||||
- docs(help): update and rollback
|
||||
- docs(help): update doc for editing
|
||||
- docs(about): remove support email
|
||||
- docs(help): update doc for tabline
|
||||
- docs(help): update doc for filetree
|
||||
- docs(typo): fix typo in post
|
||||
- docs(help): add windows and ui doc
|
||||
- docs(error): update doc for error handling
|
||||
- docs(help): update buffer/file doc
|
||||
- docs(highlighter): add doc for SPC s h
|
||||
- docs(help): update help SpaceVim-options
|
||||
- docs(guide): update help doc for mapping guide
|
||||
- docs(help): update doc
|
||||
- docs(help): add `:h SpaceVim-roadmap/community`
|
||||
- docs(website): update following head and roadmap
|
||||
- docs(scrollbar): add doc
|
||||
- docs(tabline): add doc for ctrl-shift-letf/right
|
||||
- docs(nerdtree): update doc for `ctrl-h`
|
||||
@ -163,9 +227,15 @@ call SpaceVim#dev#followHEAD#update('en')
|
||||
|
||||
## Tests
|
||||
|
||||
- test(vader): fix vader test
|
||||
|
||||
## Others
|
||||
|
||||
- build(docker): use new docker repo
|
||||
- build(makefile): update makefile
|
||||
- chore(colorscheme): use bundle vim-hybrid
|
||||
- chore(pydocstring): use bundle pydocstring
|
||||
- chore(bundle): use bundle splitjoin
|
||||
- chore(bundle): update helpful.vim
|
||||
- revert(html): remove copy button
|
||||
- refactor(format): refactor on_exit function
|
||||
|
@ -1,9 +1,9 @@
|
||||
---
|
||||
title: "Source code"
|
||||
title: "Git Repository"
|
||||
description: "The source code of SpaceVim."
|
||||
---
|
||||
|
||||
# The source code of SpaceVim
|
||||
# [Development](../../../development/) >> Git Repository
|
||||
|
||||
The source code of SpaceVim is hosted in an online repository and can be cloned locally to view the source code.
|
||||
|
||||
@ -11,7 +11,7 @@ The source code of SpaceVim is hosted in an online repository and can be cloned
|
||||
git clone https://spacevim.org/git/repos/SpaceVim/
|
||||
```
|
||||
|
||||
Since the code was previously hosted on GitHub, some old users need to manually modify the remote repository address:
|
||||
Since the code was previously hosted on GitHub, old users need to modify the remote repository address manually:
|
||||
|
||||
```
|
||||
cd ~/.SpaceVim
|
||||
|
@ -58,7 +58,9 @@ Some layers are enabled by default. The following example shows how to disable `
|
||||
enable = false
|
||||
```
|
||||
|
||||
<!-- Update layer list: call SpaceVim#dev#layers#update() -->
|
||||
<!-- Update layer list:
|
||||
call SpaceVim#dev#layers#update()
|
||||
-->
|
||||
|
||||
<!-- SpaceVim layer list start -->
|
||||
|
||||
@ -203,6 +205,7 @@ Some layers are enabled by default. The following example shows how to disable `
|
||||
| [telescope](telescope/) | This layer provides a heavily customized telescope centric workflow |
|
||||
| [test](test/) | This layer allows to run tests directly in SpaceVim |
|
||||
| [tmux](tmux/) | This layers adds extensive support for tmux |
|
||||
| [tools#cpicker](tools/cpicker/) | This layer provides color picker for SpaceVim |
|
||||
| [tools#dash](tools/dash/) | This layer provides Dash integration for SpaceVim |
|
||||
| [tools#mpv](tools/mpv/) | This layer provides mpv integration for SpaceVim |
|
||||
| [tools#zeal](tools/zeal/) | This layer provides Zeal integration for SpaceVim |
|
||||
|
47
docs/layers/tools/cpicker.md
Normal file
47
docs/layers/tools/cpicker.md
Normal file
@ -0,0 +1,47 @@
|
||||
---
|
||||
title: "SpaceVim cpicker layer"
|
||||
description: "This layer provides color picker for SpaceVim"
|
||||
---
|
||||
|
||||
# [Available Layers](../../) >> tools#cpicker
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [Description](#description)
|
||||
- [Install](#install)
|
||||
- [Layer options](#layer-options)
|
||||
- [Key bindings](#key-bindings)
|
||||
- [Commands](#commands)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
## Description
|
||||
|
||||
This layer provides color picker for SpaceVim. It requires neovim 0.10+.
|
||||
|
||||
## Install
|
||||
|
||||
To use this configuration layer, add it to your `~/.SpaceVim.d/init.toml`.
|
||||
|
||||
```vim
|
||||
[[layers]]
|
||||
name = "tools#cpicker"
|
||||
```
|
||||
|
||||
## Layer options
|
||||
|
||||
1. default_spaces: set the default color spaces, the default value is `['rgb', 'hsl']`. Available spaces: rgb, hsl, hsv, cmyk.
|
||||
|
||||
## Key bindings
|
||||
|
||||
| Key Binding | Description |
|
||||
| ----------- | ----------------- |
|
||||
| `SPC i p c` | open color picker |
|
||||
|
||||
## Commands
|
||||
|
||||
Instead of using key Binding, this layer also provides a Neovim command `:Cpicker` which can be used in cmdline. For example:
|
||||
|
||||
```
|
||||
:Cpicker rgb cmyk
|
||||
```
|
88
log.txt
88
log.txt
@ -1,88 +0,0 @@
|
||||
--- Startup times for process: Primary/TUI ---
|
||||
|
||||
times in msec
|
||||
clock self+sourced self: sourced script
|
||||
clock elapsed: other lines
|
||||
|
||||
000.003 000.003: --- NVIM STARTING ---
|
||||
000.049 000.046: event init
|
||||
000.129 000.080: early init
|
||||
016.058 015.929: locale set
|
||||
016.094 000.036: init first window
|
||||
016.622 000.528: inits 1
|
||||
016.697 000.075: window checked
|
||||
016.707 000.010: parsing arguments
|
||||
017.588 000.288 000.288: require('vim.shared')
|
||||
018.093 000.169 000.169: require('vim.inspect')
|
||||
018.390 000.282 000.282: require('vim._options')
|
||||
018.394 000.799 000.348: require('vim._editor')
|
||||
018.397 001.187 000.100: require('vim._init_packages')
|
||||
018.405 000.511: init lua interpreter
|
||||
022.946 004.542: --- NVIM STARTED ---
|
||||
|
||||
--- Startup times for process: Embedded ---
|
||||
|
||||
times in msec
|
||||
clock self+sourced self: sourced script
|
||||
clock elapsed: other lines
|
||||
|
||||
000.003 000.003: --- NVIM STARTING ---
|
||||
000.050 000.047: event init
|
||||
000.151 000.101: early init
|
||||
016.239 016.088: locale set
|
||||
016.274 000.035: init first window
|
||||
016.709 000.435: inits 1
|
||||
016.757 000.049: window checked
|
||||
016.768 000.010: parsing arguments
|
||||
017.664 000.282 000.282: require('vim.shared')
|
||||
018.228 000.183 000.183: require('vim.inspect')
|
||||
018.524 000.283 000.283: require('vim._options')
|
||||
018.529 000.858 000.392: require('vim._editor')
|
||||
018.532 001.241 000.101: require('vim._init_packages')
|
||||
018.541 000.532: init lua interpreter
|
||||
018.731 000.190: expanding arguments
|
||||
018.748 000.017: inits 2
|
||||
019.224 000.476: init highlight
|
||||
019.227 000.003: waiting for UI
|
||||
019.284 000.057: done waiting for UI
|
||||
019.287 000.004: clear screen
|
||||
019.570 000.036 000.036: require('vim.keymap')
|
||||
021.111 001.135 001.135: require('vim.termcap')
|
||||
021.311 000.170 000.170: require('vim.text')
|
||||
034.937 015.646 014.306: require('vim._defaults')
|
||||
034.944 000.011: init default mappings & autocommands
|
||||
035.445 000.078 000.078: sourcing D:\Scoop\apps\neovim\current\share\nvim\runtime\ftplugin.vim
|
||||
035.952 000.053 000.053: sourcing D:\Scoop\apps\neovim\current\share\nvim\runtime\indent.vim
|
||||
036.025 000.949: sourcing vimrc file(s)
|
||||
036.672 000.267 000.267: sourcing D:\Scoop\apps\neovim\current\share\nvim\runtime\filetype.lua
|
||||
037.926 000.094 000.094: sourcing D:\Scoop\apps\neovim\current\share\nvim\runtime\syntax\synload.vim
|
||||
039.693 002.300 002.205: sourcing D:\Scoop\apps\neovim\current\share/nvim/runtime/syntax/syntax.vim
|
||||
045.907 000.297 000.297: sourcing D:\Scoop\apps\neovim\current\share\nvim\runtime\plugin\gzip.vim
|
||||
056.088 000.423 000.423: sourcing D:\Scoop\apps\neovim\current\share\nvim\runtime\pack\dist\opt\matchit\plugin\matchit.vim
|
||||
056.232 010.027 009.603: sourcing D:\Scoop\apps\neovim\current\share\nvim\runtime\plugin\matchit.vim
|
||||
056.704 000.181 000.181: sourcing D:\Scoop\apps\neovim\current\share\nvim\runtime\plugin\matchparen.vim
|
||||
057.452 000.444 000.444: sourcing D:\Scoop\apps\neovim\current\share\nvim\runtime\plugin\netrwPlugin.vim
|
||||
057.867 000.074 000.074: sourcing D:\Scoop\apps\neovim\current\share\nvim\runtime\plugin\rplugin.vim
|
||||
058.277 000.097 000.097: sourcing D:\Scoop\apps\neovim\current\share\nvim\runtime\plugin\shada.vim
|
||||
058.631 000.045 000.045: sourcing D:\Scoop\apps\neovim\current\share\nvim\runtime\plugin\spellfile.vim
|
||||
059.074 000.139 000.139: sourcing D:\Scoop\apps\neovim\current\share\nvim\runtime\plugin\tarPlugin.vim
|
||||
059.424 000.043 000.043: sourcing D:\Scoop\apps\neovim\current\share\nvim\runtime\plugin\tutor.vim
|
||||
059.890 000.161 000.161: sourcing D:\Scoop\apps\neovim\current\share\nvim\runtime\plugin\zipPlugin.vim
|
||||
060.321 000.130 000.130: sourcing D:\Scoop\apps\neovim\current\share\nvim\runtime\plugin\editorconfig.lua
|
||||
060.792 000.155 000.155: sourcing D:\Scoop\apps\neovim\current\share\nvim\runtime\plugin\man.lua
|
||||
061.218 000.132 000.132: sourcing D:\Scoop\apps\neovim\current\share\nvim\runtime\plugin\osc52.lua
|
||||
061.620 000.108 000.108: sourcing D:\Scoop\apps\neovim\current\share\nvim\runtime\plugin\tohtml.lua
|
||||
061.717 011.093: loading rtp plugins
|
||||
062.019 000.302: loading packages
|
||||
062.828 000.809: loading after plugins
|
||||
062.858 000.029: inits 3
|
||||
062.861 000.003: reading ShaDa
|
||||
063.105 000.245: opening buffers
|
||||
063.240 000.135: BufEnter autocommands
|
||||
063.243 000.003: editing files in windows
|
||||
063.480 000.237: VimEnter autocommands
|
||||
063.485 000.005: UIEnter autocommands
|
||||
064.508 001.023: before starting main loop
|
||||
065.178 000.670: first screen update
|
||||
065.181 000.004: --- NVIM STARTED ---
|
||||
|
520
lua/spacevim/api/color.lua
Normal file
520
lua/spacevim/api/color.lua
Normal file
@ -0,0 +1,520 @@
|
||||
--=============================================================================
|
||||
-- color.lua ---
|
||||
-- Copyright (c) 2019-2024 Wang Shidong & Contributors
|
||||
-- Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
-- URL: https://spacevim.org
|
||||
-- License: GPLv3
|
||||
--=============================================================================
|
||||
|
||||
local color = {}
|
||||
|
||||
-- rgb <-> hsl - hwb
|
||||
-- rgb <-> cmyk
|
||||
-- rgb <-> hsv
|
||||
-- rgb <-> hex
|
||||
-- rgb <-> linear <-> xyz <-> lab <-> lch
|
||||
|
||||
-- 参考: https://blog.csdn.net/Sunshine_in_Moon/article/details/45131285
|
||||
|
||||
color.rgb2hsl = function(r, g, b)
|
||||
local max = math.max(r, g, b)
|
||||
local min = math.min(r, g, b)
|
||||
local h, s, l
|
||||
if max == min then
|
||||
h = 0
|
||||
elseif max == r and g >= b then
|
||||
h = 60 * (g - b) / (max - min) + 0
|
||||
elseif max == r and g < b then
|
||||
h = 60 * (g - b) / (max - min) + 360
|
||||
elseif max == g then
|
||||
h = 60 * (b - r) / (max - min) + 120
|
||||
elseif max == b then
|
||||
h = 60 * (r - g) / (max - min) + 240
|
||||
end
|
||||
|
||||
l = 1 / 2 * (max + min)
|
||||
|
||||
if l == 0 or max == min then
|
||||
s = 0
|
||||
elseif l > 0 and l <= 0.5 then
|
||||
s = (max - min) / (2 * l)
|
||||
elseif l > 0.5 then
|
||||
s = (max - min) / (2 - 2 * l)
|
||||
end
|
||||
|
||||
return h, s, l
|
||||
end
|
||||
|
||||
-- https://stackoverflow.com/questions/68317097/how-to-properly-convert-hsl-colors-to-rgb-colors-in-lua
|
||||
|
||||
color.hsl2rgb = function(h, s, l)
|
||||
h = h / 360
|
||||
|
||||
local r, g, b
|
||||
|
||||
if s == 0 then
|
||||
r, g, b = l, l, l
|
||||
else
|
||||
local function hue2rgb(p, q, t)
|
||||
if t < 0 then
|
||||
t = t + 1
|
||||
end
|
||||
if t > 1 then
|
||||
t = t - 1
|
||||
end
|
||||
if t < 1 / 6 then
|
||||
return p + (q - p) * 6 * t
|
||||
end
|
||||
if t < 1 / 2 then
|
||||
return q
|
||||
end
|
||||
if t < 2 / 3 then
|
||||
return p + (q - p) * (2 / 3 - t) * 6
|
||||
end
|
||||
return p
|
||||
end
|
||||
|
||||
local q = l < 0.5 and l * (1 + s) or l + s - l * s
|
||||
local p = 2 * l - q
|
||||
r = hue2rgb(p, q, h + 1 / 3)
|
||||
g = hue2rgb(p, q, h)
|
||||
b = hue2rgb(p, q, h - 1 / 3)
|
||||
end
|
||||
|
||||
return r, g, b
|
||||
end
|
||||
|
||||
-- https://www.rapidtables.com/convert/color/rgb-to-cmyk.html
|
||||
|
||||
color.rgb2cmyk = function(r, g, b)
|
||||
local c, m, y, k
|
||||
k = 1 - math.max(r, g, b)
|
||||
if k ~= 1 then
|
||||
c = (1 - r - k) / (1 - k)
|
||||
m = (1 - g - k) / (1 - k)
|
||||
y = (1 - b - k) / (1 - k)
|
||||
else
|
||||
c, m, y = 0, 0, 0
|
||||
end
|
||||
return c, m, y, k
|
||||
end
|
||||
|
||||
color.cmyk2rgb = function(c, m, y, k)
|
||||
local r, g, b
|
||||
r = (1 - c) * (1 - k)
|
||||
g = (1 - m) * (1 - k)
|
||||
b = (1 - y) * (1 - k)
|
||||
return r, g, b
|
||||
end
|
||||
|
||||
-- https://www.rapidtables.com/convert/color/rgb-to-hsv.html
|
||||
|
||||
color.rgb2hsv = function(r, g, b)
|
||||
local cmax = math.max(r, g, b)
|
||||
local cmin = math.min(r, g, b)
|
||||
local d = cmax - cmin
|
||||
|
||||
local h, s, v
|
||||
|
||||
if d == 0 then
|
||||
h = 0
|
||||
elseif cmax == r then
|
||||
h = 60 * (((g - b) / d) % 6)
|
||||
elseif cmax == g then
|
||||
h = 60 * (((b - r) / d) + 2)
|
||||
elseif cmax == b then
|
||||
h = 60 * (((r - g) / d) + 4)
|
||||
end
|
||||
|
||||
if cmax == 0 then
|
||||
s = 0
|
||||
else
|
||||
s = d / cmax
|
||||
end
|
||||
|
||||
v = cmax
|
||||
|
||||
return h, s, v
|
||||
end
|
||||
|
||||
-- https://www.rapidtables.com/convert/color/hsv-to-rgb.html
|
||||
color.hsv2rgb = function(h, s, v)
|
||||
local c = v * s
|
||||
local x = c * (1 - math.abs((h / 60) % 2 - 1))
|
||||
local m = v - c
|
||||
local r, g, b
|
||||
|
||||
if h >= 0 and h < 60 then
|
||||
r, g, b = c, x, 0
|
||||
elseif h >= 60 and h < 120 then
|
||||
r, g, b = x, c, 0
|
||||
elseif h >= 120 and h < 180 then
|
||||
r, g, b = 0, c, x
|
||||
elseif h >= 180 and h < 240 then
|
||||
r, g, b = 0, x, c
|
||||
elseif h >= 240 and h < 300 then
|
||||
r, g, b = x, 0, c
|
||||
elseif h >= 300 and h < 360 then
|
||||
r, g, b = c, 0, x
|
||||
end
|
||||
r, g, b = (r + m), (g + m), (b + m)
|
||||
return r, g, b
|
||||
end
|
||||
color.hsv2hsl = function(h, s, v)
|
||||
return color.rgb2hsl(color.hsv2rgb(h, s, v))
|
||||
end
|
||||
color.hsl2hsv = function(h, s, l)
|
||||
return color.rgb2hsv(color.hsl2rgb(h, s, l))
|
||||
end
|
||||
color.hsl2cmyk = function(h, s, l)
|
||||
return color.rgb2cmyk(color.hsl2rgb(h, s, l))
|
||||
end
|
||||
color.hsv2cmyk = function(h, s, v)
|
||||
return color.rgb2cmyk(color.hsv2rgb(h, s, v))
|
||||
end
|
||||
color.cmyk2hsv = function(c, m, y, k)
|
||||
return color.rgb2hsv(color.cmyk2rgb(c, m, y, k))
|
||||
end
|
||||
|
||||
color.cmyk2hsl = function(c, m, y, k)
|
||||
return color.rgb2hsl(color.cmyk2rgb(c, m, y, k))
|
||||
end
|
||||
|
||||
color.hwb2rgb = function(h, w, b)
|
||||
if w + b >= 1 then
|
||||
local grey = w / (w + b)
|
||||
return grey, grey, grey
|
||||
end
|
||||
local R, G, B = color.hsl2rgb(h, 1, 0.5)
|
||||
local function f(c)
|
||||
c = c * (1 - w - b) + w
|
||||
if c > 1 then
|
||||
return 1
|
||||
elseif c <= 0 then
|
||||
return 0
|
||||
else
|
||||
return c
|
||||
end
|
||||
end
|
||||
return f(R), f(G), f(B)
|
||||
end
|
||||
|
||||
color.rgb2hwb = function(r, g, b)
|
||||
local h = color.rgb2hsl(r, g, b)
|
||||
local w = math.min(r, g, b)
|
||||
b = 1 - math.max(r, g, b)
|
||||
return h, w, b
|
||||
end
|
||||
|
||||
color.hsv2hwb = function(h, s, v)
|
||||
return color.rgb2hwb(color.hsv2rgb(h, s, v))
|
||||
end
|
||||
|
||||
color.hsl2hwb = function(h, s, l)
|
||||
return color.rgb2hwb(color.hsl2rgb(h, s, l))
|
||||
end
|
||||
|
||||
color.cmyk2hwb = function(c, m, y, k)
|
||||
return color.rgb2hwb(color.cmyk2rgb(c, m, y, k))
|
||||
end
|
||||
|
||||
color.hwb2hsl = function(h, w, b)
|
||||
return color.rgb2hsl(color.hwb2rgb(h, w, b))
|
||||
end
|
||||
|
||||
color.hwb2hsv = function(h, w, b)
|
||||
return color.rgb2hsv(color.hwb2rgb(h, w, b))
|
||||
end
|
||||
|
||||
color.hwb2cmyk = function(h, w, b)
|
||||
return color.rgb2cmyk(color.hwb2rgb(h, w, b))
|
||||
end
|
||||
|
||||
local function decimalToHex(decimal)
|
||||
local hex = ''
|
||||
local hexChars = '0123456789ABCDEF'
|
||||
while decimal > 0 do
|
||||
local mod = decimal % 16
|
||||
hex = string.sub(hexChars, mod + 1, mod + 1) .. hex
|
||||
decimal = math.floor(decimal / 16)
|
||||
end
|
||||
if hex == '' then
|
||||
return '00'
|
||||
elseif #hex == 1 then
|
||||
return '0' .. hex
|
||||
else
|
||||
return hex
|
||||
end
|
||||
end
|
||||
color.rgb2hex = function(r, g, b)
|
||||
r = decimalToHex(math.floor(r * 255 + 0.5))
|
||||
g = decimalToHex(math.floor(g * 255 + 0.5))
|
||||
b = decimalToHex(math.floor(b * 255 + 0.5))
|
||||
return '#' .. r .. g .. b
|
||||
end
|
||||
color.hex2rgb = function(hex)
|
||||
-- make sure hex is '#[0123456789ABCDEF]\+'
|
||||
local r, g, b
|
||||
r = tonumber(string.sub(hex, 2, 3), 16)
|
||||
g = tonumber(string.sub(hex, 4, 5), 16)
|
||||
b = tonumber(string.sub(hex, 6, 7), 16)
|
||||
return r / 255, g / 255, b / 255
|
||||
end
|
||||
color.hsv2hex = function(h, s, v)
|
||||
return color.rgb2hex(color.hsv2rgb(h, s, v))
|
||||
end
|
||||
color.hsl2hex = function(h, s, l)
|
||||
return color.rgb2hex(color.hsl2rgb(h, s, l))
|
||||
end
|
||||
color.cmyk2hex = function(c, y, m, k)
|
||||
return color.rgb2hex(color.cmyk2rgb(c, y, m, k))
|
||||
end
|
||||
|
||||
color.hwb2hex = function(h, w, b)
|
||||
return color.rgb2hex(color.hwb2rgb(h, w, b))
|
||||
end
|
||||
|
||||
color.rgb2linear = function(r, g, b)
|
||||
return unpack(vim.tbl_map(function(x)
|
||||
if x <= 0.04045 then
|
||||
return x / 12.92
|
||||
end
|
||||
return ((x + 0.055) / 1.055) ^ 2.4
|
||||
end, { r, g, b }))
|
||||
end
|
||||
|
||||
color.linear2rgb = function(r, g, b)
|
||||
return unpack(vim.tbl_map(function(x)
|
||||
if x <= 0.0031308 then
|
||||
local a = 12.92 * x
|
||||
if a > 1 then
|
||||
return 1
|
||||
elseif a < 0 then
|
||||
return 0
|
||||
else
|
||||
return a
|
||||
end
|
||||
else
|
||||
local a = 1.055 * x ^ (1 / 2.4) - 0.055
|
||||
if a > 1 then
|
||||
return 1
|
||||
elseif a < 0 then
|
||||
return 0
|
||||
else
|
||||
return a
|
||||
end
|
||||
end
|
||||
end, { r, g, b }))
|
||||
end
|
||||
|
||||
color.linear2hsl = function(r, g, b)
|
||||
return color.rgb2hsl(color.linear2rgb(r, g, b))
|
||||
end
|
||||
|
||||
color.linear2hwb = function(r, g, b)
|
||||
return color.rgb2hwb(color.linear2rgb(r, g, b))
|
||||
end
|
||||
color.linear2cmyk = function(r, g, b)
|
||||
return color.rgb2cmyk(color.linear2rgb(r, g, b))
|
||||
end
|
||||
color.linear2hsv = function(r, g, b)
|
||||
return color.rgb2hsv(color.linear2rgb(r, g, b))
|
||||
end
|
||||
color.linear2hex = function(r, g, b)
|
||||
return color.rgb2hex(color.linear2rgb(r, g, b))
|
||||
end
|
||||
color.linear2lab = function(r, g, b)
|
||||
return color.xyz2lab(color.linear2xyz(r, g, b))
|
||||
end
|
||||
|
||||
color.hsl2linear = function(h, s, l)
|
||||
return color.rgb2linear(color.hsl2rgb(h, s, l))
|
||||
end
|
||||
|
||||
color.hwb2linear = function(h, w, b)
|
||||
return color.rgb2linear(color.hwb2rgb(h, w, b))
|
||||
end
|
||||
|
||||
color.cmyk2linear = function(c, m, y, k)
|
||||
return color.rgb2linear(color.cmyk2rgb(c, m, y, k))
|
||||
end
|
||||
|
||||
color.hsv2linear = function(h, s, v)
|
||||
return color.rgb2linear(color.hsv2rgb(h, s, v))
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- XYZ color space
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local linear2xyz = {
|
||||
{ 0.41239079926595, 0.35758433938387, 0.18048078840183 },
|
||||
{ 0.21263900587151, 0.71516867876775, 0.072192315360733 },
|
||||
{ 0.019330818715591, 0.11919477979462, 0.95053215224966 },
|
||||
}
|
||||
local xyz2linear = {
|
||||
{ 3.240969941904521, -1.537383177570093, -0.498610760293 },
|
||||
{ -0.96924363628087, 1.87596750150772, 0.041555057407175 },
|
||||
{ 0.055630079696993, -0.20397695888897, 1.056971514242878 },
|
||||
}
|
||||
|
||||
local function dot(a, b)
|
||||
assert(#a == #b)
|
||||
local result = 0
|
||||
for i = 1, #a do
|
||||
result = result + a[i] * b[i]
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
local function product(m, v)
|
||||
local row = #m
|
||||
local result = {}
|
||||
for i = 1, row do
|
||||
result[i] = dot(m[i], v)
|
||||
end
|
||||
return unpack(result)
|
||||
end
|
||||
|
||||
function color.linear2xyz(r, g, b)
|
||||
return product(linear2xyz, { r, g, b })
|
||||
end
|
||||
|
||||
function color.xyz2linear(x, y, z)
|
||||
return product(xyz2linear, { x, y, z })
|
||||
end
|
||||
|
||||
function color.rgb2xyz(r, g, b)
|
||||
return color.linear2xyz(color.rgb2linear(r, g, b))
|
||||
end
|
||||
function color.xyz2rgb(x, y, z)
|
||||
return color.linear2rgb(color.xyz2linear(x, y, z))
|
||||
end
|
||||
function color.xyz2hex(x, y, z)
|
||||
return color.rgb2hex(color.xyz2rgb(x, y, z))
|
||||
end
|
||||
function color.xyz2hsv(x, y, z)
|
||||
return color.rgb2hsv(color.xyz2rgb(x, y, z))
|
||||
end
|
||||
function color.hsv2xyz(h, s, v)
|
||||
return color.rgb2xyz(color.hsv2rgb(h, s, v))
|
||||
end
|
||||
function color.xyz2hsl(x, y, z)
|
||||
return color.rgb2hsl(color.xyz2rgb(x, y, z))
|
||||
end
|
||||
function color.hsl2xyz(h, s, l)
|
||||
return color.rgb2xyz(color.hsl2rgb(h, s, l))
|
||||
end
|
||||
function color.xyz2cmyk(x, y, z)
|
||||
return color.rgb2cmyk(color.xyz2rgb(x, y, z))
|
||||
end
|
||||
function color.cmyk2xyz(c, m, y, k)
|
||||
return color.rgb2xyz(color.cmyk2rgb(c, m, y, k))
|
||||
end
|
||||
function color.xyz2hwb(x, y, z)
|
||||
return color.rgb2hwb(color.xyz2rgb(x, y, z))
|
||||
end
|
||||
function color.hwb2xyz(h, w, b)
|
||||
return color.rgb2xyz(color.hwb2rgb(h, w, b))
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Lab color space
|
||||
--------------------------------------------------------------------------------
|
||||
-- What Does CIE L*a*b* Stand for?
|
||||
--
|
||||
-- The CIE in CIELAB is the abbreviation for the International Commission on
|
||||
-- Illumination’s French name, Commission Internationale de l´Eclairage.
|
||||
-- The letters L*, a* and b* represent each of the three values the CIELAB color
|
||||
-- space uses to measure objective color and calculate color differences.
|
||||
-- L* represents lightness from black to white on a scale of zero to 100,
|
||||
-- while a* and b* represent chromaticity with no specific numeric limits.
|
||||
-- Negative a* corresponds with green, positive a* corresponds with red,
|
||||
-- negative b* corresponds with blue and positive b* corresponds with yellow.
|
||||
--
|
||||
-- https://www.hunterlab.com/blog/what-is-cielab-color-space/
|
||||
-- https://zh.wikipedia.org/wiki/CIELAB%E8%89%B2%E5%BD%A9%E7%A9%BA%E9%97%B4
|
||||
-- https://en.wikipedia.org/wiki/CIELAB_color_space
|
||||
-- https://developer.mozilla.org/zh-CN/docs/Web/CSS/color_value/lab
|
||||
|
||||
function color.xyz2lab(x, y, z)
|
||||
local Xn, Yn, Zn = 0.9505, 1, 1.089
|
||||
local function f(t)
|
||||
if t > (6 / 29) ^ 3 then
|
||||
return 116 * t ^ (1 / 3) - 16
|
||||
end
|
||||
return (29 / 3) ^ 3 * t
|
||||
end
|
||||
return f(y / Yn), (500 / 116) * (f(x / Xn) - f(y / Yn)), (200 / 116) * (f(y / Yn) - f(z / Zn))
|
||||
end
|
||||
|
||||
function color.lab2xyz(l, a, b)
|
||||
local Xn, Yn, Zn = 0.9505, 1, 1.089
|
||||
local fy = (l + 16) / 116
|
||||
local fx = fy + (a / 500)
|
||||
local fz = fy - (b / 200)
|
||||
local function t(f)
|
||||
if f > 6 / 29 then
|
||||
return f ^ 3
|
||||
end
|
||||
return (116 * f - 16) * (3 / 29) ^ 3
|
||||
end
|
||||
return t(fx) * Xn, t(fy) * Yn, t(fz) * Zn
|
||||
end
|
||||
|
||||
function color.rgb2lab(r, g, b)
|
||||
return color.xyz2lab(color.linear2xyz(color.rgb2linear(r, g, b)))
|
||||
end
|
||||
|
||||
function color.hsl2lab(h, s, l)
|
||||
return color.rgb2lab(color.hsl2rgb(h, s, l))
|
||||
end
|
||||
function color.cmyk2lab(c, m, y, k)
|
||||
return color.rgb2lab(color.cmyk2rgb(c, m, y, k))
|
||||
end
|
||||
function color.hsv2lab(h, s, v)
|
||||
return color.rgb2lab(color.hsv2rgb(h, s, v))
|
||||
end
|
||||
function color.hwb2lab(h, w, b)
|
||||
return color.rgb2lab(color.hwb2rgb(h, w, b))
|
||||
end
|
||||
|
||||
function color.lab2rgb(l, a, b)
|
||||
return color.linear2rgb(color.xyz2linear(color.lab2xyz(l, a, b)))
|
||||
end
|
||||
|
||||
function color.lab2hex(l, a, b)
|
||||
return color.rgb2hex(color.lab2rgb(l, a, b))
|
||||
end
|
||||
|
||||
function color.lab2hsl(l, a, b)
|
||||
return color.rgb2hsl(color.lab2rgb(l, a, b))
|
||||
end
|
||||
function color.lab2hsv(l, a, b)
|
||||
return color.rgb2hsv(color.lab2rgb(l, a, b))
|
||||
end
|
||||
function color.lab2hwb(l, a, b)
|
||||
return color.rgb2hwb(color.lab2rgb(l, a, b))
|
||||
end
|
||||
function color.lab2cmyk(l, a, b)
|
||||
return color.rgb2cmyk(color.lab2rgb(l, a, b))
|
||||
end
|
||||
function color.lab2linear(l, a, b)
|
||||
return color.xyz2linear(color.lab2xyz(l, a, b))
|
||||
end
|
||||
|
||||
function color.lab2lch(L, a, b)
|
||||
local H = math.atan2(b, a)
|
||||
local C = math.sqrt(a ^ 2 + b ^ 2)
|
||||
H = H / (2 * math.pi) * 360 -- [rad] -> [deg]
|
||||
H = H % 360
|
||||
return L, C, H
|
||||
end
|
||||
|
||||
function color.lch2lab(L, C, H)
|
||||
H = H / 360 * (2 * math.pi) -- [deg] -> [rad]
|
||||
local a = C * math.cos(H)
|
||||
local b = C * math.sin(H)
|
||||
return L, a, b
|
||||
end
|
||||
return color
|
@ -17,21 +17,18 @@ end
|
||||
|
||||
function M.fill(str, length, ...)
|
||||
local v = ''
|
||||
local rightmost
|
||||
if string.len(str) <= length then
|
||||
v = str
|
||||
else
|
||||
local rightmost= 0
|
||||
rightmost= 0
|
||||
while string.len(string.sub(str, 0, rightmost)) < length do
|
||||
rightmost = rightmost + 1
|
||||
end
|
||||
|
||||
end
|
||||
v = string.sub(str, 0, rightmost)
|
||||
local argvs = ...
|
||||
local char = ' '
|
||||
if argvs ~= nil then
|
||||
char = argvs[1] or char
|
||||
end
|
||||
local char = select(1, ...) or ' '
|
||||
return v .. string.rep(char, length - string.len(v))
|
||||
end
|
||||
|
||||
|
40
lua/spacevim/plugin/logevents.lua
Normal file
40
lua/spacevim/plugin/logevents.lua
Normal file
@ -0,0 +1,40 @@
|
||||
--=============================================================================
|
||||
-- logevents.lua --- log events
|
||||
-- Copyright (c) 2019-2024 Wang Shidong & Contributors
|
||||
-- Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
-- URL: https://spacevim.org
|
||||
-- License: GPLv3
|
||||
--=============================================================================
|
||||
|
||||
local M = {}
|
||||
|
||||
local log = require('spacevim.logger').derive('logevent')
|
||||
local notify = require('spacevim.api.notify')
|
||||
|
||||
local enabled = false
|
||||
|
||||
function M.toggle()
|
||||
if not enabled then
|
||||
notify.notify('logevent enabled')
|
||||
local group = vim.api.nvim_create_augroup('logevent', { clear = true })
|
||||
vim.api.nvim_create_autocmd(
|
||||
vim.tbl_filter(function(e)
|
||||
return not vim.endswith(e, 'Cmd') and e ~= 'SafeState'
|
||||
end, vim.fn.getcompletion('', 'event')),
|
||||
{
|
||||
callback = vim.schedule_wrap(function(event)
|
||||
log.debug(event.event .. event.buf)
|
||||
end),
|
||||
group = group,
|
||||
}
|
||||
)
|
||||
|
||||
enabled = true
|
||||
else
|
||||
notify.notify('logevent disabled')
|
||||
vim.api.nvim_create_augroup('logevent', { clear = true })
|
||||
enabled = false
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
@ -568,7 +568,17 @@ local special_statusline = {
|
||||
return simple_name('Gista')
|
||||
end,
|
||||
terminal = function() end, -- todo
|
||||
vimchat = function() end, -- todo
|
||||
vimchat = function()
|
||||
|
||||
return '%#SpaceVim_statusline_ia#' .. winnr(1) .. '%#SpaceVim_statusline_ia_SpaceVim_statusline_b#' .. lsep
|
||||
.. '%#SpaceVim_statusline_b# Chat %#SpaceVim_statusline_b_SpaceVim_statusline_c#' .. lsep
|
||||
.. '%#SpaceVim_statusline_c# '
|
||||
.. '%{chat#windows#status().protocol}' .. ' %#SpaceVim_statusline_c_SpaceVim_statusline_b#' .. lsep
|
||||
.. '%#SpaceVim_statusline_b# '
|
||||
.. '%{chat#windows#status().channel}' .. ' %#SpaceVim_statusline_b_SpaceVim_statusline_c#' .. lsep
|
||||
.. '%#SpaceVim_statusline_c# '
|
||||
.. '%{chat#windows#status().usercount}'
|
||||
end, -- todo
|
||||
calender = function()
|
||||
return simple_name('Calendar')
|
||||
end,
|
||||
|
@ -29,6 +29,7 @@ local right_sep
|
||||
local left_sep
|
||||
|
||||
local highlight = require('spacevim.api.vim.highlight')
|
||||
local VIM = require('spacevim.api.vim')
|
||||
|
||||
local file = require('spacevim.api.file')
|
||||
|
||||
@ -300,17 +301,43 @@ function M.move_to_next()
|
||||
end
|
||||
|
||||
function M.close_current_buffer()
|
||||
if index({ 'defx', 'startify' }, vim.o.filetype) ~= -1 then
|
||||
return
|
||||
end
|
||||
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
|
||||
local idx = index(visiable_bufs, bufnr)
|
||||
|
||||
local f = ''
|
||||
if vim.api.nvim_buf_get_option(bufnr, 'modified') then
|
||||
vim.api.nvim_echo(
|
||||
{ { 'save changes to "' .. vim.fn.bufname(bufnr) .. '"? Yes/No/Cancel', 'WarningMsg' } },
|
||||
false,
|
||||
{}
|
||||
)
|
||||
local rs = VIM.getchar()
|
||||
vim.cmd.redraw()
|
||||
if rs == 'y' then
|
||||
vim.cmd.write()
|
||||
elseif rs == 'n' then
|
||||
f = '!'
|
||||
vim.api.nvim_echo({ { 'discarded', 'None' } }, false, {})
|
||||
else
|
||||
vim.api.nvim_echo({ { 'canceled!', 'None' } }, false, {})
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if idx > 0 then
|
||||
vim.cmd('b' .. visiable_bufs[idx])
|
||||
vim.cmd('bd ' .. bufnr)
|
||||
vim.cmd('bd' .. f .. ' ' .. bufnr)
|
||||
elseif idx == 0 and #visiable_bufs > 1 then
|
||||
vim.cmd('b' .. visiable_bufs[1])
|
||||
vim.cmd('bd' .. f .. ' ' .. bufnr)
|
||||
elseif idx == 0 and #visiable_bufs == 1 then
|
||||
vim.cmd('Startify')
|
||||
vim.cmd('bd' .. f .. ' ' .. bufnr)
|
||||
end
|
||||
end
|
||||
|
||||
@ -321,14 +348,12 @@ function M.enable()
|
||||
right_sep = seps[1]
|
||||
left_sep = seps[2]
|
||||
for bufnr = 1, vim.fn.bufnr('$') do
|
||||
if
|
||||
vim.api.nvim_buf_is_valid(bufnr) and vim.api.nvim_buf_get_option(bufnr, 'buflisted')
|
||||
then
|
||||
table.insert(visiable_bufs, bufnr)
|
||||
end
|
||||
if vim.api.nvim_buf_is_valid(bufnr) and vim.api.nvim_buf_get_option(bufnr, 'buflisted') then
|
||||
table.insert(visiable_bufs, bufnr)
|
||||
end
|
||||
end
|
||||
local tabline_augroup = vim.api.nvim_create_augroup('spacevim_tabline', { clear = true })
|
||||
vim.api.nvim_create_autocmd({ 'BufNewFile', 'BufReadPost', 'BufAdd' }, {
|
||||
vim.api.nvim_create_autocmd({ 'BufAdd' }, {
|
||||
callback = vim.schedule_wrap(function(event)
|
||||
if
|
||||
vim.api.nvim_buf_is_valid(event.buf)
|
||||
@ -336,7 +361,12 @@ function M.enable()
|
||||
and index(visiable_bufs, event.buf) == -1
|
||||
and index(left_hide_bufs, event.buf) == -1
|
||||
then
|
||||
table.insert(right_hide_bufs, event.buf)
|
||||
if event.buf == vim.api.nvim_get_current_buf() then
|
||||
table.insert(visiable_bufs, event.buf)
|
||||
else
|
||||
table.insert(right_hide_bufs, event.buf)
|
||||
end
|
||||
vim.cmd('redrawtabline')
|
||||
end
|
||||
end),
|
||||
group = tabline_augroup,
|
||||
|
Loading…
x
Reference in New Issue
Block a user