-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_spinners.lua
64 lines (53 loc) · 2.13 KB
/
test_spinners.lua
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
local spinetta = require'spinetta'
-- To simulate a process that takes 3 seconds
local my_job = "sleep 3"
-- To test a real case with a curl command
-- local my_job = "curl https://httpbin.org/get"
-- Default values are { main_msg = "", final_msg = nil, interruptec_msg = nil, spinner = spinetta.DEFAULT_SPINNER, speed_ms = 200}
local spinetta_default = spinetta:new()
spinetta_default:start(spinetta.job_to_run(my_job))
-- Values speed_ms, spinner, main_msg and final_msg set by parameters
local spinetta_arrow = spinetta:new {
speed_ms = 400,
spinner = spinetta.ARROW_SPINNER,
main_msg = "Arrows ",
on_success = function()
print("Arrows finished!")
end
}
spinetta_arrow:start(spinetta.job_to_run(my_job))
--Values speed_ms, spinner and final_msg set by parameters
local spinetta_equals = spinetta:new {
speed_ms = 100,
spinner = spinetta.EQUALS_SPINNER,
final_msg = "Equals finished!"
}
-- This is optional to use spinetta.jab_tu_run(my_job) which has this line implicit
local pid = vim.fn.jobpid(vim.fn.jobstart(my_job))
spinetta_equals:start(spinetta.break_when_pid_is_complete(pid))
-- Values spinner and speed_ms set by parameters
local spinetta_ping_pong = spinetta:new {
spinner = spinetta.PING_PONG_SPINNER,
speed_ms = 50
}
local pid2 = vim.fn.jobpid(vim.fn.jobstart(my_job))
-- This is optional to use spinetta.jab_tu_run(pid) or spinetta.break_when_pid_is_complete(pid) which has this line implicit
-- If a function is passed to 'start' it has to be a function that return a boolean value to break the spinner process
-- like this:
spinetta_ping_pong:start(function()
local job_status = string.format("[ -f '/proc/%d/status' ] && echo 1 || echo 0", pid2)
return tonumber(vim.fn.system(job_status)) == 0
end)
-- Values spinner, main_msg, final_msg and interrupted_msg are set by parameters
local spinetta_bar = spinetta:new {
spinner = spinetta.PROGRESS_BAR_SPINNER,
on_success = function()
print("Done!")
end,
main_msg = "Loading ",
on_interrupted = function()
vim.cmd("redraw")
print("Interrupted!")
end
}
spinetta_bar:start(spinetta.job_to_run(my_job))