is it possible to run code in a NuiLine? (I'd need to count time in a field) #325
-
Hi :) I'm not sure but I tought I'd ask. I'd like to count time since the NuiLine was added to NuiTree. Starting from I there a way to embed some code in it (I guess no since it's a string)? or to update each line every second (madness :P)? ref: andreacfromtheapp/chuck-nvim#8 I promise to keep this short. Please and thank you |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
something like this (work in progress): -- FIX: idea to show the elapsed time of each shred since each addition
-- https://stackoverflow.com/questions/30424431/how-to-implement-a-stopwatch-in-lua
local function timer()
local start = os.time()
return os.date("%M:%S", os.difftime(os.time(), start))
end M.shreds_tree = NuiTree({
bufnr = M.shred_pane.bufnr,
nodes = {},
get_node_id = function(node)
if node.id then
return node.id
end
end,
prepare_node = function(node)
return NuiLine({
NuiText("id: "),
NuiText(tostring(node.id), "DiagnosticOk"),
NuiText(" "),
NuiText("name: "),
NuiText(node.name, "DiagnosticOk"),
NuiText(" "),
NuiText("time: "),
NuiText(timer(), "DiagnosticOk"),
})
end,
}) |
Beta Was this translation helpful? Give feedback.
-
Check |
Beta Was this translation helpful? Give feedback.
Check
:help timer
. You'll need to runtree:render()
on regular interval.