Skip to content
Open
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
11 changes: 11 additions & 0 deletions lua/claudecode/terminal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,17 @@ function M.get_active_terminal_bufnr()
return get_provider().get_active_bufnr()
end

---Reposition the terminal window with new opts, keeping the process alive.
---@param opts_override table? Overrides (e.g. snacks_win_opts with new position)
function M.reposition(opts_override)
local effective_config = build_config(opts_override)
local cmd_string, claude_env_table = get_claude_command_and_env()
local provider = get_provider()
if type(provider.reposition) == "function" then
provider.reposition(cmd_string, claude_env_table, effective_config)
end
end

---Gets the managed terminal instance for testing purposes.
-- NOTE: This function is intended for use in tests to inspect internal state.
-- The underscore prefix indicates it's not part of the public API for regular use.
Expand Down
19 changes: 19 additions & 0 deletions lua/claudecode/terminal/snacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,25 @@ function M.is_available()
return is_available()
end

---Reposition the terminal window using new config, keeping the terminal process alive.
---Closes the current window (not the buffer), then reopens with new position/opts.
---@param cmd_string string
---@param env_table table
---@param config table
function M.reposition(cmd_string, env_table, config)
if not is_available() or not terminal or not terminal:buf_valid() then
return
end
local buf = terminal.buf
terminal:close({ buf = false })
local opts = build_opts(config, env_table, true)
opts.win.buf = buf
local new_term = Snacks.win(opts.win)
if new_term and new_term:buf_valid() then
terminal = new_term
end
end

---For testing purposes
---@return table? terminal The terminal instance, or nil
function M._get_terminal_for_test()
Expand Down