Compare commits
2 Commits
d367d166a9
...
v1.0.0
Author | SHA1 | Date | |
---|---|---|---|
312689b005 | |||
e9eab52653 |
@ -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()
|
||||||
|
|
||||||
|
|
||||||
@ -132,13 +130,27 @@ local function log_time_table()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function focus_gained()
|
||||||
|
table.insert(focus_events, {
|
||||||
|
time = os.time(),
|
||||||
|
event = "gain",
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
local function focus_lost()
|
||||||
|
table.insert(focus_events, {
|
||||||
|
time = os.time(),
|
||||||
|
event = "lose",
|
||||||
|
})
|
||||||
|
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"))
|
||||||
@ -162,27 +174,17 @@ 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
|
||||||
focus_events = {}
|
focus_events = {}
|
||||||
focus_gained()
|
focus_gained()
|
||||||
end
|
end
|
||||||
local function focus_gained()
|
|
||||||
table.insert(focus_events, {
|
|
||||||
time = os.time(),
|
|
||||||
event = "gain",
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
local function focus_lost()
|
|
||||||
table.insert(focus_events, {
|
|
||||||
time = os.time(),
|
|
||||||
event = "lose",
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
local function setup()
|
local function setup()
|
||||||
vim.api.nvim_create_autocmd("VimEnter",
|
vim.api.nvim_create_autocmd("VimEnter",
|
||||||
@ -193,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)
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user