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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ return {
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)
oss = false, -- Select the local open source model provider
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
Expand Down
37 changes: 29 additions & 8 deletions lua/codex/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ local config = {
width = 0.8,
height = 0.8,
cmd = 'codex',
oss = false, -- Select the local open source model provider
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 side-panel instead of floating window
use_buffer = false, -- if true, capture Codex stdout into a normal buffer instead of a terminal
}

function M.setup(user_config)
Expand Down Expand Up @@ -91,7 +92,7 @@ end
--- Open Codex in a side-panel (vertical split) instead of floating window
local function open_panel()
-- Create a vertical split on the right and show the buffer
vim.cmd('vertical rightbelow vsplit')
vim.cmd 'vertical rightbelow vsplit'
local win = vim.api.nvim_get_current_win()
vim.api.nvim_win_set_buf(win, state.buf)
-- Adjust width according to config (percentage of total columns)
Expand Down Expand Up @@ -142,7 +143,11 @@ function M.open()
'You can install manually with:',
' npm install -g @openai/codex',
})
if config.panel then open_panel() else open_window() end
if config.panel then
open_panel()
else
open_window()
end
end
end)
return
Expand All @@ -159,7 +164,11 @@ function M.open()
'',
'Or enable autoinstall in setup: require("codex").setup{ autoinstall = true }',
})
if config.panel then open_panel() else open_window() end
if config.panel then
open_panel()
else
open_window()
end
return
end
end
Expand All @@ -172,11 +181,19 @@ function M.open()
state.buf = create_clean_buf()
end

if config.panel then open_panel() else open_window() end
if config.panel then
open_panel()
else
open_window()
end

if not state.job then
-- assemble command
local cmd_args = type(config.cmd) == 'string' and { config.cmd } or vim.deepcopy(config.cmd)
if config.oss then
table.insert(cmd_args, '--oss')
end

if config.model then
table.insert(cmd_args, '-m')
table.insert(cmd_args, config.model)
Expand All @@ -188,15 +205,19 @@ function M.open()
cwd = vim.loop.cwd(),
stdout_buffered = true,
on_stdout = function(_, data)
if not data then return end
if not data then
return
end
for _, line in ipairs(data) do
if line ~= '' then
vim.api.nvim_buf_set_lines(state.buf, -1, -1, false, { line })
end
end
end,
on_stderr = function(_, data)
if not data then return end
if not data then
return
end
for _, line in ipairs(data) do
if line ~= '' then
vim.api.nvim_buf_set_lines(state.buf, -1, -1, false, { '[ERR] ' .. line })
Expand Down