Repository: neovim/neovim
File: runtime/lua/vim/_extui/shared.lua (Lua)

Code before:
    enable = true,
    msg = { -- Options related to the message module.
      ---@type 'box'|'cmd' Type of window used to place messages, either in the
      ---cmdline or in a separate ephemeral message box window.
      pos = 'cmd',
      box = { -- Options related to the message box window.
        timeout = 4000, -- Time a message is visible.
      },
    },
  },
}
local wincfg = { -- Default cfg for nvim_open_win().
  relative = 'laststatus',
  style = 'minimal',
  col = 0,
  row = 1,
  width = 10000,
  height = 1,
  noautocmd = true,
}

local tab = 0
--- Ensure the various buffers and windows have not been deleted.
function M.tab_check_wins()
  local curtab = api.nvim_get_current_tabpage()
  for _, type in ipairs({ 'box', 'cmd', 'pager', 'dialog' }) do
    local setopt = not api.nvim_buf_is_valid(M.bufs[type])
    if setopt then
      M.bufs[type] = api.nvim_create_buf(false, true)
      if type == 'cmd' then
        -- Attach highlighter to the cmdline buffer.
        local parser = assert(vim.treesitter.get_parser(M.bufs.cmd, 'vim', {}))
        M.cmd.highlighter = vim.treesitter.highlighter.new(parser)
      end
    end

    if
      tab ~= curtab
      or not api.nvim_win_is_valid(M.wins[type])
      or not api.nvim_win_get_config(M.wins[type]).zindex -- no longer floating
    then
      local top = { vim.opt.fcs:get().horiz or o.ambw == 'single' and '─' or '-', 'WinSeparator' }
      local border = (type == 'pager' or type == 'dialog') and { '', top, '', '', '', '', '', '' }
      local cfg = vim.tbl_deep_extend('force', wincfg, {
        focusable = type == 'pager',
        mouse = type ~= 'cmd' and true or nil,
        anchor = type ~= 'cmd' and 'SE' or nil,
        hide = type ~= 'cmd' or M.cmdheight == 0 or nil,
        title = type == 'pager' and 'Pager' or nil,
        border = type == 'box' and 'single' or border or 'none',
        -- kZIndexMessages < zindex < kZIndexCmdlinePopupMenu (grid_defs.h), pager below others.

Review comment (suggestion):
if we rename "box" to `msg` I think it all fits together nicely. then we could use `filetype=msg` too.

```suggestion
  for _, type in ipairs({ 'msg', 'cmd', 'pager', 'dialog' }) do
```

Code after:
    enable = true,
    msg = { -- Options related to the message module.
      ---@type 'cmd'|'msg' Where to place regular messages, either in the
      ---cmdline or in a separate ephemeral message window.
      target = 'cmd',
      timeout = 4000, -- Time a message is visible in the message window.
    },
  },
}
local wincfg = { -- Default cfg for nvim_open_win().
  relative = 'laststatus',
  style = 'minimal',
  col = 0,
  row = 1,
  width = 10000,
  height = 1,
  noautocmd = true,
}

local tab = 0
--- Ensure the various buffers and windows have not been deleted.
function M.tab_check_wins()
  local curtab = api.nvim_get_current_tabpage()
  for _, type in ipairs({ 'cmd', 'dialog', 'msg', 'pager' }) do
    local setopt = not api.nvim_buf_is_valid(M.bufs[type])
    if setopt then
      M.bufs[type] = api.nvim_create_buf(false, true)
      if type == 'cmd' then
        -- Attach highlighter to the cmdline buffer.
        local parser = assert(vim.treesitter.get_parser(M.bufs.cmd, 'vim', {}))
        M.cmd.highlighter = vim.treesitter.highlighter.new(parser)
      end
    end

    if
      tab ~= curtab
      or not api.nvim_win_is_valid(M.wins[type])
      or not api.nvim_win_get_config(M.wins[type]).zindex -- no longer floating
    then
      local top = { vim.opt.fcs:get().horiz or o.ambw == 'single' and '─' or '-', 'WinSeparator' }
      local border = (type == 'pager' or type == 'dialog') and { '', top, '', '', '', '', '', '' }
      local cfg = vim.tbl_deep_extend('force', wincfg, {
        focusable = type == 'pager',
        mouse = type ~= 'cmd' and true or nil,
        anchor = type ~= 'cmd' and 'SE' or nil,
        hide = type ~= 'cmd' or M.cmdheight == 0 or nil,
        title = type == 'pager' and 'Pager' or nil,
        border = type == 'msg' and 'single' or border or 'none',
        -- kZIndexMessages < zindex < kZIndexCmdlinePopupMenu (grid_defs.h), pager below others.
        zindex = 200 - (type == 'pager' and 1 or 0),
        _cmdline_offset = type == 'cmd' and 0 or nil,