feat: add 'location' config option
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# opencode.nvim
|
# opencode.nvim
|
||||||
|
|
||||||
Neovim plugin that toggles an `opencode` terminal in a right-side split.
|
Neovim plugin that toggles an `opencode` terminal in a configurable split.
|
||||||
|
|
||||||
The terminal buffer is kept alive when hidden, so your `opencode` session remains
|
The terminal buffer is kept alive when hidden, so your `opencode` session remains
|
||||||
available across toggles.
|
available across toggles.
|
||||||
@@ -25,6 +25,7 @@ Using `lazy.nvim`:
|
|||||||
"agj/opencode.nvim",
|
"agj/opencode.nvim",
|
||||||
opts = {
|
opts = {
|
||||||
width = 0.3,
|
width = 0.3,
|
||||||
|
location = "right",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -57,11 +58,17 @@ show the same session.
|
|||||||
```lua
|
```lua
|
||||||
require("opencode").setup({
|
require("opencode").setup({
|
||||||
width = 0.3,
|
width = 0.3,
|
||||||
|
location = "right",
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
`width` is the fraction of the screen width used by the terminal window. The
|
`width` is the fraction of the screen width used by the terminal window for
|
||||||
default is `0.3`. It must be greater than `0` and less than or equal to `1`.
|
`left` and `right` locations, or the screen height for `top` and `bottom`
|
||||||
|
locations. The default is `0.3`. It must be greater than `0` and less than or
|
||||||
|
equal to `1`.
|
||||||
|
|
||||||
|
`location` controls where the terminal window opens. The default is `"right"`.
|
||||||
|
It must be one of `"left"`, `"right"`, `"top"`, or `"bottom"`.
|
||||||
|
|
||||||
## Help
|
## Help
|
||||||
|
|
||||||
|
|||||||
+12
-4
@@ -13,7 +13,7 @@ CONTENTS *opencode.nvim-contents*
|
|||||||
===============================================================================
|
===============================================================================
|
||||||
INTRODUCTION *opencode.nvim*
|
INTRODUCTION *opencode.nvim*
|
||||||
|
|
||||||
opencode.nvim toggles an `opencode` terminal in a right-side split.
|
opencode.nvim toggles an `opencode` terminal in a configurable split.
|
||||||
|
|
||||||
The terminal buffer is hidden instead of deleted when closed, so the same
|
The terminal buffer is hidden instead of deleted when closed, so the same
|
||||||
`opencode` session is shown the next time the window is toggled open.
|
`opencode` session is shown the next time the window is toggled open.
|
||||||
@@ -38,6 +38,7 @@ Using lazy.nvim: >lua
|
|||||||
"agj/opencode.nvim",
|
"agj/opencode.nvim",
|
||||||
opts = {
|
opts = {
|
||||||
width = 0.3,
|
width = 0.3,
|
||||||
|
location = "right",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
<
|
<
|
||||||
@@ -55,7 +56,7 @@ USAGE *opencode.nvim-usage*
|
|||||||
|
|
||||||
*:OpenCodeToggle*
|
*:OpenCodeToggle*
|
||||||
:OpenCodeToggle
|
:OpenCodeToggle
|
||||||
Toggle the right-side opencode terminal window.
|
Toggle the opencode terminal window.
|
||||||
|
|
||||||
If the terminal window is visible, this closes only the window. The
|
If the terminal window is visible, this closes only the window. The
|
||||||
terminal buffer and running `opencode` process remain alive. If the
|
terminal buffer and running `opencode` process remain alive. If the
|
||||||
@@ -67,6 +68,7 @@ CONFIGURATION *opencode.nvim-configuration*
|
|||||||
Call setup with an optional table: >lua
|
Call setup with an optional table: >lua
|
||||||
require("opencode").setup({
|
require("opencode").setup({
|
||||||
width = 0.3,
|
width = 0.3,
|
||||||
|
location = "right",
|
||||||
})
|
})
|
||||||
<
|
<
|
||||||
|
|
||||||
@@ -74,8 +76,14 @@ Options: *opencode.nvim-options*
|
|||||||
|
|
||||||
*opencode.nvim-width*
|
*opencode.nvim-width*
|
||||||
width number, default: 0.3
|
width number, default: 0.3
|
||||||
Fraction of the screen width used by the terminal split. Must be
|
Fraction of the screen width used by the terminal split for left and
|
||||||
greater than 0 and less than or equal to 1.
|
right locations, or the screen height for top and bottom locations.
|
||||||
|
Must be greater than 0 and less than or equal to 1.
|
||||||
|
|
||||||
|
*opencode.nvim-location*
|
||||||
|
location string, default: "right"
|
||||||
|
Side of the screen where the terminal split opens. Must be one of
|
||||||
|
"left", "right", "top", or "bottom".
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
LICENSE *opencode.nvim-license*
|
LICENSE *opencode.nvim-license*
|
||||||
|
|||||||
+39
-4
@@ -21,6 +21,14 @@ local state = {
|
|||||||
|
|
||||||
local config = {
|
local config = {
|
||||||
width = 0.3,
|
width = 0.3,
|
||||||
|
location = "right",
|
||||||
|
}
|
||||||
|
|
||||||
|
local valid_locations = {
|
||||||
|
left = true,
|
||||||
|
right = true,
|
||||||
|
top = true,
|
||||||
|
bottom = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
local function is_valid_window(win)
|
local function is_valid_window(win)
|
||||||
@@ -35,10 +43,28 @@ local function terminal_width()
|
|||||||
return math.max(1, math.floor(vim.o.columns * config.width))
|
return math.max(1, math.floor(vim.o.columns * config.width))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function open_side_window()
|
local function terminal_height()
|
||||||
vim.cmd("botright vertical " .. terminal_width() .. "new")
|
return math.max(1, math.floor(vim.o.lines * config.width))
|
||||||
|
end
|
||||||
|
|
||||||
|
local function open_terminal_window()
|
||||||
|
if config.location == "left" then
|
||||||
|
vim.cmd("topleft vertical " .. terminal_width() .. "new")
|
||||||
|
elseif config.location == "right" then
|
||||||
|
vim.cmd("botright vertical " .. terminal_width() .. "new")
|
||||||
|
elseif config.location == "top" then
|
||||||
|
vim.cmd("topleft " .. terminal_height() .. "new")
|
||||||
|
else
|
||||||
|
vim.cmd("botright " .. terminal_height() .. "new")
|
||||||
|
end
|
||||||
|
|
||||||
state.win = vim.api.nvim_get_current_win()
|
state.win = vim.api.nvim_get_current_win()
|
||||||
vim.api.nvim_set_option_value("winfixwidth", true, { win = state.win })
|
|
||||||
|
if config.location == "left" or config.location == "right" then
|
||||||
|
vim.api.nvim_set_option_value("winfixwidth", true, { win = state.win })
|
||||||
|
else
|
||||||
|
vim.api.nvim_set_option_value("winfixheight", true, { win = state.win })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function start_terminal()
|
local function start_terminal()
|
||||||
@@ -62,7 +88,7 @@ function M.toggle()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
open_side_window()
|
open_terminal_window()
|
||||||
|
|
||||||
if is_valid_buffer(state.buf) then
|
if is_valid_buffer(state.buf) then
|
||||||
vim.api.nvim_win_set_buf(state.win, state.buf)
|
vim.api.nvim_win_set_buf(state.win, state.buf)
|
||||||
@@ -85,6 +111,15 @@ function M.setup(opts)
|
|||||||
config.width = opts.width
|
config.width = opts.width
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if opts.location ~= nil then
|
||||||
|
assert(
|
||||||
|
type(opts.location) == "string" and valid_locations[opts.location],
|
||||||
|
"opencode.nvim: location must be one of: left, right, top, bottom"
|
||||||
|
)
|
||||||
|
|
||||||
|
config.location = opts.location
|
||||||
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("OpenCodeToggle", function()
|
vim.api.nvim_create_user_command("OpenCodeToggle", function()
|
||||||
M.toggle()
|
M.toggle()
|
||||||
end, { force = true })
|
end, { force = true })
|
||||||
|
|||||||
Reference in New Issue
Block a user