Skip to content

Commit 456b686

Browse files
authored
feat(snacks): add snacks_win_opts for user to override opts of Snacks.terminal.open() (#65)
Case: - Floating window. - Toggle to show/hide the snacks terminal. ```lua local toggle_key = "<C-,>" return { { "coder/claudecode.nvim", keys = { { toggle_key, "<cmd>ClaudeCodeFocus<cr>", desc = "Claude Code", mode = { "n", "x" } }, }, opts = { terminal = { ---@module "snacks" ---@type snacks.win.Config|{} snacks_win_opts = { position = "float", width = 0.9, height = 0.9, keys = { claude_hide = { toggle_key, function(self) self:hide() end, mode = "t", desc = "Hide", }, }, }, }, }, }, } ```
1 parent 8876747 commit 456b686

File tree

5 files changed

+14
-3
lines changed

5 files changed

+14
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ For deep technical details, see [ARCHITECTURE.md](./ARCHITECTURE.md).
157157
split_width_percentage = 0.30,
158158
provider = "auto", -- "auto", "snacks", or "native"
159159
auto_close = true,
160+
snacks_win_opts = {}, -- Opts to pass to `Snacks.terminal.open()`
160161
},
161162

162163
-- Diff Integration

dev-config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ return {
7070
-- provider = "auto", -- "auto", "snacks", or "native"
7171
-- show_native_term_exit_tip = true, -- Show exit tip for native terminal
7272
-- auto_close = true, -- Auto-close terminal after command completion
73+
-- snacks_win_opts = {}, -- Opts to pass to `Snacks.terminal.open()`
7374
-- },
7475

7576
-- Development overrides (uncomment as needed)

lua/claudecode/init.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ M.state = {
8787
--- split_side?: "left"|"right", \
8888
--- split_width_percentage?: number, \
8989
--- provider?: "auto"|"snacks"|"native", \
90-
--- show_native_term_exit_tip?: boolean }
90+
--- show_native_term_exit_tip?: boolean, \
91+
--- snacks_win_opts?: table }
9192
---
9293
---@alias ClaudeCode.SetupOpts { \
9394
--- terminal?: ClaudeCode.TerminalOpts }

lua/claudecode/terminal.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ local config = {
2424
show_native_term_exit_tip = true,
2525
terminal_cmd = nil,
2626
auto_close = true,
27+
snacks_win_opts = {},
2728
}
2829

2930
-- Lazy load providers
@@ -91,6 +92,9 @@ local function build_config(opts_override)
9192
split_width_percentage = function(val)
9293
return type(val) == "number" and val > 0 and val < 1
9394
end,
95+
snacks_win_opts = function(val)
96+
return type(val) == "table"
97+
end,
9498
}
9599
for key, val in pairs(opts_override) do
96100
if effective_config[key] ~= nil and validators[key] and validators[key](val) then
@@ -102,6 +106,7 @@ local function build_config(opts_override)
102106
split_side = effective_config.split_side,
103107
split_width_percentage = effective_config.split_width_percentage,
104108
auto_close = effective_config.auto_close,
109+
snacks_win_opts = effective_config.snacks_win_opts,
105110
}
106111
end
107112

@@ -179,6 +184,7 @@ end
179184
-- @field user_term_config.split_width_percentage number Percentage of screen width (0.0 to 1.0, default: 0.30).
180185
-- @field user_term_config.provider string 'snacks' or 'native' (default: 'snacks').
181186
-- @field user_term_config.show_native_term_exit_tip boolean Show tip for exiting native terminal (default: true).
187+
-- @field user_term_config.snacks_win_opts table Opts to pass to `Snacks.terminal.open()` (default: {}).
182188
-- @param p_terminal_cmd string|nil The command to run in the terminal (from main config).
183189
function M.setup(user_term_config, p_terminal_cmd)
184190
if user_term_config == nil then -- Allow nil, default to empty table silently
@@ -210,6 +216,8 @@ function M.setup(user_term_config, p_terminal_cmd)
210216
config[k] = v
211217
elseif k == "auto_close" and type(v) == "boolean" then
212218
config[k] = v
219+
elseif k == "snacks_win_opts" and type(v) == "table" then
220+
config[k] = v
213221
else
214222
vim.notify("claudecode.terminal.setup: Invalid value for " .. k .. ": " .. tostring(v), vim.log.levels.WARN)
215223
end

lua/claudecode/terminal/snacks.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ local function build_opts(config, env_table, focus)
5454
start_insert = focus,
5555
auto_insert = focus,
5656
auto_close = false,
57-
win = {
57+
win = vim.tbl_deep_extend("force", {
5858
position = config.split_side,
5959
width = config.split_width_percentage,
6060
height = 0,
6161
relative = "editor",
62-
},
62+
}, config.snacks_win_opts or {}),
6363
}
6464
end
6565

0 commit comments

Comments
 (0)