Skip to content

Commit c414612

Browse files
committed
Add a callback to provide external statusline sizes
This is necessary if the statusline is not embedded in tmux, but in a different external statusline (e.g. the statusline of the window manager or the kitty statusline). This was one of the missing pieces to allow embedding the statusline properly in arbitrary external statuslines. Fixes #60
1 parent 7d1fd62 commit c414612

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

autoload/tpipeline.vim

+4-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ func tpipeline#initialize()
126126
if s:is_nvim
127127
let g:tpipeline_fillchar = ""
128128

129-
if !exists('g:tpipeline_size')
129+
if exists('#User#TpipelineSize')
130+
call tpipeline#util#set_custom_size()
131+
au VimResized * call tpipeline#util#set_custom_size()
132+
elseif !exists('g:tpipeline_size')
130133
call tpipeline#util#set_size()
131134
au VimResized * call tpipeline#util#set_size()
132135
endif

autoload/tpipeline/util.vim

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ func tpipeline#util#set_size()
1515
let g:tpipeline_size = str2nr(systemlist("sh -c 'echo \"\"; tmux display-message -p \"#{window_width}\"'")[-1])
1616
endfunc
1717

18+
func tpipeline#util#set_custom_size()
19+
if exists('#User#TpipelineSize')
20+
doautocmd User TpipelineSize
21+
endif
22+
endfunc
23+
1824
func tpipeline#util#check_gui()
1925
if (v:event['chan'] && !has('nvim-0.9')) || has('gui_running')
2026
call tpipeline#state#restore()

doc/tpipeline-external.txt

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ statusline can be embedded in arbitrary external programs. The
1313
|g:tpipeline_refreshcmd| option already allows running arbitrary commands to
1414
trigger the update of an external statusline.
1515

16+
The |g:tpipeline_size| option allows to configure the size of the rendered
17+
statusline, which usually should be set to the numerical size of the external
18+
statusline, i.e. the number of characters or columns that fit into it.
19+
1620
Depending on the external program, some integration needs to be done on that
1721
side as well. There exists full documentation for some external programs in
1822
|tpipeline-external-examples|.

doc/tpipeline.txt

+20
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Introduction |tpipeline-introduction|
77
Tmux Integration |tpipeline-tmux|
88
Configuration |tpipeline-configure|
99
Api |tpipeline-api|
10+
Autocommands |tpipeline-autocommands|
1011

1112
==============================================================================
1213
INTRODUCTION *tpipeline-introduction*
@@ -165,6 +166,14 @@ CONFIGURATION *tpipeline-configure*
165166
set -g pane-border-format '#{pane_title}'
166167
<
167168

169+
g:tpipeline_size *g:tpipeline_size*
170+
By default the statusline size is calculated automatically to
171+
span the entire tmux window size. With this option you can
172+
overwrite a custom statusline size to be used. If the size is
173+
not constant and should be recalculated on every statusline
174+
evaluation, then the |User_TpipelineSize| autocommand can be
175+
used.
176+
168177
------------------------------------------------------------------------------
169178
API *tpipeline-api*
170179

@@ -198,5 +207,16 @@ API *tpipeline-api*
198207
Toggles the active state.
199208
See also |tpipeline#state#restore()| and |tpipeline#state#reload()|.
200209

210+
------------------------------------------------------------------------------
211+
AUTOCOMMANDS *tpipeline-autocommands*
212+
213+
A few |User| |autocommands| are provided to allow extending this
214+
plugin's functionality. Example usage:
215+
>
216+
autocmd User TpipelineSize let g:tpipeline_size = &co
217+
<
218+
*User_TpipelineSize*
219+
TpipelineSize When calculating a custom statusline size. See |g:tpipeline_size|.
220+
201221
==============================================================================
202222
vim:tw=78:sw=4:ts=8:ft=help:norl:noet:

0 commit comments

Comments
 (0)