Skip to content

Commit bc6da38

Browse files
[grok-nvim] 0.1.1-109-p: UI polish: issue 7:testing autocmd to clean buffers, issue 4: character limit is now set
1 parent 8d46250 commit bc6da38

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

lua/grok/init.lua

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ function M.setup(opts)
3737
temperature = 0.7,
3838
max_tokens = 256,
3939
debug = false,
40-
-- v0.1.1 Additions: UI Polish
4140
prompt_position = "center", -- Options: "left", "center", "right"
42-
-- Hidden: max_prompt_length derived from model (not user-settable)
4341
}, opts or {})
4442
if not M.config.api_key then
4543
vim.notify("GROK_KEY not set in ~/.secrets, environment, or opts!", vim.log.levels.ERROR)
@@ -50,21 +48,25 @@ function M.setup(opts)
5048
commands.setup_commands()
5149
log.info("Plugin setup completed - grok-nvim v0.1.1")
5250

53-
-- Autocmd to clean up Grok UI on Neovim exit
51+
-- Clean up Grok UI and buffers on Neovim exit
5452
vim.api.nvim_create_autocmd("VimLeavePre", {
5553
callback = function()
5654
local ui = require("grok.ui")
5755
if ui.current_win and vim.api.nvim_win_is_valid(ui.current_win) then
5856
require("grok.ui").close_chat_window()
5957
end
60-
-- Cleanup any lingering input buffers
6158
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
62-
if vim.api.nvim_buf_get_option(buf, "buftype") == "prompt" then
63-
vim.api.nvim_buf_delete(buf, { force = true })
59+
if vim.api.nvim_buf_is_valid(buf) then
60+
local buftype = vim.api.nvim_buf_get_option(buf, "buftype")
61+
local filetype = vim.api.nvim_buf_get_option(buf, "filetype")
62+
if buftype == "prompt" or filetype == "markdown" then
63+
pcall(vim.api.nvim_buf_delete, buf, { force = true })
64+
end
6465
end
6566
end
67+
log.debug("Cleaned up Grok UI and buffers on VimLeavePre")
6668
end,
67-
desc = "Clean up Grok UI before exiting Neovim",
69+
desc = "Clean up Grok UI and buffers before exiting Neovim",
6870
})
6971
end
7072

lua/grok/ui/window.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,25 @@ local function close_chat_window()
7373
local log = require("grok.log")
7474
local ui = require("grok.ui")
7575
log.info("Closing chat window")
76+
77+
-- Close the main chat window
7678
if ui.current_win and vim.api.nvim_win_is_valid(ui.current_win) then
7779
vim.api.nvim_win_close(ui.current_win, true)
7880
end
81+
82+
-- Delete the main chat buffer
7983
if ui.current_buf and vim.api.nvim_buf_is_valid(ui.current_buf) then
8084
vim.api.nvim_buf_delete(ui.current_buf, { force = true })
8185
end
86+
87+
-- Clean up any lingering prompt buffers
88+
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
89+
if vim.api.nvim_buf_is_valid(buf) and vim.api.nvim_buf_get_option(buf, "buftype") == "prompt" then
90+
pcall(vim.api.nvim_buf_delete, buf, { force = true })
91+
end
92+
end
93+
94+
-- Reset UI state
8295
ui.current_buf = nil
8396
ui.current_win = nil
8497
ui.current_callback = nil

roadmap.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,18 @@ UI Polish - Centered Input + Multi-line Prompts + Auto-scrolling.
164164
- Max length: config.max_prompt_length = 2048 (model-aware defaults)
165165
- Dependencies: Existing ui/window.lua for floating window patterns.
166166
- Test Plan:
167-
- [ ] Input appears centered, scales to 3+ lines
168-
- [ ] Config tab changes position instantly
169-
- [ ] Multi-line input submits correctly
170-
- [ ] Auto-scrolls to bottom on responses
171-
- [ ] Respects max length per model
167+
- [] Input appears centered, scales to 3+ lines
168+
- [] Config tab changes position instantly
169+
- [] Multi-line input submits correctly
170+
- [] Auto-scrolls to bottom on responses
171+
- [ ] Respects max length per model <-- incorrect. we track max chars, not max tokens
172172

173173
**UI Auto-scrolling Enhancement** (Target: 0.1.1)
174174
- Description: Automatically scroll to bottom on new messages.
175175
- Implementation Notes:
176176
- In `ui/render.lua.append_response`: Always set cursor to {line_count, 0}
177177
- In `ui/render.lua.render_tab_content`: Set cursor to bottom for tab 1
178-
- Status: [ ] Not implemented.
178+
- Status: [] Implemented, need to test.
179179
- Dependencies: Existing cursor positioning code.
180180

181181
**Multi-line Input Support** (Target: 0.1.1)
@@ -184,7 +184,7 @@ UI Polish - Centered Input + Multi-line Prompts + Auto-scrolling.
184184
- Create dedicated input buffer/window in `chat/init.lua`
185185
- Keymaps: <CR> = submit, <Esc> = cancel, <C-u> = clear
186186
- Auto-grow height from 3 to 8 lines based on content
187-
- Status: [ ] Not implemented.
187+
- Status: [] Implemented. Need to test.
188188
- Dependencies: ui/window.lua patterns.
189189

190190
**Issue 5: Inconsistent Prompt Box Display** (Target: 0.1.1)
@@ -203,7 +203,7 @@ UI Polish - Centered Input + Multi-line Prompts + Auto-scrolling.
203203
- Problem: Requires :qa! to exit Neovim after using Grok.
204204
- Analysis: Likely unclosed buffers/windows or autocmds; check ui/window.lua close logic.
205205
- Solution: Ensure close_chat_window cleans up properly; add vim.api.nvim_buf_delete on exit.
206-
- Status: [] Verified fixed.
206+
- Status: [ ] Further testing required.
207207

208208
#### v0.1.2
209209
**Config expansions**

0 commit comments

Comments
 (0)