@@ -4,19 +4,32 @@ local M = {}
44function M .setup_commands ()
55 local log = require (" grok.log" )
66 vim .api .nvim_create_user_command (" Grok" , function (opts )
7- require (" grok.chat" ).chat (opts .args )
7+ require (" grok.ui" ).open_chat_window (function (input )
8+ require (" grok.chat" ).chat (input )
9+ end )
10+ if opts .args and opts .args ~= " " then
11+ require (" grok.chat" ).chat (opts .args )
12+ end
813 log .debug (" Grok command executed with args: " .. vim .inspect (opts .args ))
914 end , { nargs = " *" , desc = " Chat with Grok" })
1015 vim .api .nvim_create_user_command (" GrokVisual" , function ()
1116 local selected_text = require (" grok.util" ).get_visual_selection ()
17+ require (" grok.ui" ).open_chat_window (function (input )
18+ require (" grok.chat" ).chat (input )
19+ end )
1220 require (" grok.chat" ).chat (selected_text )
1321 log .debug (" GrokVisual command executed with selection: " .. selected_text )
1422 end , { range = true , desc = " Chat with Grok using visual selection" })
1523 vim .api .nvim_create_user_command (" GrokClear" , function ()
16- require (" grok.ui" ).close_chat_window ()
1724 require (" grok.chat" ).clear_history ()
25+ local ui = require (" grok.ui" )
26+ if ui .current_buf and vim .api .nvim_buf_is_valid (ui .current_buf ) then
27+ require (" grok.ui.render" ).render_tab_content (ui .current_buf , function (input )
28+ require (" grok.chat" ).chat (input )
29+ end )
30+ end
1831 log .info (" GrokClear command executed" )
19- end , { desc = " Clear and close Grok chat window " })
32+ end , { desc = " Clear Grok chat history " })
2033 vim .api .nvim_create_user_command (" GrokLog" , function ()
2134 local log_file = vim .fn .stdpath (" data" ) .. " /grok.log"
2235 vim .cmd (" edit " .. log_file )
@@ -25,18 +38,19 @@ function M.setup_commands()
2538 vim .api .nvim_create_user_command (" GrokKeymaps" , function ()
2639 local ui = require (" grok.ui" )
2740 if ui .current_win and vim .api .nvim_win_is_valid (ui .current_win ) then
28- ui .current_tab = 2
41+ ui .set_current_tab ( 2 )
2942 require (" grok.ui.render" ).render_tab_content (ui .current_buf , function () end )
3043 log .debug (" GrokKeymaps switched to tab 2 in UI" )
3144 else
32- local keymaps = {
33- " In Grok Chat Window:" ,
34- " <CR> or i: Open input prompt" ,
35- " <Esc>: Close window" ,
36- }
37- vim .notify (table.concat (keymaps , " \n " ), vim .log .levels .INFO )
38- log .debug (" GrokKeymaps notified keymaps" )
45+ ui .open_chat_window (function () end )
46+ ui .set_current_tab (2 )
47+ require (" grok.ui.render" ).render_tab_content (ui .current_buf , function () end )
48+ log .debug (" GrokKeymaps opened UI and switched to tab 2" )
3949 end
40- end , { desc = " List Grok-nvim keymaps" })
50+ end , { desc = " Show Grok-nvim keymaps" })
51+ vim .api .nvim_create_user_command (" GrokUI" , function ()
52+ require (" grok.ui" ).toggle_ui ()
53+ log .debug (" GrokUI command executed" )
54+ end , { desc = " Toggle Grok UI" })
4155end
4256return M
0 commit comments