voldikss / vim-floaterm

:computer: Terminal manager for (neo)vim
MIT License
2.47k stars 78 forks source link

Transition to native border API #342

Open adigitoleo opened 2 years ago

adigitoleo commented 2 years ago

I was away for a while and it seems neovim have now finally implemented floating window borders, I think in https://github.com/neovim/neovim/pull/13998.

Example:

function! NewFloating() abort "{{{2
    " Open a new floating window.
    let l:buf = nvim_create_buf(v:false, v:true)
    let l:row = &lines / 4
    let l:col = &columns / 4
    let l:height = &lines / 2
    let l:width = &columns / 2
    let l:win = nvim_open_win(
        \l:buf,
        \v:true,
        \{
        \   'relative': 'editor',
        \   'border': 'single',
        \   'row': l:row,
        \   'col': l:col,
        \   'width': l:width,
        \   'height': l:height
        \}
    \)
endfunction

Border highlight group is FloatBorder (undocumented).

Maybe transitioning to this API will help resolve some of the weird border issues.

adigitoleo commented 2 years ago

Relevant section of :h neovim_open_win:

• border: Style of (optional) window border.
  This can either be a string or an array. The
  string values are
• "none": No border (default).
• "single": A single line box.
• "double": A double line box.
• "rounded": Like "single", but with rounded
  corners ("╭" etc.).
• "solid": Adds padding by a single whitespace
    cell.
• "shadow": A drop shadow effect by blending
    with the background.
• If it is an array, it should have a length
    of eight or any divisor of eight. The array
    will specifify the eight chars building up
    the border in a clockwise fashion starting
    with the top-left corner. As an example, the
    double box style could be specified as [
    "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" ]. If
    the number of chars are less than eight,
    they will be repeated. Thus an ASCII border
    could be specified as [ "/", "-", "\\", "|"
    ], or all chars the same as [ "x" ]. An
    empty string can be used to turn off a
    specific border, for instance, [ "", "", "",
    ">", "", "", "", "<" ] will only make
    vertical borders but not horizontal ones. By
    default, `FloatBorder` highlight is used,
    which links to `VertSplit` when not defined.
    It could also be specified by character: [
    {"+", "MyCorner"}, {"x", "MyBorder"} ].
adigitoleo commented 2 years ago

Of course the border chars are specified in a different order, ugh. From vim:

borderchars     List with characters, defining the character to use
                for the top/right/bottom/left border.  Optionally
                followed by the character to use for the
                topleft/topright/botright/botleft corner.
                Example: ['-', '|', '-', '|', '┌', '┐', '┘', '└']
                When the list has one character it is used for all.
                When the list has two characters the first is used for
                the border lines, the second for the corners.
                By default a double line is used all around when
                'encoding' is "utf-8" and 'ambiwidth' is "single",
                otherwise ASCII characters are used.