mirror of
https://github.com/vim-airline/vim-airline.git
synced 2025-07-27 07:54:44 +02:00
Merge pull request #2234 from kmoschcau/master
Improve the term extension and make it consistent
This commit is contained in:
commit
3740312de0
@ -5,51 +5,60 @@ scriptencoding utf-8
|
|||||||
|
|
||||||
call airline#parts#define_function('tmode', 'airline#extensions#term#termmode')
|
call airline#parts#define_function('tmode', 'airline#extensions#term#termmode')
|
||||||
call airline#parts#define('terminal', {'text': get(g:airline_mode_map, 't', 't'), 'accent': 'bold'})
|
call airline#parts#define('terminal', {'text': get(g:airline_mode_map, 't', 't'), 'accent': 'bold'})
|
||||||
|
|
||||||
|
let s:spc = g:airline_symbols.space
|
||||||
|
|
||||||
let s:section_a = airline#section#create_left(['terminal', 'tmode'])
|
let s:section_a = airline#section#create_left(['terminal', 'tmode'])
|
||||||
|
let s:section_z = airline#section#create(['linenr', 'maxlinenr'])
|
||||||
|
|
||||||
function! airline#extensions#term#apply(...)
|
function! airline#extensions#term#apply(...) abort
|
||||||
if &buftype == 'terminal' || bufname('%')[0] == '!'
|
if &buftype ==? 'terminal' || bufname(a:2.bufnr)[0] ==? '!'
|
||||||
let spc = g:airline_symbols.space
|
call a:1.add_section_spaced('airline_a', s:section_a)
|
||||||
|
call a:1.add_section_spaced('airline_b', s:neoterm_id(a:2.bufnr))
|
||||||
call a:1.add_section('airline_a', spc.s:section_a.spc)
|
call a:1.add_section('airline_term', s:spc.s:termname(a:2.bufnr))
|
||||||
call a:1.add_section('airline_b', '')
|
|
||||||
call a:1.add_section('airline_term', spc.s:termname())
|
|
||||||
call a:1.split()
|
call a:1.split()
|
||||||
call a:1.add_section('airline_y', '')
|
call a:1.add_section('airline_y', '')
|
||||||
call a:1.add_section('airline_z', spc.airline#section#create_right(['linenr', 'maxlinenr']))
|
call a:1.add_section_spaced('airline_z', s:section_z)
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! airline#extensions#term#inactive_apply(...)
|
function! airline#extensions#term#inactive_apply(...) abort
|
||||||
if getbufvar(a:2.bufnr, '&buftype') == 'terminal'
|
if getbufvar(a:2.bufnr, '&buftype') ==? 'terminal'
|
||||||
let spc = g:airline_symbols.space
|
call a:1.add_section_spaced('airline_a', s:section_a)
|
||||||
call a:1.add_section('airline_a', spc.'TERMINAL'.spc)
|
call a:1.add_section_spaced('airline_b', s:neoterm_id(a:2.bufnr))
|
||||||
call a:1.add_section('airline_b', spc.'%f')
|
call a:1.add_section('airline_term', s:spc.s:termname(a:2.bufnr))
|
||||||
let neoterm_id = getbufvar(a:2.bufnr, 'neoterm_id')
|
call a:1.split()
|
||||||
if neoterm_id != ''
|
call a:1.add_section('airline_y', '')
|
||||||
call a:1.add_section('airline_c', spc.'neoterm_'.neoterm_id.spc)
|
call a:1.add_section_spaced('airline_z', s:section_z)
|
||||||
endif
|
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! airline#extensions#term#termmode()
|
function! airline#extensions#term#termmode() abort
|
||||||
let mode = airline#parts#mode()[0]
|
let mode = airline#parts#mode()[0]
|
||||||
if mode ==? 'T'
|
if mode ==? 'T' || mode ==? '-'
|
||||||
" don't need to output T, statusline already says "TERMINAL"
|
" We don't need to output T, the statusline already says "TERMINAL".
|
||||||
|
" Also we don't want to output "-" on an inactive statusline.
|
||||||
let mode = ''
|
let mode = ''
|
||||||
endif
|
endif
|
||||||
return mode
|
return mode
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:termname()
|
function! s:termname(bufnr) abort
|
||||||
let bufname = bufname('%')
|
let bufname = bufname(a:bufnr)
|
||||||
if has('nvim')
|
if has('nvim')
|
||||||
return matchstr(bufname, 'term.*:\zs.*')
|
" Get rid of the leading "term", working dir and process ID.
|
||||||
|
" Afterwards, remove the possibly added neoterm ID.
|
||||||
|
return substitute(matchstr(bufname, 'term.*:\zs.*'),
|
||||||
|
\ ';#neoterm-\d\+', '', '')
|
||||||
else
|
else
|
||||||
" get rid of leading '!'
|
if bufname =~? 'neoterm-\d\+'
|
||||||
if bufname[0] is# '!'
|
" Do not return a redundant buffer name, when this is a neoterm terminal.
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
" Get rid of the leading "!".
|
||||||
|
if bufname[0] ==? '!'
|
||||||
return bufname[1:]
|
return bufname[1:]
|
||||||
else
|
else
|
||||||
return bufname
|
return bufname
|
||||||
@ -57,7 +66,15 @@ function! s:termname()
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! airline#extensions#term#init(ext)
|
function! s:neoterm_id(bufnr) abort
|
||||||
|
let id = getbufvar(a:bufnr, 'neoterm_id')
|
||||||
|
if id !=? ''
|
||||||
|
let id = 'neoterm-'.id
|
||||||
|
endif
|
||||||
|
return id
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! airline#extensions#term#init(ext) abort
|
||||||
call a:ext.add_statusline_func('airline#extensions#term#apply')
|
call a:ext.add_statusline_func('airline#extensions#term#apply')
|
||||||
call a:ext.add_inactive_statusline_func('airline#extensions#term#inactive_apply')
|
call a:ext.add_inactive_statusline_func('airline#extensions#term#inactive_apply')
|
||||||
endfunction
|
endfunction
|
||||||
|
Loading…
x
Reference in New Issue
Block a user