|
|
|
@ -5,20 +5,19 @@ |
|
|
|
-- count, e.g. 2<C-/> opens a *separate* terminal #2) |
|
|
|
-- count, e.g. 2<C-/> opens a *separate* terminal #2) |
|
|
|
-- <leader>fT terminal in the current working directory |
|
|
|
-- <leader>fT terminal in the current working directory |
|
|
|
-- |
|
|
|
-- |
|
|
|
-- This module adds: |
|
|
|
-- This module adds (actual key bindings are declared in lua/plugins/terminal.lua): |
|
|
|
-- <Tab> open/focus a *dedicated* floating terminal (close it with <C-/>) |
|
|
|
-- open_float() open/focus a *dedicated* floating terminal (close it with <C-/>) |
|
|
|
-- <leader>ft a picker that lists every live terminal so any contextual |
|
|
|
-- picker() list every live terminal so any contextual terminal can be |
|
|
|
-- terminal can be focused or restored even after its window was |
|
|
|
-- focused or restored even after its window was closed/hidden. |
|
|
|
-- closed/hidden. |
|
|
|
|
|
|
|
local M = {} |
|
|
|
local M = {} |
|
|
|
|
|
|
|
|
|
|
|
-- The <Tab> floating terminal. Tracked as an upvalue so <Tab> always re-focuses |
|
|
|
-- The floating terminal. Tracked as an upvalue so the same key always re-focuses |
|
|
|
-- the *same* float regardless of which directory the editor is in. |
|
|
|
-- the *same* float regardless of which directory the editor is in. |
|
|
|
---@type snacks.win? |
|
|
|
---@type snacks.win? |
|
|
|
local float |
|
|
|
local float |
|
|
|
|
|
|
|
|
|
|
|
--- Open or focus the <Tab> floating terminal, or hide it if already focused. |
|
|
|
--- Open or focus the floating terminal, or hide it if already focused. |
|
|
|
-- NOTE: currently unused; <Tab> calls open_float() instead so shell |
|
|
|
-- NOTE: currently unused; the binding calls open_float() instead so shell |
|
|
|
-- tab-completion keeps working while the terminal is open. Kept around for a |
|
|
|
-- tab-completion keeps working while the terminal is open. Kept around for a |
|
|
|
-- future explicit open/close toggle. |
|
|
|
-- future explicit open/close toggle. |
|
|
|
function M.toggle_float() |
|
|
|
function M.toggle_float() |
|
|
|
@ -35,17 +34,17 @@ function M.toggle_float() |
|
|
|
|
|
|
|
|
|
|
|
-- First open: a high fixed count guarantees this terminal never collides with |
|
|
|
-- First open: a high fixed count guarantees this terminal never collides with |
|
|
|
-- the count-keyed bottom terminals (1, 2, 3 ...), so it is always the *same* |
|
|
|
-- the count-keyed bottom terminals (1, 2, 3 ...), so it is always the *same* |
|
|
|
-- float for <Tab> no matter the context. |
|
|
|
-- float for <C-Tab> no matter the context. |
|
|
|
float = Snacks.terminal(nil, { |
|
|
|
float = Snacks.terminal(nil, { |
|
|
|
count = 99, |
|
|
|
count = 99, |
|
|
|
win = { position = "float", border = "rounded" }, |
|
|
|
win = { position = "float", border = "rounded" }, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
-- Close it with a single keystroke from inside the shell: <Tab> hides the |
|
|
|
-- Close it with a single keystroke from inside the shell: hides the |
|
|
|
-- window (buffer-local, so it only affects this floating terminal and never |
|
|
|
-- window (buffer-local, so it only affects this floating terminal and never |
|
|
|
-- the bottom split, where shell tab-completion must keep working). |
|
|
|
-- the bottom split, where shell tab-completion must keep working). |
|
|
|
if float and float.buf then |
|
|
|
if float and float.buf then |
|
|
|
vim.keymap.set("t", "<Tab>", function() |
|
|
|
vim.keymap.set("t", "<leader>tt", function() |
|
|
|
if float and float:win_valid() then |
|
|
|
if float and float:win_valid() then |
|
|
|
float:hide() |
|
|
|
float:hide() |
|
|
|
end |
|
|
|
end |
|
|
|
@ -53,8 +52,8 @@ function M.toggle_float() |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
--- Open or focus the <Tab> floating terminal. This never hides the window, so |
|
|
|
--- Open or focus the floating terminal. This never hides the window, so |
|
|
|
--- once the float is open <Tab> falls through to the shell and stays available |
|
|
|
--- once the float is open the key falls through to the shell and stays available |
|
|
|
--- for tab-completion. Close the floating terminal with <C-/> while it is |
|
|
|
--- for tab-completion. Close the floating terminal with <C-/> while it is |
|
|
|
--- visible (handled by Snacks' native terminal keymap). |
|
|
|
--- visible (handled by Snacks' native terminal keymap). |
|
|
|
function M.open_float() |
|
|
|
function M.open_float() |
|
|
|
@ -71,7 +70,7 @@ function M.open_float() |
|
|
|
|
|
|
|
|
|
|
|
-- First open: a high fixed count guarantees this terminal never collides with |
|
|
|
-- First open: a high fixed count guarantees this terminal never collides with |
|
|
|
-- the count-keyed bottom terminals (1, 2, 3 ...), so it is always the *same* |
|
|
|
-- the count-keyed bottom terminals (1, 2, 3 ...), so it is always the *same* |
|
|
|
-- float for <Tab> no matter the context. |
|
|
|
-- float for <C-Tab> no matter the context. |
|
|
|
float = Snacks.terminal(nil, { |
|
|
|
float = Snacks.terminal(nil, { |
|
|
|
count = 99, |
|
|
|
count = 99, |
|
|
|
win = { position = "float", border = "rounded" }, |
|
|
|
win = { position = "float", border = "rounded" }, |
|
|
|
|