The IDE starts with the tree open on the left and LLeMbas's settings, chat and prompt on the right, the state on top and the keys for where the focus is at the bottom. Its cheat sheet and README read LLeMbas's keys from the plugin's key table; the statusline and the line of buffers stand in when a bar is switched off; a session saves the code's windows only. Tests at 160x45, 100x30 and 80x24 on the installed IDE's own screen. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
191 lines
8.2 KiB
Lua
191 lines
8.2 KiB
Lua
-- Visual design, highlights, floating cards and formatting helpers for llembas.nvim.
|
|
-- Every colour links to standard Neovim highlight groups with `default = true`, so any
|
|
-- colorscheme looks cohesive and users can override individual `LLeMbas*` groups.
|
|
local M = {}
|
|
|
|
local HIGHLIGHTS = {
|
|
LLeMbasBrand = { link = "Special" },
|
|
LLeMbasUserHeader = { link = "Title" },
|
|
LLeMbasAgentHeader = { link = "Function" },
|
|
LLeMbasThoughtHeader = { link = "Comment" },
|
|
LLeMbasThought = { link = "Comment" },
|
|
LLeMbasToolPending = { link = "DiagnosticWarn" },
|
|
LLeMbasToolDone = { link = "DiagnosticOk" },
|
|
LLeMbasToolFail = { link = "DiagnosticError" },
|
|
LLeMbasToolDenied = { link = "DiagnosticWarn" },
|
|
LLeMbasToolKind = { link = "Tag" },
|
|
LLeMbasToolMeta = { link = "Comment" },
|
|
LLeMbasPlanHeader = { link = "Title" },
|
|
LLeMbasPlanBar = { link = "DiagnosticOk" },
|
|
LLeMbasPlanDone = { link = "DiagnosticOk" },
|
|
LLeMbasPlanActive = { link = "DiagnosticInfo" },
|
|
LLeMbasPlanPending = { link = "Comment" },
|
|
LLeMbasNote = { link = "Comment" },
|
|
LLeMbasWarn = { link = "DiagnosticWarn" },
|
|
LLeMbasError = { link = "DiagnosticError" },
|
|
LLeMbasDiffAdd = { link = "DiffAdd" },
|
|
LLeMbasDiffDelete = { link = "DiffDelete" },
|
|
LLeMbasDiffHint = { link = "DiagnosticVirtualTextInfo" },
|
|
LLeMbasGhost = { link = "Comment" },
|
|
LLeMbasSeparator = { link = "WinSeparator" },
|
|
LLeMbasStatusBrand = { link = "Special" },
|
|
LLeMbasStatusMode = { link = "DiagnosticInfo" },
|
|
LLeMbasStatusModel = { link = "Comment" },
|
|
LLeMbasStatusBusy = { link = "DiagnosticWarn" },
|
|
LLeMbasStatusAttach = { link = "DiagnosticHint" },
|
|
-- The bars.
|
|
LLeMbasBar = { link = "StatusLine" },
|
|
LLeMbasBarVim = { link = "StatusLine" },
|
|
-- The prompt and the settings lines.
|
|
LLeMbasPromptPrefix = { link = "Special" },
|
|
LLeMbasChip = { link = "DiagnosticHint" },
|
|
LLeMbasLineLabel = { link = "Comment" },
|
|
LLeMbasLineValue = { link = "Normal" },
|
|
LLeMbasLineOff = { link = "Comment" },
|
|
LLeMbasLineCurrent = { link = "Title" },
|
|
-- The tree.
|
|
LLeMbasTreeDirectory = { link = "Directory" },
|
|
LLeMbasTreeCurrent = { link = "Visual" },
|
|
LLeMbasTreeChanged = { link = "DiagnosticWarn" },
|
|
LLeMbasTreeAdded = { link = "DiagnosticOk" },
|
|
LLeMbasTreeNew = { link = "DiagnosticHint" },
|
|
LLeMbasTreeDeleted = { link = "DiagnosticError" },
|
|
LLeMbasTreeConflict = { link = "DiagnosticError" },
|
|
}
|
|
|
|
-- The coloured cells of the bars: each takes its colour from a standard group and its ground
|
|
-- from StatusLine, so that a row of cells has one ground whatever the colourscheme.
|
|
local BAR_CELLS = {
|
|
LLeMbasBarKey = "Special", LLeMbasBarTitle = "Title", LLeMbasBarSeparator = "WinSeparator", LLeMbasBarFact = "Comment",
|
|
LLeMbasBarIdle = "DiagnosticOk", LLeMbasBarBusy = "DiagnosticWarn", LLeMbasBarWaiting = "DiagnosticInfo", LLeMbasBarOff = "Comment",
|
|
}
|
|
|
|
local function bar_cells()
|
|
local base = vim.api.nvim_get_hl(0, { name = "StatusLine", link = false })
|
|
local fg, bg = base.fg, base.bg
|
|
if base.reverse then fg, bg = bg, fg end
|
|
for name, from in pairs(BAR_CELLS) do
|
|
local own = vim.api.nvim_get_hl(0, { name = from, link = false })
|
|
vim.api.nvim_set_hl(0, name, { default = true, fg = own.fg or fg, bg = bg, bold = own.bold, italic = own.italic })
|
|
end
|
|
end
|
|
|
|
local hi_installed = false
|
|
|
|
function M.setup_highlights()
|
|
for name, spec in pairs(HIGHLIGHTS) do
|
|
vim.api.nvim_set_hl(0, name, vim.tbl_extend("force", { default = true }, spec))
|
|
end
|
|
bar_cells()
|
|
if not hi_installed then
|
|
hi_installed = true
|
|
local group = vim.api.nvim_create_augroup("llembas-highlights", { clear = true })
|
|
vim.api.nvim_create_autocmd("ColorScheme", {
|
|
group = group,
|
|
callback = function()
|
|
for name, spec in pairs(HIGHLIGHTS) do
|
|
vim.api.nvim_set_hl(0, name, vim.tbl_extend("force", { default = true }, spec))
|
|
end
|
|
bar_cells()
|
|
end,
|
|
})
|
|
end
|
|
end
|
|
|
|
function M.format_tokens(n)
|
|
local v = tonumber(n) or 0
|
|
if v >= 1000000 then return ("%.1fM"):format(v / 1000000) end
|
|
if v >= 1000 then return ("%.1fk"):format(v / 1000) end
|
|
return tostring(math.floor(v))
|
|
end
|
|
|
|
function M.format_ms(ms)
|
|
local v = tonumber(ms)
|
|
if not v or v < 0 then return "" end
|
|
if v < 1000 then return ("%dms"):format(math.floor(v + 0.5)) end
|
|
return ("%.1fs"):format(v / 1000)
|
|
end
|
|
|
|
function M.progress_bar(done, total, width)
|
|
width = width or 12
|
|
if not total or total <= 0 then return "" end
|
|
local ratio = math.max(0, math.min(1, done / total))
|
|
local filled = math.floor(ratio * width + 0.5)
|
|
return "[" .. string.rep("█", filled) .. string.rep("░", width - filled) .. "]"
|
|
end
|
|
|
|
--- Welcome virtual lines shown in an empty transcript (never written to the buffer text).
|
|
function M.welcome_virt_lines(narrow)
|
|
if narrow then
|
|
-- For a bar of 34 columns: no line is wider than 32.
|
|
return {
|
|
{ { "", "Normal" } },
|
|
{ { " ◈ ", "LLeMbasBrand" }, { "LLeMbas", "LLeMbasUserHeader" } },
|
|
{ { " Waybread for the code ahead.", "LLeMbasNote" } },
|
|
{ { "", "Normal" } },
|
|
{ { " Type below; Enter sends.", "LLeMbasNote" } },
|
|
{ { " Tab: ask, rewrite or add.", "LLeMbasNote" } },
|
|
}
|
|
end
|
|
return {
|
|
{ { "", "Normal" } },
|
|
{ { " ◈ ", "LLeMbasBrand" }, { "LLeMbas", "LLeMbasUserHeader" }, { " · Waybread for the code ahead.", "LLeMbasNote" } },
|
|
{ { " ────────────────────────────────────────────", "LLeMbasSeparator" } },
|
|
{ { " Prompt: ", "LLeMbasNote" }, { "<CR>/<C-s>", "LLeMbasToolKind" }, { " send ", "LLeMbasNote" }, { "<C-c>", "LLeMbasToolKind" }, { " stop ", "LLeMbasNote" }, { "q", "LLeMbasToolKind" }, { " close", "LLeMbasNote" } },
|
|
{ { " Chat: ", "LLeMbasNote" }, { "<CR>/gf", "LLeMbasToolKind" }, { " open file ", "LLeMbasNote" }, { "K", "LLeMbasToolKind" }, { " output ", "LLeMbasNote" }, { "y", "LLeMbasToolKind" }, { " yank code ", "LLeMbasNote" }, { "g?", "LLeMbasToolKind" }, { " help", "LLeMbasNote" } },
|
|
{ { " Tools: ", "LLeMbasNote" }, { ":LLeMbasAsk", "LLeMbasAgentHeader" }, { " ", "Normal" }, { ":LLeMbasEdit", "LLeMbasAgentHeader" }, { " ", "Normal" }, { ":LLeMbasGenerate", "LLeMbasAgentHeader" }, { " ", "Normal" }, { ":LLeMbasFiles", "LLeMbasAgentHeader" } },
|
|
{ { " Models: ", "LLeMbasNote" }, { ":LLeMbasAutocompleteTokens", "LLeMbasAgentHeader" }, { " ", "Normal" }, { ":LLeMbasSessions", "LLeMbasAgentHeader" } },
|
|
}
|
|
end
|
|
|
|
--- Open a read-only floating window with rounded borders (`q` or `<Esc>` closes).
|
|
function M.float(title, lines, opts)
|
|
opts = opts or {}
|
|
local flat = {}
|
|
for _, l in ipairs(lines) do
|
|
for _, part in ipairs(vim.split(tostring(l), "\n", { plain = true })) do flat[#flat + 1] = (part:gsub("\r", "")) end
|
|
end
|
|
lines = flat
|
|
local b = vim.api.nvim_create_buf(false, true)
|
|
vim.bo[b].buftype = "nofile"
|
|
vim.bo[b].bufhidden = "wipe"
|
|
vim.bo[b].swapfile = false
|
|
vim.bo[b].modeline = false
|
|
vim.bo[b].undolevels = -1
|
|
vim.api.nvim_buf_set_lines(b, 0, -1, false, lines)
|
|
if opts.filetype then vim.bo[b].filetype = opts.filetype end
|
|
vim.bo[b].modifiable = false
|
|
|
|
local max_w = 0
|
|
for _, l in ipairs(lines) do
|
|
local w = vim.fn.strdisplaywidth(l)
|
|
if w > max_w then max_w = w end
|
|
end
|
|
local ui = vim.api.nvim_list_uis()[1]
|
|
local cols = (ui and ui.width) or vim.o.columns or 100
|
|
local rows = (ui and ui.height) or vim.o.lines or 30
|
|
local width = math.min(math.max(max_w + 4, 44), math.max(44, math.floor(cols * 0.8)))
|
|
local height = math.min(math.max(#lines, 4), math.max(6, math.floor(rows * 0.7)))
|
|
local win = vim.api.nvim_open_win(b, opts.enter ~= false, {
|
|
relative = "editor",
|
|
width = width,
|
|
height = height,
|
|
row = math.max(1, math.floor((rows - height) / 2) - 1),
|
|
col = math.max(1, math.floor((cols - width) / 2)),
|
|
style = "minimal",
|
|
border = opts.border or "rounded",
|
|
title = title and (" " .. title .. " ") or nil,
|
|
title_pos = title and "center" or nil,
|
|
})
|
|
vim.wo[win].wrap = true
|
|
vim.wo[win].linebreak = true
|
|
local function close()
|
|
if vim.api.nvim_win_is_valid(win) then pcall(vim.api.nvim_win_close, win, true) end
|
|
end
|
|
vim.keymap.set("n", "q", close, { buffer = b, nowait = true, desc = "LLeMbas: close window" })
|
|
vim.keymap.set("n", "<Esc>", close, { buffer = b, nowait = true, desc = "LLeMbas: close window" })
|
|
return win, close
|
|
end
|
|
|
|
return M
|