amadeus / vim-convert-color-to

A simple and easy to use plugin to convert color strings to different formats.
75 stars 0 forks source link

Feature request: Add a command to cycle through different color formats #4

Open poetaman opened 3 years ago

poetaman commented 3 years ago

Please add a command to cycle through different formats.

Currently I tried cycling using the command: :call ConvertColorTo(), but it seems to have error for converting back from rgb to hex. And it doesn't cycle other formats anyway.

Here's a mp4:

https://user-images.githubusercontent.com/71736629/117571377-269d9d00-b083-11eb-9697-403d20ba13ea.mp4

amadeus commented 3 years ago

I’m not quite sure what the error you are referring to is? It’s converting back and forth between rgb and hex exactly as it should? The hex it converts to is just shorthand since it detects shorthand is possible and converts to it.

As for command… there’s a simpler command you can use and you can specify the type to convert to:

:ConvertColorTo hsl

and here’s all the options available from that command: B96F2DEF-1D23-450D-9C8B-D06E25F2C2DB

there’s no need for the :call interface you are using.

I don’t think I will add just a function that iterates through each type, I think making commands explicit and immediately understandable is most important

poetaman commented 3 years ago

@amadeus Cool, this is what I coded to iterate through the types, with 1 caveat. I would prefer if transparency is 1, that RGBA get converted to HEX instead of HEXA when type hex is used. This would work as there as they can always cycle back to hexa by explicitly specifying the existing type 'hexa'. This way a user can cycle through all the possible formats. Currently, if a number is converted to hexa/rgba/hsla (with transparency value 1), it cannot be cycled back to rgb/rgbint/hex/hexnum without the 'a' value.

let g:colorFormatPtr=0
let g:vim_convert_color_to_list = ['hex_num', 'rgb_int', 'rgb_float', 'hsl']
function! s:toggleColorFormat()
    if g:colorFormatPtr >= 3
        let g:colorFormatPtr = 0
    else
        let g:colorFormatPtr += 1
    endif
    call ConvertColorTo(g:vim_convert_color_to_list[g:colorFormatPtr])
endfunction

nnoremap <leader>2 :call <SID>toggleColorFormat()<CR>