Skip to content

Commit

Permalink
Add a callback to provide external statusline sizes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vimpostor committed Feb 18, 2024
1 parent 7d1fd62 commit c414612
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
5 changes: 4 additions & 1 deletion autoload/tpipeline.vim
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ func tpipeline#initialize()
if s:is_nvim
let g:tpipeline_fillchar = ""

if !exists('g:tpipeline_size')
if exists('#User#TpipelineSize')
call tpipeline#util#set_custom_size()
au VimResized * call tpipeline#util#set_custom_size()
elseif !exists('g:tpipeline_size')
call tpipeline#util#set_size()
au VimResized * call tpipeline#util#set_size()
endif
Expand Down
6 changes: 6 additions & 0 deletions autoload/tpipeline/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ func tpipeline#util#set_size()
let g:tpipeline_size = str2nr(systemlist("sh -c 'echo \"\"; tmux display-message -p \"#{window_width}\"'")[-1])
endfunc

func tpipeline#util#set_custom_size()
if exists('#User#TpipelineSize')
doautocmd User TpipelineSize
endif
endfunc

func tpipeline#util#check_gui()
if (v:event['chan'] && !has('nvim-0.9')) || has('gui_running')
call tpipeline#state#restore()
Expand Down
4 changes: 4 additions & 0 deletions doc/tpipeline-external.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ statusline can be embedded in arbitrary external programs. The
|g:tpipeline_refreshcmd| option already allows running arbitrary commands to
trigger the update of an external statusline.

The |g:tpipeline_size| option allows to configure the size of the rendered
statusline, which usually should be set to the numerical size of the external
statusline, i.e. the number of characters or columns that fit into it.

Depending on the external program, some integration needs to be done on that
side as well. There exists full documentation for some external programs in
|tpipeline-external-examples|.
Expand Down
20 changes: 20 additions & 0 deletions doc/tpipeline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Introduction |tpipeline-introduction|
Tmux Integration |tpipeline-tmux|
Configuration |tpipeline-configure|
Api |tpipeline-api|
Autocommands |tpipeline-autocommands|

==============================================================================
INTRODUCTION *tpipeline-introduction*
Expand Down Expand Up @@ -165,6 +166,14 @@ CONFIGURATION *tpipeline-configure*
set -g pane-border-format '#{pane_title}'
<

g:tpipeline_size *g:tpipeline_size*
By default the statusline size is calculated automatically to
span the entire tmux window size. With this option you can
overwrite a custom statusline size to be used. If the size is
not constant and should be recalculated on every statusline
evaluation, then the |User_TpipelineSize| autocommand can be
used.

------------------------------------------------------------------------------
API *tpipeline-api*

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

------------------------------------------------------------------------------
AUTOCOMMANDS *tpipeline-autocommands*

A few |User| |autocommands| are provided to allow extending this
plugin's functionality. Example usage:
>
autocmd User TpipelineSize let g:tpipeline_size = &co
<
*User_TpipelineSize*
TpipelineSize When calculating a custom statusline size. See |g:tpipeline_size|.

==============================================================================
vim:tw=78:sw=4:ts=8:ft=help:norl:noet:

0 comments on commit c414612

Please sign in to comment.