-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path\
84 lines (69 loc) · 2.15 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
local M = {}
local http = require("socket.http")
local ltn12 = require("ltn12")
M.counter = 0
M.keySequence = {}
M.targetSequence = {'g', 'g', 'V', 'G'}
function M.setup()
vim.on_key(function(key)
local key_char = vim.api.nvim_replace_termcodes(key, true, false, true)
M.show_key(key_char)
end)
end
function M.show_key(key)
table.insert(M.keySequence, key)
if #M.keySequence > 4 then
table.remove(M.keySequence, 1) -- Keep only the last 4 keys pressed
end
if M.check_sequence() then
M.counter = M.counter + 500
vim.o.statusline = "key combo +500! Count: " .. M.counter
M.keySequence = {} -- Reset the sequence after a match
else
M.counter = M.counter + 1
vim.o.statusline = string.format("Key pressed: %s | Count: %d", key, M.counter)
end
vim.api.nvim_command('redrawstatus')
end
function M.check_sequence()
if #M.keySequence ~= 4 then
return false
end
for i, v in ipairs(M.targetSequence) do
if M.keySequence[i] ~= v then
return false
end
end
return true
end
-- TOKEN ##############
-- TOKEN END ###########
-- START POST REQUEST ## SENDING DATA!!!!
-- Funzione per inviare una richiesta HTTP POST
function M.sendRequest()
local path = "http://localhost:3000/api/v1/nvim-plugin/sendscore"
local payload = [[
{
"id_token": "id_token",
"userName": "userName",
"totalKeyPressed": "contatore"
}
]]
local response_body = {}
local res, code, response_headers, status = http.request {
url = path,
method = "POST",
headers = {
["Authorization"] = "Bearer YourToken", -- sistemare token
["Content-Type"] = "application/json",
["Content-Length"] = tostring(#payload)
},
source = ltn12.source.string(payload),
sink = ltn12.sink.table(response_body)
}
-- Stampa la risposta nel command-line di Neovim
print('Response: ' .. table.concat(response_body) .. ' Code: ' .. tostring(code) .. ' Status: ' .. tostring(status))
end
-- Altre funzioni
-- END POST REQUEST#################
return M