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

feat: add rounded opt #139

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lua/avante/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ M.defaults = {
windows = {
wrap_line = true, -- similar to vim.o.wrap
width = 30, -- default % based on available width
sidebar = {
sidebar_header = {
align = "center", -- left, center, right for title
rounded = true,
},
},
--- @class AvanteConflictUserConfig
Expand Down
33 changes: 23 additions & 10 deletions lua/avante/sidebar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -331,19 +331,25 @@ function Sidebar:do_render_header(winid, bufnr, header_text, hl, reverse_hl)
return
end

header_text = " " .. header_text .. " "
local reversed_hl_off = 0
if Config.windows.sidebar_header.rounded then
reversed_hl_off = 1
header_text = "" .. header_text .. ""
else
header_text = " " .. header_text .. " "
end

local width = api.nvim_win_get_width(winid)
local header_text_length = vim.fn.strdisplaywidth(header_text)
local prefix_padding, suffix_padding = 0, 0

if Config.windows.sidebar.align == "center" then
if Config.windows.sidebar_header.align == "center" then
prefix_padding = math.floor((width - header_text_length) / 2)
suffix_padding = width - header_text_length - prefix_padding
elseif Config.windows.sidebar.align == "right" then
elseif Config.windows.sidebar_header.align == "right" then
prefix_padding = width - header_text_length
suffix_padding = 0
elseif Config.windows.sidebar.align == "left" then
elseif Config.windows.sidebar_header.align == "left" then
suffix_padding = width - header_text_length
prefix_padding = 0
end
Expand All @@ -352,18 +358,25 @@ function Sidebar:do_render_header(winid, bufnr, header_text, hl, reverse_hl)
local suffix_padding_text = string.rep(" ", suffix_padding)
Utils.unlock_buf(bufnr)
api.nvim_buf_set_lines(bufnr, 0, -1, false, { prefix_padding_text .. header_text .. suffix_padding_text })
api.nvim_buf_add_highlight(bufnr, -1, "WinSeparator", 0, 0, #prefix_padding_text)
api.nvim_buf_add_highlight(bufnr, -1, reverse_hl, 0, #prefix_padding_text, #prefix_padding_text)
api.nvim_buf_add_highlight(bufnr, -1, hl, 0, #prefix_padding_text, #prefix_padding_text + #header_text)
api.nvim_buf_add_highlight(bufnr, -1, "WinSeparator", 0, 0, #prefix_padding_text - reversed_hl_off)
api.nvim_buf_add_highlight(bufnr, -1, reverse_hl, 0, #prefix_padding_text, #prefix_padding_text + reversed_hl_off)
api.nvim_buf_add_highlight(
bufnr,
-1,
hl,
0,
#prefix_padding_text + reversed_hl_off,
#prefix_padding_text + #header_text - reversed_hl_off * 3
)
api.nvim_buf_add_highlight(
bufnr,
-1,
reverse_hl,
0,
#prefix_padding_text + #header_text,
#prefix_padding_text + #header_text
#prefix_padding_text + #header_text - reversed_hl_off * 3,
#prefix_padding_text + #header_text - reversed_hl_off * 2
)
api.nvim_buf_add_highlight(bufnr, -1, "WinSeparator", 0, #prefix_padding_text + #header_text, -1)
api.nvim_buf_add_highlight(bufnr, -1, "WinSeparator", 0, #prefix_padding_text + #header_text - reversed_hl_off, -1)
Utils.lock_buf(bufnr)
end

Expand Down