fix persist

This commit is contained in:
u80864958 2024-10-08 10:57:57 +02:00
parent e9eab52653
commit 312689b005

View File

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