Skip to content

Commit e550019

Browse files
[grok-nvim] 0.1.1-108.1-p: UI polish: working on UI color to match grok prompt UI look/feel
1 parent 11d7c84 commit e550019

File tree

3 files changed

+47
-39
lines changed

3 files changed

+47
-39
lines changed

lua/grok/ui.lua

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,10 @@ M.tabs = { "1: Grok", "2: Keymaps", "3: Config" }
1414
local ui_state = require("grok.ui.state")
1515
M.current_tab = ui_state.state.current_tab
1616

17-
-- Theme-aware highlights
18-
local color = require("grok.ui.color")
19-
local normal_hl = vim.api.nvim_get_hl(0, { name = "Normal" })
20-
local float_hl = vim.api.nvim_get_hl(0, { name = "NormalFloat" })
21-
22-
local user_fg = normal_hl.fg and string.format("#%06x", normal_hl.fg) or "#c0caf5" -- Lightish blue-grey fallback
23-
local grok_bg_hex = float_hl.bg and string.format("#%06x", float_hl.bg) or "#1e1e1e" -- Dark fallback
24-
local grok_bg_dark = color.darken_color(grok_bg_hex, 0.8) -- Darken by 20%
25-
local grok_fg = float_hl.fg and string.format("#%06x", float_hl.fg) or "#ffffff"
26-
27-
vim.api.nvim_set_hl(0, "GrokUser", { fg = user_fg }) -- Lighter fg for user
28-
vim.api.nvim_set_hl(0, "GrokAssistant", { bg = grok_bg_dark, fg = grok_fg }) -- Darker bg for Grok
17+
-- Fixed highlights for v0.1.1 polish
18+
vim.api.nvim_set_hl(0, "GrokUser", { bg = "#333333", fg = "#ffffff" }) -- Charcoal gray bg, white fg for user
19+
vim.api.nvim_set_hl(0, "GrokAssistant", { bg = "#1a1a1a", fg = "#ffffff" }) -- Dark black bg, white fg for Grok
20+
vim.api.nvim_set_hl(0, "GrokChatWindow", { bg = "#2d2d2d" }) -- Neutral chat window bg (dark grey)
2921

3022
M.open_chat_window = require("grok.ui.window").open_chat_window
3123
M.append_response = require("grok.ui.render").append_response

lua/grok/ui/render.lua

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,23 @@ local function render_tab_header(buf)
1111
end
1212

1313
local function render_tab_content(buf, callback)
14-
local history = require("grok.chat.history").get() -- For re-rendering (Issue 1)
14+
local history = require("grok.chat.history").get() -- For re-rendering
1515
vim.api.nvim_buf_set_option(buf, "modifiable", true)
16-
vim.api.nvim_buf_set_lines(buf, 1, -1, false, {})
16+
vim.api.nvim_buf_set_lines(buf, 0, -1, false, {})
1717
vim.cmd("stopinsert")
18+
19+
-- Apply chat window background
20+
vim.api.nvim_set_option_value("winhl", "Normal:GrokChatWindow", { win = require("grok.ui").current_win })
21+
1822
if require("grok.ui").current_tab == 1 then -- Grok
1923
local chat_lines = {}
24+
local line_idx = 1 -- Track buffer line for highlighting
2025
for _, msg in ipairs(history) do
2126
local role = msg.role == "user" and "You" or "Grok"
2227
local content_lines = vim.split(msg.content, "\n", { plain = true })
2328
table.insert(chat_lines, role .. ": " .. (content_lines[1] or ""))
2429
for i = 2, #content_lines do
25-
table.insert(chat_lines, " " .. content_lines[i])
30+
table.insert(chat_lines, " " .. content_lines[i]) -- Indent continuation lines
2631
end
2732
table.insert(chat_lines, "")
2833
end
@@ -31,6 +36,19 @@ local function render_tab_content(buf, callback)
3136
table.insert(chat_lines, "")
3237
end
3338
vim.api.nvim_buf_set_lines(buf, 1, -1, false, chat_lines)
39+
40+
-- Apply highlights per message block
41+
local current_line = 1
42+
for _, msg in ipairs(history) do
43+
local role = msg.role
44+
local msg_lines = #vim.split(msg.content, "\n", { plain = true }) + 1 -- +1 for empty line
45+
local hl_group = (role == "user") and "GrokUser" or "GrokAssistant"
46+
for i = 0, msg_lines - 1 do
47+
vim.api.nvim_buf_add_highlight(buf, require("grok.ui").ns, hl_group, current_line + i - 1, 0, -1)
48+
end
49+
current_line = current_line + msg_lines
50+
end
51+
3452
if require("grok.ui").current_win and vim.api.nvim_win_is_valid(require("grok.ui").current_win) then
3553
require("grok.util").auto_scroll(buf, require("grok.ui").current_win) -- v0.1.1 Auto-scroll
3654
end
@@ -57,10 +75,9 @@ local function render_tab_content(buf, callback)
5775
" Max Tokens: " .. config.max_tokens,
5876
" Debug: " .. tostring(config.debug),
5977
" Prompt Position: " .. config.prompt_position, -- v0.1.1 Visible UI option
60-
-- TODO: Add more; make editable? For real-time, use autocmd on BufLeave
6178
}
6279
end
63-
vim.api.nvim_buf_set_lines(buf, -1, -1, false, content_lines)
80+
vim.api.nvim_buf_set_lines(buf, 1, -1, false, content_lines)
6481
render_tab_header(buf) -- Refresh header before locking
6582
vim.api.nvim_buf_set_option(buf, "modifiable", false) -- Lock non-chat tabs
6683
end
@@ -86,6 +103,14 @@ local function append_response(text)
86103
local lines = vim.split(new_text, "\n", { plain = true })
87104
vim.api.nvim_buf_set_lines(require("grok.ui").current_buf, line_count - 1, line_count, false, lines)
88105
require("grok.util").auto_scroll(require("grok.ui").current_buf, require("grok.ui").current_win) -- v0.1.1 Auto-scroll
106+
vim.api.nvim_buf_add_highlight(
107+
require("grok.ui").current_buf,
108+
require("grok.ui").ns,
109+
"GrokAssistant",
110+
line_count - 1,
111+
0,
112+
-1
113+
)
89114
vim.api.nvim_buf_set_option(require("grok.ui").current_buf, "modifiable", false)
90115
end)
91116
if not ok then

lua/grok/util.lua

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,8 @@ function M.create_floating_input(opts)
6060
local buf = vim.api.nvim_create_buf(false, true)
6161
local width = math.floor(vim.o.columns * 0.6)
6262
local height = 3
63-
local row, col
64-
if config.prompt_position == "left" then
65-
row = math.floor(vim.o.lines * 0.1)
66-
col = math.floor(vim.o.columns * 0.1)
67-
elseif config.prompt_position == "right" then
68-
row = math.floor(vim.o.lines * 0.1)
69-
col = math.floor(vim.o.columns * 0.9 - width)
70-
else -- center
71-
row = math.floor((vim.o.lines - height) / 2)
72-
col = math.floor((vim.o.columns - width) / 2)
73-
end
63+
local row = math.floor(vim.o.lines - height - 2) -- Bottom-aligned, 2 lines from edge
64+
local col = math.floor((vim.o.columns - width) / 2) -- Centered horizontally
7465
local win_opts = {
7566
relative = "editor",
7667
width = width,
@@ -84,22 +75,18 @@ function M.create_floating_input(opts)
8475
local win = vim.api.nvim_open_win(buf, true, win_opts)
8576
vim.api.nvim_buf_set_option(buf, "modifiable", true)
8677
vim.api.nvim_buf_set_option(buf, "buftype", "prompt")
87-
-- Clear any existing text
8878
vim.fn.prompt_setprompt(buf, "")
8979
log.debug("Prompt set to empty string")
9080
vim.api.nvim_buf_set_lines(buf, 0, -1, false, {})
91-
-- Store callback in buffer variable
9281
if opts.callback then
9382
vim.api.nvim_buf_set_var(buf, "grok_callback", opts.callback)
9483
end
95-
-- Char counter autocmd with window validity check
9684
local char_count = 0
9785
local autocmd_id = vim.api.nvim_create_autocmd({ "TextChanged", "TextChangedI" }, {
9886
buffer = buf,
9987
callback = function()
100-
-- Check if window is still valid
10188
if not vim.api.nvim_win_is_valid(win) then
102-
return true -- Returning true removes the autocmd
89+
return true
10390
end
10491
local text = table.concat(vim.api.nvim_buf_get_lines(buf, 0, -1, false), "\n")
10592
char_count = #text
@@ -113,21 +100,17 @@ function M.create_floating_input(opts)
113100
if new_height ~= height then
114101
height = new_height
115102
win_opts.height = height
116-
if config.prompt_position == "center" then
117-
win_opts.row = math.floor((vim.o.lines - height) / 2)
118-
end
103+
win_opts.row = math.floor(vim.o.lines - height - 2) -- Recalculate bottom row
119104
vim.api.nvim_win_set_config(win, win_opts)
120105
end
121106
end,
122107
})
123-
-- Clean up autocmd when buffer is deleted
124108
vim.api.nvim_create_autocmd("BufWipeout", {
125109
buffer = buf,
126110
callback = function()
127111
vim.api.nvim_del_autocmd(autocmd_id)
128112
end,
129113
})
130-
-- Keymaps for input
131114
vim.api.nvim_buf_set_keymap(
132115
buf,
133116
"i",
@@ -149,10 +132,18 @@ function M.create_floating_input(opts)
149132
"<cmd>lua vim.api.nvim_buf_set_lines(0, 0, -1, false, {})<CR>",
150133
{ noremap = true, silent = true }
151134
)
152-
-- Explicitly enter insert mode cleanly
153135
vim.api.nvim_command("startinsert")
154136
end
155137

138+
function M.submit_input()
139+
local buf = vim.api.nvim_get_current_buf()
140+
local text = table.concat(vim.api.nvim_buf_get_lines(buf, 0, -1, false), "\n")
141+
local ok, callback = pcall(vim.api.nvim_buf_get_var, buf, "grok_callback")
142+
vim.api.nvim_win_close(0, true)
143+
if ok and callback then
144+
callback(text)
145+
end
146+
end
156147
function M.submit_input()
157148
local buf = vim.api.nvim_get_current_buf()
158149
local text = table.concat(vim.api.nvim_buf_get_lines(buf, 0, -1, false), "\n")

0 commit comments

Comments
 (0)