diff --git a/lua/overseer/config.lua b/lua/overseer/config.lua index 4f386b1..399cc1b 100644 --- a/lua/overseer/config.lua +++ b/lua/overseer/config.lua @@ -26,6 +26,20 @@ local default_config = { separator = "────────────────────────────────────────", -- Default direction. Can be "left", "right", or "bottom" direction = "left", + -- You can set window options (see `:help vim.wo`) to be used when creating + -- the Task List window, these are the defaults used: + win_opts = { + listchars = "tab:> ", + winfixwidth = true, + winfixheight = true, + number = false, + relativenumber = false, + foldcolumn = "0", + signcolumn = "no", + statuscolumn = "", + wrap = false, + spell = false, + }, -- Set keymap to false to remove default behavior -- You can add custom keymaps here as well (anything vim.keymap.set accepts) bindings = { @@ -51,6 +65,24 @@ local default_config = { [""] = "ScrollOutputDown", ["q"] = "Close", }, + -- When the Task List is positioned at the bottom, it will show its output + -- window on the right side of the split. The next configuration table + -- tweaks options for such window + output = { + -- You can set window options (see `:help vim.wo`) to be used when + -- creating the Task List Output window, these are the defaults used: + win_opts = { + number = false, + relativenumber = false, + cursorline = false, + cursorcolumn = false, + foldcolumn = "0", + signcolumn = "no", + statuscolumn = "", + spell = false, + list = false, + }, + }, }, -- See :help overseer-actions actions = {}, diff --git a/lua/overseer/task_list/sidebar.lua b/lua/overseer/task_list/sidebar.lua index 8d48703..1152c2e 100644 --- a/lua/overseer/task_list/sidebar.lua +++ b/lua/overseer/task_list/sidebar.lua @@ -217,6 +217,24 @@ function Sidebar:_get_preview_wins() return ret end +---@param winid number +---@param bufnr number +---@param window_opts vim.wo +function Sidebar:_update_window_buf(winid, bufnr, window_opts) + if vim.api.nvim_win_get_buf(winid) ~= bufnr then + vim.api.nvim_win_set_buf(winid, bufnr) + -- The documentation of `vim.api.nvim_win_set_buf` states that it will + -- "Set the current buffer in a window, without side effects", but + -- unfortunately, some window options are not kept when a "new" buffer is + -- set to the window. For instance, the `winhighlight` and the experimental + -- `statuscolumn` options may change with a new buffer, therefore, to make + -- the appearance of the window consistent, we re-apply its window options + -- when switching its current buffer. + util.set_window_opts(window_opts, winid) + util.scroll_to_end(winid) + end +end + function Sidebar:update_preview() local winids = self:_get_preview_wins() if vim.tbl_isempty(winids) then @@ -240,9 +258,12 @@ function Sidebar:update_preview() end for _, winid in ipairs(winids) do - if vim.api.nvim_win_get_buf(winid) ~= display_buf then - vim.api.nvim_win_set_buf(winid, display_buf) - util.scroll_to_end(winid) + -- We need to use different window options between the floating preview + -- window and the output one + if vim.wo[winid].previewwindow then + self:_update_window_buf(winid, display_buf, config.task_win.win_opts) + else + self:_update_window_buf(winid, display_buf, config.task_list.output.win_opts) end end end diff --git a/lua/overseer/util.lua b/lua/overseer/util.lua index 4eb3ca0..41a2405 100644 --- a/lua/overseer/util.lua +++ b/lua/overseer/util.lua @@ -147,6 +147,15 @@ M.scroll_to_end = function(winid) vim.api.nvim_set_option_value("scrolloff", scrolloff, { scope = "local", win = winid }) end +---@param win_opts vim.wo +---@param winid? number +M.set_window_opts = function(win_opts, winid) + winid = winid or 0 + for k, v in pairs(win_opts) do + vim.api.nvim_set_option_value(k, v, { scope = "local", win = winid }) + end +end + ---@param bufnr number ---@param ns number ---@param highlights table @@ -265,10 +274,12 @@ end ---Set the appropriate window options for a terminal buffer M.set_term_window_opts = function(winid) - winid = winid or 0 - vim.api.nvim_set_option_value("number", false, { scope = "local", win = winid }) - vim.api.nvim_set_option_value("relativenumber", false, { scope = "local", win = winid }) - vim.api.nvim_set_option_value("signcolumn", "no", { scope = "local", win = winid }) + M.set_window_opts({ + number = false, + relativenumber = false, + signcolumn = "no", + statuscolumn = "", + }, winid) end ---@generic T : any diff --git a/lua/overseer/window.lua b/lua/overseer/window.lua index 651a62d..22103a1 100644 --- a/lua/overseer/window.lua +++ b/lua/overseer/window.lua @@ -21,23 +21,6 @@ local function watch_for_win_closed() }) end -local min_win_opts = { - number = false, - relativenumber = false, - cursorline = false, - cursorcolumn = false, - foldcolumn = "0", - signcolumn = "no", - spell = false, - list = false, -} ----@param winid integer -local function set_minimal_win_opts(winid) - for k, v in pairs(min_win_opts) do - vim.api.nvim_set_option_value(k, v, { scope = "local", win = winid }) - end -end - ---@param direction "left"|"right"|"bottom" ---@param existing_win integer local function create_overseer_window(direction, existing_win) @@ -68,34 +51,21 @@ local function create_overseer_window(direction, existing_win) vim.bo[outbuf].bufhidden = "wipe" end util.go_buf_no_au(outbuf) - set_minimal_win_opts(0) + util.set_window_opts(config.task_list.output.win_opts, 0) util.go_win_no_au(winid) vim.w.overseer_output_win = output_win watch_for_win_closed() end util.go_buf_no_au(bufnr) - local default_opts = { - listchars = "tab:> ", - winfixwidth = true, - winfixheight = true, - number = false, - signcolumn = "no", - foldcolumn = "0", - relativenumber = false, - wrap = false, - spell = false, - } - for k, v in pairs(default_opts) do - vim.api.nvim_set_option_value(k, v, { scope = "local", win = 0 }) - end + util.set_window_opts(config.task_list.win_opts, 0) vim.api.nvim_win_set_width(0, layout.calculate_width(nil, config.task_list)) if direction == "bottom" then vim.api.nvim_win_set_height(0, layout.calculate_height(nil, config.task_list)) end -- Set the filetype only after we enter the buffer so that FileType autocmds -- behave properly - vim.bo[bufnr].filetype = "OverseerList" + vim.api.nvim_set_option_value("filetype", "OverseerList", { buf = bufnr }) util.go_win_no_au(my_winid) return winid