Skip to content

Commit bccd426

Browse files
committed
Color: refactor: move .as_rgb_hex() to s:Color
1 parent 880320d commit bccd426

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

autoload/vital/__vital__/Color.vim

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ function! s:Color.as_rgb_str() abort
1212
return printf('rgb(%d,%d,%d)', r, g, b)
1313
endfunction
1414

15+
function! s:Color.as_rgb_hex() abort
16+
let [r, g, b] = self.as_rgb()
17+
let [r, g, b] = map([r, g, b], 'float2nr(round(v:val))')
18+
return '#' . s:_nr2hex(r) . s:_nr2hex(g) . s:_nr2hex(b)
19+
endfunction
20+
1521
function! s:Color.as_hsl_str() abort
1622
let [h, s, l] = self.as_hsl()
1723
let [h, s, l] = map([h, s, l], 'float2nr(round(v:val))')
@@ -30,11 +36,6 @@ endfunction
3036

3137
let s:RGB = deepcopy(s:Color)
3238

33-
function! s:RGB.as_rgb_hex() abort
34-
let [r, g, b] = map([self._r, self._g, self._b], 'float2nr(round(v:val))')
35-
return '#' . s:_nr2hex(r) . s:_nr2hex(g) . s:_nr2hex(b)
36-
endfunction
37-
3839
function! s:RGB.as_rgb() abort
3940
return [self._r, self._g, self._b]
4041
endfunction
@@ -45,12 +46,6 @@ endfunction
4546

4647
let s:HSL = deepcopy(s:Color)
4748

48-
function! s:HSL.as_rgb_hex() abort
49-
let [r, g, b] = s:_hsl2rgb(self._h, self._s, self._l)
50-
let [r, g, b] = map([r, g, b], 'float2nr(round(v:val))')
51-
return '#' . s:_nr2hex(r) . s:_nr2hex(g) . s:_nr2hex(b)
52-
endfunction
53-
5449
function! s:HSL.as_rgb() abort
5550
return s:_hsl2rgb(self._h, self._s, self._l)
5651
endfunction

0 commit comments

Comments
 (0)