Skip to content

Commit

Permalink
Merge pull request vim-airline#2605 from igbanam/theme/vim9-variable-…
Browse files Browse the repository at this point in the history
…arguments

Bring Vim9 Variable Arguments to airline/themes
  • Loading branch information
chrisbra committed Dec 7, 2022
2 parents 25d53a8 + 2ae1475 commit 5f5e00f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
3 changes: 1 addition & 2 deletions autoload/airline/highlighter.vim
Expand Up @@ -430,12 +430,11 @@ else
return res
enddef

def airline#highlighter#get_highlight2(fg: list<string>, bg: list<string>, rest1: string = '', rest2: string = '', rest3: string = ''): list<string>
def airline#highlighter#get_highlight2(fg: list<string>, bg: list<string>, ...rest: list<string>): list<string>
var guifg = s:get_syn(fg[0], fg[1], 'gui')
var guibg = s:get_syn(bg[0], bg[1], 'gui')
var ctermfg = s:get_syn(fg[0], fg[1], 'cterm')
var ctermbg = s:get_syn(bg[0], bg[1], 'cterm')
var rest = [ rest1, rest2, rest3 ]
return s:get_array(guifg, guibg, ctermfg, ctermbg, filter(rest, (_, v) => !empty(v)))
enddef

Expand Down
32 changes: 20 additions & 12 deletions autoload/airline/themes.vim
Expand Up @@ -83,33 +83,41 @@ if !exists(":def") || !airline#util#has_vim9_script()
finish
else
" New Vim9 Script Implementation
def airline#themes#generate_color_map(sect1: list<any>, sect2: list<any>, sect3: list<any>): dict<any>
# Only allows for 3 arguments currently, because Vim9 Script does not allow for a:000

def airline#themes#generate_color_map(sect1: list<any>, sect2: list<any>, sect3: list<any>, ...rest: list<any>): dict<any>
# all sections should be string
map(sect2, (_, v) => type(v) != type('') ? string(v) : v)
for section in [sect1, sect2, sect3] + rest
map(section, (_, v) => type(v) != type('') ? string(v) : v)
endfor

var palette = {
'airline_a': [ sect1[0], sect1[1], sect1[2], sect1[3], get(sect1, 4, '') ],
'airline_b': [ sect2[0], sect2[1], sect2[2], sect2[3], get(sect2, 4, '') ],
'airline_c': [ sect3[0], sect3[1], sect3[2], sect3[3], get(sect3, 4, '') ],
}

extend(palette, {
'airline_x': [ sect3[0], sect3[1], sect3[2], sect3[3], '' ],
'airline_y': [ sect2[0], sect2[1], sect2[2], sect2[3], '' ],
'airline_z': [ sect1[0], sect1[1], sect1[2], sect1[3], '' ],
if rest->len() > 0
extend(palette, {
'airline_x': [ rest[0][0], rest[0][1], rest[0][2], rest[0][3], get(rest[0], 4, '' ) ],
'airline_y': [ rest[1][0], rest[1][1], rest[1][2], rest[1][3], get(rest[1], 4, '' ) ],
'airline_z': [ rest[2][0], rest[2][1], rest[2][2], rest[2][3], get(rest[2], 4, '' ) ],
})
else
extend(palette, {
'airline_x': [ sect3[0], sect3[1], sect3[2], sect3[3], '' ],
'airline_y': [ sect2[0], sect2[1], sect2[2], sect2[3], '' ],
'airline_z': [ sect1[0], sect1[1], sect1[2], sect1[3], '' ],
})
endif

return palette
enddef

def airline#themes#get_highlight(group: string): list<string>
return call('airline#highlighter#get_highlight', [group])
def airline#themes#get_highlight(group: string, ...modifiers: list<string>): list<string>
return call('airline#highlighter#get_highlight', [group, modifiers])
enddef

def airline#themes#get_highlight2(fg: list<string>, bg: list<string>): list<string>
return call('airline#highlighter#get_highlight2', [fg, bg])
def airline#themes#get_highlight2(fg: list<string>, bg: list<string>, ...modifiers: list<string>): list<string>
return call('airline#highlighter#get_highlight2', [fg, bg] + modifiers)
enddef

def airline#themes#patch(palette: dict<any>): void
Expand Down

0 comments on commit 5f5e00f

Please sign in to comment.