aboutsummaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-05-02 12:04:43 +0530
committerAkshay Nair <phenax5@gmail.com>2025-05-02 16:24:38 +0530
commit398b1a4b398324311b6e0f15d2e4ede5ad8500ff (patch)
tree4af9a1b5106dc30d22adc0a4391b5ac006dd7141 /lua
parent8a71de53c002b7afdd516cff7190896d40496483 (diff)
downloadnull-browser-398b1a4b398324311b6e0f15d2e4ede5ad8500ff.tar.gz
null-browser-398b1a4b398324311b6e0f15d2e4ede5ad8500ff.zip
Prefix uv with web.uv + add permissions_persistance config option
Diffstat (limited to 'lua')
-rw-r--r--lua/null-browser/extras/dmenu.lua19
-rw-r--r--lua/null-browser/extras/history.lua14
-rw-r--r--lua/null-browser/utils.lua6
3 files changed, 21 insertions, 18 deletions
diff --git a/lua/null-browser/extras/dmenu.lua b/lua/null-browser/extras/dmenu.lua
index c7a941f..fc92b35 100644
--- a/lua/null-browser/extras/dmenu.lua
+++ b/lua/null-browser/extras/dmenu.lua
@@ -1,12 +1,9 @@
---- @type table
-uv = uv
-
local dmenu = {}
function dmenu.select(list, opts, callback)
local selection = nil
- local stdin = uv.new_pipe();
- local stdout = uv.new_pipe();
+ local stdin = web.uv.new_pipe();
+ local stdout = web.uv.new_pipe();
local args = opts.args or {}
if opts.prompt then
table.insert(args, '-p')
@@ -17,9 +14,9 @@ function dmenu.select(list, opts, callback)
table.insert(args, opts.input)
end
- uv.spawn('dmenu', { args = args, stdio = { stdin, stdout, nil } }, function(code)
- uv.close(stdout)
- uv.close(stdin)
+ web.uv.spawn('dmenu', { args = args, stdio = { stdin, stdout, nil } }, function(code)
+ web.uv.close(stdout)
+ web.uv.close(stdin)
if code == 0 then
callback(nil, selection)
else
@@ -27,14 +24,14 @@ function dmenu.select(list, opts, callback)
end
end)
- uv.read_start(stdout, function(_, data)
+ web.uv.read_start(stdout, function(_, data)
if data then selection = data end
end)
for _, value in ipairs(list) do
- uv.write(stdin, value .. '\n')
+ web.uv.write(stdin, value .. '\n')
end
- uv.shutdown(stdin)
+ web.uv.shutdown(stdin)
end
function dmenu.input(opts, callback)
diff --git a/lua/null-browser/extras/history.lua b/lua/null-browser/extras/history.lua
index 8106178..d1f58d0 100644
--- a/lua/null-browser/extras/history.lua
+++ b/lua/null-browser/extras/history.lua
@@ -6,11 +6,11 @@ local history = {
local hook_registered = false
function history.list()
- local file = uv.fs_open(history.path, 'r', 438)
+ local file = web.uv.fs_open(history.path, 'r', 438)
if not file then return {} end
- local stat = assert(uv.fs_fstat(file))
- local data = assert(uv.fs_read(file, stat.size))
- assert(uv.fs_close(file))
+ local stat = assert(web.uv.fs_fstat(file))
+ local data = assert(web.uv.fs_read(file, stat.size))
+ assert(web.uv.fs_close(file))
local urls = {}
for line in string.gmatch(data, '[^\r\n]+') do
@@ -33,11 +33,11 @@ end
function history.update(func)
local urls = history.list()
- local file = assert(uv.fs_open(history.path, 'w', 438))
+ local file = assert(web.uv.fs_open(history.path, 'w', 438))
urls = func(urls)
local contents = table.concat(urls, '\n')
- assert(uv.fs_write(file, contents))
- assert(uv.fs_close(file))
+ assert(web.uv.fs_write(file, contents))
+ assert(web.uv.fs_close(file))
end
function history.add(url)
diff --git a/lua/null-browser/utils.lua b/lua/null-browser/utils.lua
index b6ff40a..2fe44e1 100644
--- a/lua/null-browser/utils.lua
+++ b/lua/null-browser/utils.lua
@@ -2,6 +2,12 @@
_G.web = _G.web or {}
web.utils = web.utils or {}
+--- luv api
+--- @type table
+--- @link https://github.com/luvit/luv/blob/master/docs.md
+--- @diagnostic disable-next-line: undefined-global
+web.uv = web.uv or nil
+
local inspector = require 'null-browser.inspect'
--- Returns human-readable string representation of Lua tables