diff --git a/README.md b/README.md index 47339a4..98cf5a2 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ > Latest version: ![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/johnseth97/codex.nvim?sort=semver) ### Features: -- ✅ Toggle Codex window or side-panel with `:CodexToggle` +- ✅ Toggle Codex window, side-panel, or horizontal split with `:CodexToggle` - ✅ Optional keymap mapping via `setup` call - ✅ Background running when window hidden - ✅ Statusline integration via `require('codex').status()` @@ -36,7 +36,7 @@ return { { 'cc', -- Change this to your preferred keybinding function() require('codex').toggle() end, - desc = 'Toggle Codex popup or side-panel', + desc = 'Toggle Codex window', mode = { 'n', 't' } }, }, @@ -46,19 +46,25 @@ return { quit = '', -- Keybind to close the Codex window (default: Ctrl + q) }, -- Disable internal default keymap (cc -> :CodexToggle) border = 'rounded', -- Options: 'single', 'double', or 'rounded' - width = 0.8, -- Width of the floating window (0.0 to 1.0) - height = 0.8, -- Height of the floating window (0.0 to 1.0) + width = 0.8, -- Width of the floating window or split (0.0 to 1.0) + height = 0.8, -- Height of the floating window or split (0.0 to 1.0) model = nil, -- Optional: pass a string to use a specific model (e.g., 'o3-mini') autoinstall = true, -- Automatically install the Codex CLI if not found - panel = false, -- Open Codex in a side-panel (vertical split) instead of floating window + panel = false, -- Open Codex in a panel (split) instead of floating window + layout = 'vertical', -- 'vertical' or 'horizontal' (only applies when panel = true) use_buffer = false, -- Capture Codex stdout into a normal buffer instead of a terminal buffer }, }``` ### Usage: -- Call `:Codex` (or `:CodexToggle`) to open or close the Codex popup or side-panel. +- Call `:Codex` (or `:CodexToggle`) to open or close the Codex window. - Map your own keybindings via the `keymaps.toggle` setting. -- To choose floating popup vs side-panel, set `panel = false` (popup) or `panel = true` (panel) in your setup options. +- Configure the window display: + - Set `panel = false` for a floating window (default) + - Set `panel = true` for an in-place split panel + - When `panel = true`, use `layout` to choose split direction: + - `layout = 'vertical'` - Vertical split on the right (default) + - `layout = 'horizontal'` - Horizontal split at the bottom - To capture Codex output in an editable buffer instead of a terminal, set `use_buffer = true` (or `false` to keep terminal) in your setup options. - Add the following code to show backgrounded Codex window in lualine: diff --git a/lua/codex/init.lua b/lua/codex/init.lua index 4378b46..488f4af 100644 --- a/lua/codex/init.lua +++ b/lua/codex/init.lua @@ -15,8 +15,9 @@ local config = { cmd = 'codex', model = nil, -- Default to the latest model autoinstall = true, - panel = false, -- if true, open Codex in a side-panel instead of floating window - use_buffer = false, -- if true, capture Codex stdout into a normal buffer instead of a terminal + panel = false, -- if true, open Codex in a panel instead of floating window + layout = 'vertical', -- 'vertical' or 'horizontal' (only applies when panel = true) + use_buffer = false, -- if true, capture Codex stdout into a normal buffer instead of a terminal } function M.setup(user_config) @@ -100,6 +101,35 @@ local function open_panel() state.win = win end +--- Open Codex in a horizontal split at the bottom +local function open_horizontal_split() + -- Create a horizontal split at the bottom and show the buffer + vim.cmd('rightbelow split') + local win = vim.api.nvim_get_current_win() + vim.api.nvim_win_set_buf(win, state.buf) + -- Adjust height according to config (percentage of total lines) + local height = math.floor(vim.o.lines * config.height) + vim.api.nvim_win_set_height(win, height) + state.win = win +end + +--- Open the window based on the configured panel and layout settings +local function open_based_on_config() + if config.panel then + -- Panel mode: check layout to decide between vertical and horizontal + local layout = config.layout or 'vertical' + if layout == 'horizontal' then + open_horizontal_split() + else + -- Default to vertical split for backward compatibility + open_panel() + end + else + -- Floating window mode + open_window() + end +end + function M.open() local function create_clean_buf() local buf = vim.api.nvim_create_buf(false, false) @@ -142,7 +172,7 @@ function M.open() 'You can install manually with:', ' npm install -g @openai/codex', }) - if config.panel then open_panel() else open_window() end + open_based_on_config() end end) return @@ -159,7 +189,7 @@ function M.open() '', 'Or enable autoinstall in setup: require("codex").setup{ autoinstall = true }', }) - if config.panel then open_panel() else open_window() end + open_based_on_config() return end end @@ -172,7 +202,7 @@ function M.open() state.buf = create_clean_buf() end - if config.panel then open_panel() else open_window() end + open_based_on_config() if not state.job then -- assemble command