Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: allow to configure window options as functions #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

weilbith
Copy link
Contributor

This adds the possibility for more dynamic window configuration. To do so, it allows some window configuration options to be a function. If so, it evaluates the function by calling it with the window number as first parameter. The output of the function is taken as the actual configuration value that is then passed to the Nui library.

In addition to this, it also makes the "relative" option of Nui configurable. The default value reflects the former fixed constant.

A possible usage of this would be a configuration that sizes and positions Navbuddy relative to the current window and with the same width as the window.
Moreover this allows to easily require a minimum width of Navbuddy and much more. It does so without putting the burden to the plugin, but rather the experienced power user.

All changes are fully backwards compatible.

This adds the possibility for more dynamic window configuration. To do
so, it allows some window configuration options to be a function. If so,
it evaluates the function by calling it with the window number as first
parameter. The output of the function is taken as the actual
configuration value that is then passed to the Nui library.

In addition to this, it also makes the "relative" option of Nui
configurable. The default value reflects the former fixed constant.

A possible usage of this would be a configuration that sizes and
positions Navbuddy relative to the current window and with the same
width as the window.
Moreover this allows to easily require a minimum width of Navbuddy and
much more. It does so without putting the burden to the plugin, but
rather the experienced power user.

All changes are fully backwards compatible.
@weilbith
Copy link
Contributor Author

weilbith commented Jun 27, 2023

An example configuration I'm using atm with this branch:

{
  window = {
    relative = 'win'
    size = function(window_number)
      local window_width = vim.api.nvim_win_get_width(window_number)
      local width = window_width > minimum_width and window_width or '100%'

      return {
        width = width,
        height = 20,
      }
    end,
    position = function(window_number)
      local window_width = vim.api.nvim_win_get_width(window_number)
      local window_column = vim.api.nvim_win_get_position(window_number)[2]
      local column = window_width > minimum_width and window_column or 0

      return {
        row = '50%',
        col = column,
      }
    end,
  },
}

@SmiteshP
Copy link
Owner

SmiteshP commented Jul 2, 2023

I see what you mean, makes sense to me. Maybe consider raising this as a feature of Nui library itself so that other plugins could also benefit from this. If its not accepted by nui, we can merge this PR here anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants