-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show code stats in status bar #110
Comments
I did a function (in lua) to get this, but the delay is too long
|
@m4thewz that's painfully blocking, this needs to be done asynchronously. |
I managed to do it with this code: local uv = require("luv")
local current_time = ""
local function set_interval(interval, callback)
local timer = uv.new_timer()
local function ontimeout()
callback(timer)
end
uv.timer_start(timer, interval, interval, ontimeout)
return timer
end
local function update_wakatime()
local stdin = uv.new_pipe()
local stdout = uv.new_pipe()
local stderr = uv.new_pipe()
local handle, pid =
uv.spawn(
"wakatime",
{
args = {"--today"},
stdio = {stdin, stdout, stderr}
},
function(code, signal) -- on exit
stdin:close()
stdout:close()
stderr:close()
end
)
uv.read_start(
stdout,
function(err, data)
assert(not err, err)
if data then
current_time = "🅆 " .. data:sub(1, #data - 2) .. " "
end
end
)
end
set_interval(5000, update_wakatime)
local function get_wakatime()
return current_time
end put it somewhere then you can use it in your status bar like: require("lualine").setup {
...
lualine_y = {"filetype", "progress", get_wakatime},
...} |
Here's my version* based on @smezzy's (note that mine requires https://github.com/nvim-lua/plenary.nvim) local Job = require("plenary.job")
local async = require("plenary.async")
local get_wakatime_time = function()
local tx, rx = async.control.channel.oneshot()
local ok, job = pcall(Job.new, Job, {
command = os.getenv("HOME") .. "/.wakatime/wakatime-cli",
args = { "--today" },
on_exit = function(j, _) tx(j:result()[1] or "") end,
})
if not ok then
vim.notify("Bad WakaTime call: " .. job, "warn")
return ""
end
job:start()
return rx()
end
---@diagnostic disable
local state = { comp_wakatime_time = "" }
-- Yield statusline value
local wakatime = function()
local WAKATIME_UPDATE_INTERVAL = 10000
if not Wakatime_routine_init then
local timer = uv.new_timer()
if timer == nil then return "" end
-- Update wakatime every 10s
uv.timer_start(timer, 500, WAKATIME_UPDATE_INTERVAL, function()
async.run(get_wakatime_time, function(time) state.comp_wakatime_time = time end)
end)
Wakatime_routine_init = true
end
return state.comp_wakatime_time
end And the lualine component: {
components.wakatime,
cond = function() return vim.g["loaded_wakatime"] == 1 end,
icon = "",
color = { bg = COLORS.bg, fg = COLORS.cyan },
} |
Instead of calling |
I believe |
Yes, there's also |
FWIW, unless a vim command is writing directly to vim's stdout (and it almost never should be as this will ruin the TUI/display), you can usually capture a command's output with vim's -- This should be silent and should capture the cmd's output into the `output` variable.
-- `output` is a string.
local output = vim.api.nvim_cmd({ cmd = "WakaTimeToday" }, { output = true }) There's also |
Hi,
How I can put the value from :WakaTimeToday on my status line?
The text was updated successfully, but these errors were encountered: