Replaced print statements by write statements for nvim floating window

This commit is contained in:
Yannick Reiß 2024-02-19 16:01:37 +01:00
parent 0e7348af80
commit 2e6580d6b4
No known key found for this signature in database
GPG Key ID: 5A3AF456F0A0338C
1 changed files with 35 additions and 11 deletions

View File

@ -54,7 +54,16 @@ function M.lookup()
url, empty = url:gsub(" ", "+")
open_window()
print("Starting the request")
-- enable write to buffer
api.nvim_buf_set_option(buf, "modifiable", true)
api.nvim_buf_set_lines(buf, 0, 1, false, {
"Interesting ACM Publications",
})
api.nvim_buf_set_lines(buf, 1, 2, false, {
"Requesting papers from ACM...",
})
-- Setup a http socket and request
local command = string.format("wget -q -O - '%s'", url)
@ -72,16 +81,21 @@ function M.lookup()
-- extract the rss feed link
local rss_url = response:match('"https://dl%.acm%.org/action/showFeed%?.-"')
if rss_url == nil then
print("ERROR in URL")
api.nvim_buf_set_lines(buf, 3, 4, false, {
"ERROR: Could not locate Feed!",
})
return
end
rss_url = rss_url:sub(2, #rss_url - 1)
print("Feed found at: " .. rss_url)
api.nvim_buf_set_lines(buf, 3, 4, false, {
"Feed found at: " .. rss_url,
})
local rss_content = httprequest(rss_url)
print("Received feed content")
print(rss_content)
api.nvim_buf_set_lines(buf, 4, 5, false, {
"Received feed content",
})
-- skip initial block
local b, b_start = rss_content:find("</image>", 1, false)
@ -150,12 +164,22 @@ function M.lookup()
b = y
end
print("Keywords: " .. keywords)
print("URL: " .. url)
print("Title: " .. #titles)
print("Links: " .. #links)
print("Descriptions: " .. #descriptions)
print("Dates: " .. #dates)
local current_line = 2
for x = 1, #dates do
api.nvim_buf_set_lines(buf, current_line, -1, false, titles[x])
current_line = current_line + 1
api.nvim_buf_set_lines(buf, current_line, -1, false, dates[x])
current_line = current_line + 1
api.nvim_buf_set_lines(buf, current_line, -1, false, descriptions[x])
current_line = current_line + 1
api.nvim_buf_set_lines(buf, current_line, -1, false, links[x])
current_line = current_line + 1
api.nvim_buf_set_lines(buf, current_line, -1, false, "---")
current_line = current_line + 1
end
-- disable write / make buffer readonly
api.nvim_buf_set_option(buf, "modifiable", false)
end
return M