diff --git a/lua/timer.lua b/lua/timer.lua index 83b48c4..54b5443 100644 --- a/lua/timer.lua +++ b/lua/timer.lua @@ -1,4 +1,3 @@ -local TOML = require("toml") function trim(s) return (s:gsub("^%s*(.-)%s*$", "%1")) end @@ -12,7 +11,6 @@ local clean_to = 1 local function clean_from(from, events) - local to = 1 local clean_events = {} -- coppy until from @@ -106,7 +104,7 @@ local function log_total_time() -- if file exists read if file ~= nil then - local history = TOML.parse(file:read("*a")) + local history = require("toml").parse(file:read("*a")) file:close() @@ -148,11 +146,11 @@ end local function persist() + local TOML = require("toml") local today = os.date("%y-%m-%d", os.time()) local table = {} local file = io.open(filename, "r") - -- if file exists read if file ~= nil then table = TOML.parse(file:read("*a")) @@ -176,8 +174,11 @@ local function persist() return end - file:write("## dates and their corresponding seconds been here :)\n", TOML.encode(table), "\n") - file.close() + local tml = TOML.encode(table) + print(tml) + + file:write("## dates and their corresponding seconds been here :)\n", tml, "\n") + file:close() --reset timer clean_to = 1 @@ -194,17 +195,17 @@ local function setup() vim.api.nvim_create_autocmd("FocusLost", { group = augroup, callback = focus_lost }) vim.api.nvim_create_user_command( - 'Timer', -- The name of the command (accessible via :TimerStart) + 'Timer', log_total_time, { nargs = 0 } -- No arguments for this command (you can configure this later) ) vim.api.nvim_create_user_command( - 'TimerLog', -- The name of the command (accessible via :TimerStart) + 'TimerLog', log_time_table, { nargs = 0 } -- No arguments for this command (you can configure this later) ) vim.api.nvim_create_user_command( - 'TimerSave', -- The name of the command (accessible via :TimerStart) + 'TimerSave', persist, { nargs = 0 } -- No arguments for this command (you can configure this later) )