Skip to content

Commit da7a28b

Browse files
committed
update default headers to match eca-emacs UI
1 parent d36ede9 commit da7a28b

File tree

2 files changed

+58
-6
lines changed

2 files changed

+58
-6
lines changed

lua/eca/config.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ M._defaults = {
4545
},
4646
chat = {
4747
headers = {
48-
user = "## 👤 You\n\n",
49-
assistant = "## 🤖 ECA\n\n",
48+
user = "> ",
49+
assistant = "",
5050
},
5151
},
5252
windows = {

lua/eca/sidebar.lua

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ function M.new(id, mediator)
6262
instance._response_start_time = 0
6363
instance._max_response_length = 50000 -- 50KB max response
6464
instance._headers = {
65-
user = (Config.chat and Config.chat.headers and Config.chat.headers.user) or "## 👤 You\n\n",
66-
assistant = (Config.chat and Config.chat.headers and Config.chat.headers.assistant) or "## 🤖 ECA\n\n",
65+
user = (Config.chat and Config.chat.headers and Config.chat.headers.user) or "> ",
66+
assistant = (Config.chat and Config.chat.headers and Config.chat.headers.assistant) or "",
6767
}
6868

6969
require("eca.observer").subscribe("sidebar-" .. id, function(message)
@@ -1376,8 +1376,32 @@ function M:_handle_streaming_text(text)
13761376
-- Start streaming - simple and direct
13771377
self._is_streaming = true
13781378
self._current_response_buffer = ""
1379+
1380+
-- Determine insertion point before adding placeholder (works even with empty header)
1381+
local chat = self.containers.chat
1382+
local start_line = 1
1383+
if chat and vim.api.nvim_buf_is_valid(chat.bufnr) then
1384+
start_line = vim.api.nvim_buf_line_count(chat.bufnr) + 1
1385+
end
1386+
1387+
-- Add assistant placeholder and track its start line
13791388
self:_add_message("assistant", "")
1380-
self._last_assistant_line = self:_get_last_message_line()
1389+
self._last_assistant_line = start_line
1390+
1391+
-- Track placeholder with an extmark independent of header content
1392+
self.extmarks = self.extmarks or {}
1393+
if not self.extmarks.assistant then
1394+
self.extmarks.assistant = { _ns = vim.api.nvim_create_namespace('extmarks_assistant') }
1395+
end
1396+
if chat and vim.api.nvim_buf_is_valid(chat.bufnr) then
1397+
self.extmarks.assistant._id = vim.api.nvim_buf_set_extmark(
1398+
chat.bufnr,
1399+
self.extmarks.assistant._ns,
1400+
start_line - 1,
1401+
0,
1402+
{ id = self.extmarks.assistant._id }
1403+
)
1404+
end
13811405
end
13821406

13831407
-- Simple accumulation - no complex checks
@@ -1415,9 +1439,17 @@ function M:_update_streaming_message(content)
14151439
-- Get current lines
14161440
local lines = vim.api.nvim_buf_get_lines(chat.bufnr, 0, -1, false)
14171441
local content_lines = Utils.split_lines(content)
1442+
1443+
-- Resolve assistant start line using extmark if available
14181444
local start_line = self._last_assistant_line
1445+
if self.extmarks and self.extmarks.assistant and self.extmarks.assistant._id then
1446+
local pos = vim.api.nvim_buf_get_extmark_by_id(chat.bufnr, self.extmarks.assistant._ns, self.extmarks.assistant._id, {})
1447+
if pos and pos[1] then
1448+
start_line = pos[1] + 1
1449+
end
1450+
end
14191451

1420-
Logger.debug("DEBUG: Assistant line: " .. self._last_assistant_line .. ", start_line: " .. start_line)
1452+
Logger.debug("DEBUG: Assistant line: " .. tostring(self._last_assistant_line) .. ", start_line: " .. tostring(start_line))
14211453
Logger.debug("DEBUG: Content lines: " .. #content_lines)
14221454

14231455
-- Replace assistant content directly
@@ -1439,6 +1471,19 @@ function M:_update_streaming_message(content)
14391471
-- Set all lines at once
14401472
vim.api.nvim_buf_set_lines(chat.bufnr, 0, -1, false, new_lines)
14411473

1474+
-- Re-anchor the assistant extmark at the start line (for subsequent updates)
1475+
self.extmarks = self.extmarks or {}
1476+
if not self.extmarks.assistant then
1477+
self.extmarks.assistant = { _ns = vim.api.nvim_create_namespace('extmarks_assistant') }
1478+
end
1479+
self.extmarks.assistant._id = vim.api.nvim_buf_set_extmark(
1480+
chat.bufnr,
1481+
self.extmarks.assistant._ns,
1482+
start_line - 1,
1483+
0,
1484+
{ id = self.extmarks.assistant._id }
1485+
)
1486+
14421487
Logger.debug("DEBUG: Buffer updated successfully with " .. #new_lines .. " total lines")
14431488
end)
14441489

@@ -1520,6 +1565,13 @@ function M:_finalize_streaming_response()
15201565
self._last_assistant_line = 0
15211566
self._response_start_time = 0
15221567

1568+
-- Clear assistant placeholder tracking extmark
1569+
local chat = self.containers.chat
1570+
if chat and vim.api.nvim_buf_is_valid(chat.bufnr) and self.extmarks and self.extmarks.assistant then
1571+
pcall(vim.api.nvim_buf_clear_namespace, chat.bufnr, self.extmarks.assistant._ns, 0, -1)
1572+
self.extmarks.assistant._id = nil
1573+
end
1574+
15231575
Logger.debug("DEBUG: Streaming state cleared")
15241576
else
15251577
Logger.debug("DEBUG: _finalize_streaming_response called but not streaming")

0 commit comments

Comments
 (0)