2021-01-01 20:57:00 +08:00
|
|
|
" MIT License. Copyright (c) 2013-2021 Bailey Ling et al.
|
2017-08-22 21:30:15 +08:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
|
|
|
scriptencoding utf-8
|
|
|
|
|
2019-08-20 20:00:34 +08:00
|
|
|
call airline#parts#define_function('tmode', 'airline#extensions#term#termmode')
|
2019-08-21 04:12:34 +08:00
|
|
|
call airline#parts#define('terminal', {'text': get(g:airline_mode_map, 't', 't'), 'accent': 'bold'})
|
2019-08-20 20:00:34 +08:00
|
|
|
|
2020-09-14 19:44:10 +08:00
|
|
|
let s:spc = g:airline_symbols.space
|
|
|
|
|
|
|
|
let s:section_a = airline#section#create_left(['terminal', 'tmode'])
|
|
|
|
let s:section_z = airline#section#create(['linenr', 'maxlinenr'])
|
2017-08-22 21:30:15 +08:00
|
|
|
|
2020-09-14 19:44:10 +08:00
|
|
|
function! airline#extensions#term#apply(...) abort
|
|
|
|
if &buftype ==? 'terminal' || bufname(a:2.bufnr)[0] ==? '!'
|
|
|
|
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_term', s:spc.s:termname(a:2.bufnr))
|
2017-08-22 21:30:15 +08:00
|
|
|
call a:1.split()
|
|
|
|
call a:1.add_section('airline_y', '')
|
2020-09-14 19:44:10 +08:00
|
|
|
call a:1.add_section_spaced('airline_z', s:section_z)
|
2017-08-22 21:30:15 +08:00
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2020-09-14 19:44:10 +08:00
|
|
|
function! airline#extensions#term#inactive_apply(...) abort
|
|
|
|
if getbufvar(a:2.bufnr, '&buftype') ==? 'terminal'
|
|
|
|
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_term', s:spc.s:termname(a:2.bufnr))
|
|
|
|
call a:1.split()
|
|
|
|
call a:1.add_section('airline_y', '')
|
|
|
|
call a:1.add_section_spaced('airline_z', s:section_z)
|
2018-11-20 23:32:55 +08:00
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2020-09-14 19:44:10 +08:00
|
|
|
function! airline#extensions#term#termmode() abort
|
2019-08-21 04:12:34 +08:00
|
|
|
let mode = airline#parts#mode()[0]
|
2020-09-14 19:44:10 +08:00
|
|
|
if mode ==? 'T' || mode ==? '-'
|
|
|
|
" 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 = ''
|
2019-08-20 20:00:34 +08:00
|
|
|
endif
|
|
|
|
return mode
|
|
|
|
endfunction
|
|
|
|
|
2020-09-14 19:44:10 +08:00
|
|
|
function! s:termname(bufnr) abort
|
|
|
|
let bufname = bufname(a:bufnr)
|
2018-11-20 23:11:34 +08:00
|
|
|
if has('nvim')
|
2020-09-14 19:44:10 +08:00
|
|
|
" 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\+', '', '')
|
2018-11-20 23:11:34 +08:00
|
|
|
else
|
2020-09-14 19:44:10 +08:00
|
|
|
if bufname =~? 'neoterm-\d\+'
|
|
|
|
" Do not return a redundant buffer name, when this is a neoterm terminal.
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
" Get rid of the leading "!".
|
|
|
|
if bufname[0] ==? '!'
|
2019-04-18 21:52:54 +08:00
|
|
|
return bufname[1:]
|
|
|
|
else
|
|
|
|
return bufname
|
|
|
|
endif
|
2018-11-20 23:11:34 +08:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2020-09-14 19:44:10 +08:00
|
|
|
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
|
2017-08-22 21:30:15 +08:00
|
|
|
call a:ext.add_statusline_func('airline#extensions#term#apply')
|
2018-11-20 23:32:55 +08:00
|
|
|
call a:ext.add_inactive_statusline_func('airline#extensions#term#inactive_apply')
|
2017-08-22 21:30:15 +08:00
|
|
|
endfunction
|