support for conditional parts. resolves #238.
This commit is contained in:
parent
4c6aa4401b
commit
55f524de77
@ -26,6 +26,10 @@ function! airline#parts#define_minwidth(key, width)
|
|||||||
call airline#parts#define(a:key, { 'minwidth': a:width })
|
call airline#parts#define(a:key, { 'minwidth': a:width })
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! airline#parts#define_condition(key, predicate)
|
||||||
|
call airline#parts#define(a:key, { 'condition': a:predicate })
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! airline#parts#define_empty(keys)
|
function! airline#parts#define_empty(keys)
|
||||||
for key in a:keys
|
for key in a:keys
|
||||||
call airline#parts#define_raw(key, '')
|
call airline#parts#define_raw(key, '')
|
||||||
|
@ -36,12 +36,19 @@ function! s:create(parts, append)
|
|||||||
let minwidth = get(part, 'minwidth', 0)
|
let minwidth = get(part, 'minwidth', 0)
|
||||||
|
|
||||||
if a:append > 0 && idx != 0
|
if a:append > 0 && idx != 0
|
||||||
let val .= printf('%%{airline#util#append(%s,%s)}', func, minwidth)
|
let partval = printf('%%{airline#util#append(%s,%s)}', func, minwidth)
|
||||||
elseif a:append < 0 && idx != len(a:parts) - 1
|
elseif a:append < 0 && idx != len(a:parts) - 1
|
||||||
let val .= printf('%%{airline#util#prepend(%s,%s)}', func, minwidth)
|
let partval = printf('%%{airline#util#prepend(%s,%s)}', func, minwidth)
|
||||||
else
|
else
|
||||||
let val .= printf('%%{airline#util#wrap(%s,%s)}', func, minwidth)
|
let partval = printf('%%{airline#util#wrap(%s,%s)}', func, minwidth)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if exists('part.condition')
|
||||||
|
let partval = substitute(partval, '{', '{'.(part.condition).' ? ', '')
|
||||||
|
let partval = substitute(partval, '}', ' : ""}', '')
|
||||||
|
endif
|
||||||
|
|
||||||
|
let val .= partval
|
||||||
let _ .= val
|
let _ .= val
|
||||||
endfor
|
endfor
|
||||||
return _
|
return _
|
||||||
|
@ -370,6 +370,9 @@ Here is how you would define a part that is visible only if the window width
|
|||||||
greater than a minimum width. >
|
greater than a minimum width. >
|
||||||
call airline#parts#define_minwidth('foo', 50)
|
call airline#parts#define_minwidth('foo', 50)
|
||||||
<
|
<
|
||||||
|
Parts can be configured to be visible conditionally. >
|
||||||
|
call airline#parts#define_condition('foo', 'getcwd() =~ "work_dir"')
|
||||||
|
<
|
||||||
Note: Part definitions are combinative; e.g. the two examples above modify the
|
Note: Part definitions are combinative; e.g. the two examples above modify the
|
||||||
same `foo` part.
|
same `foo` part.
|
||||||
|
|
||||||
|
@ -25,5 +25,10 @@ describe 'parts'
|
|||||||
call airline#parts#define_minwidth('mw', 123)
|
call airline#parts#define_minwidth('mw', 123)
|
||||||
Expect airline#parts#get('mw').minwidth == 123
|
Expect airline#parts#get('mw').minwidth == 123
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'can define a condition'
|
||||||
|
call airline#parts#define_condition('part', '1')
|
||||||
|
Expect airline#parts#get('part').condition == '1'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -55,5 +55,12 @@ describe 'section'
|
|||||||
let s = airline#section#create_right(['%t', 'asdf', '%{getcwd()}'])
|
let s = airline#section#create_right(['%t', 'asdf', '%{getcwd()}'])
|
||||||
Expect s == '%t < asdf < %{getcwd()}'
|
Expect s == '%t < asdf < %{getcwd()}'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should empty out parts that do not pass their condition'
|
||||||
|
call airline#parts#define_text('conditional', 'conditional')
|
||||||
|
call airline#parts#define_condition('conditional', '0')
|
||||||
|
let s = airline#section#create(['conditional'])
|
||||||
|
Expect s == '%{0 ? airline#util#wrap("conditional",0) : ""}'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user