Skip to content

Commit

Permalink
feat: marquee size, show models
Browse files Browse the repository at this point in the history
  • Loading branch information
gsuuon committed Dec 10, 2023
1 parent d707091 commit b26afbb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
6 changes: 4 additions & 2 deletions lua/model/providers/llamacpp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ function M.request_completion(handlers, params, options)

if valid then
stop_marquee = juice.handler_marquee_or_notify(
'llama.cpp server starting',
handlers.segment
'llama.cpp: ' .. opts.model,
handlers.segment,
nil,
20
)
wait(M.start_server(opts.model, opts.args, resolve))
stop_marquee()
Expand Down
6 changes: 4 additions & 2 deletions lua/model/providers/ollama.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ return {
request_completion = function (handlers, params)

local stop_marquee = juice.handler_marquee_or_notify(
'ollama',
handlers.segment
'ollama: ' .. params.model,
handlers.segment,
nil,
20
)

return curl.stream(
Expand Down
13 changes: 9 additions & 4 deletions lua/model/util/juice.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local segment = require('model.util.segment')

local M = {}

function M.scroll(text, rate, set)
function M.scroll(text, rate, set, size)
local run = true

local function scroll_(t)
Expand All @@ -12,7 +12,11 @@ function M.scroll(text, rate, set)
local tail = t:sub(2, #t)
local text_ = tail .. head

set('<' .. text_ .. '>')
if size then
set('<' .. text_:sub(1, size) .. '>')
else
set('<' .. text_ .. '>')
end

return scroll_(text_)
end
Expand All @@ -35,16 +39,17 @@ end
--- @param text string The text to display either as a marquee or notification.
--- @param seg? Segment segment to place the marquee after
--- @param hl? string Optional highlight group for the marquee segment. Defaults to 'Comment'.
--- @param size? number Limit marquee size
--- @return function stop stop and clear the marquee
function M.handler_marquee_or_notify(text, seg, hl)
function M.handler_marquee_or_notify(text, seg, hl, size)
if seg then
local handler_seg = seg.details()
local pending = segment.create_segment_at(
handler_seg.details.end_row,
handler_seg.details.end_col,
hl or 'Comment'
)
return M.scroll(text .. ' ', 160, pending.set_virt)
return M.scroll(text .. ' ', 160, pending.set_virt, size)
else
vim.notify(text)
end
Expand Down

0 comments on commit b26afbb

Please sign in to comment.