grapp-dev / nui-components.nvim

A feature-rich and highly customizable library for creating user interfaces in Neovim.
https://nui-components.grapp.dev
MIT License
303 stars 6 forks source link

Adding a border to a paragraph causes extra line breaks #20

Closed b0o closed 5 months ago

b0o commented 5 months ago

With no border, spacing is correct:

2024-04-12_17-24-09_region

local n = require 'nui-components'

local renderer = n.create_renderer {
  width = 64,
  height = 20,
}

renderer:render(
  n.paragraph {
    lines = {
      n.line(n.text('Foo', 'Keyword')),
      n.line(n.text('Bar', 'Keyword')),
      n.line(n.text('Qux', 'Keyword')),
    },
  }
)

When adding a border, we get extra blank lines. I think there is an issue with width calculation causing the lines to wrap.

2024-04-12_17-26-00_region

local n = require 'nui-components'

local renderer = n.create_renderer {
  width = 64,
  height = 20,
}

renderer:render(
  n.paragraph {
    border_style = 'rounded',
    lines = {
      n.line(n.text('Foo', 'Keyword')),
      n.line(n.text('Bar', 'Keyword')),
      n.line(n.text('Qux', 'Keyword')),
    },
  }
)

By doing :setlocal list and :setlocal listchars=trail:~, it appears the line is padded with spaces, but there are 2 too many:

2024-04-12_22-36-23_region

Also, when truncate is set to true, the issue does not occur.