-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinit.lua
More file actions
85 lines (69 loc) · 1.83 KB
/
Copy pathinit.lua
File metadata and controls
85 lines (69 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
local utils = require "timerly.utils"
local state = require "timerly.state"
local api = vim.api
local volt = require "volt"
local volt_events = require "volt.events"
local timerlyapi = require "timerly.api"
state.ns = api.nvim_create_namespace "Timerly"
local M = {}
M.setup = function(opts)
state.config = vim.tbl_deep_extend("force", state.config, opts or {})
end
M.open = function()
state.volt_set = true
local config = state.config
state.minutes = config.minutes[1]
utils.secs_to_ascii(state.minutes * 60)
state.w = 24 + 2 + (2 * 4) + (2 * state.xpad)
state.w_with_pad = state.w - (2 * state.xpad)
utils.openwins()
vim.fn.prompt_setcallback(state.input_buf, function(input)
local n = tonumber(input)
if type(n) == "number" then
state.minutes = n
timerlyapi.reset()
end
end)
volt.gen_data {
{
buf = state.buf,
layout = require "timerly.layout",
xpad = state.xpad,
ns = state.ns,
},
}
volt.run(state.buf, { h = state.h, w = state.w })
volt_events.add(state.buf)
volt.mappings {
bufs = { state.buf, state.input_buf },
after_close = function()
state.timer:stop()
state.buf = nil
state.input_buf = nil
state.volt_set = false
vim.api.nvim_del_augroup_by_name "TimerlyResize"
end,
}
require "timerly.actions"()
vim.api.nvim_create_autocmd("VimResized", {
group = vim.api.nvim_create_augroup("TimerlyResize",{}),
callback = function()
if state.visible then
require("timerly").toggle()
require("timerly").toggle()
end
end,
})
end
M.toggle = function()
if not state.volt_set then
M.open()
elseif state.visible then
api.nvim_win_close(state.win, true)
api.nvim_win_close(state.input_win, true)
else
utils.openwins()
end
state.visible = not state.visible
end
return M