aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-04-12 10:09:22 +0530
committerAkshay Nair <phenax5@gmail.com>2025-04-12 10:09:22 +0530
commit8c5e75578b063a4fb64dc7ecef4851a860d7674d (patch)
tree0cc849cc6710a06a4ab1158913b3691a234d33d3
parent762ac5a2bc8902fb22fa7005a136ed07c2e2cdfc (diff)
downloadnull-browser-8c5e75578b063a4fb64dc7ecef4851a860d7674d.tar.gz
null-browser-8c5e75578b063a4fb64dc7ecef4851a860d7674d.zip
Respect cli args for main instance
Diffstat (limited to '')
-rw-r--r--TODO.org12
-rw-r--r--config.lua21
-rw-r--r--lua/null-browser/extras/dmenu.lua7
-rw-r--r--src/main.cpp18
4 files changed, 40 insertions, 18 deletions
diff --git a/TODO.org b/TODO.org
index 5c72e73..f3f15db 100644
--- a/TODO.org
+++ b/TODO.org
@@ -19,11 +19,15 @@
- [X] History storage
- [X] History completion
- [X] Close window if last tab closed
+- [ ] Rename terms: webview/tab to page? (also web.tabs)
- [ ] Configuration lua api
- [ ] Switch to __internals
+- [ ] Respect cli args for main window
- [ ] Tests for api
- [ ] Log stdout, errors and results from lua somewhere
-- [ ] Downloading
+- [ ] Downloading/download path config
+- [ ] Run JS in page
+- [ ] Segfault on close
** Next
- [ ] Search text in page
@@ -31,7 +35,7 @@
- [ ] Fullscreen
- [ ] Zoom in/out
- [ ] Permission requests handling/persisting
-- [ ] window.opener controls
+- [ ] window.opener controls (use createWindow api directly?)
- [ ] Notifications
- [ ] Conflict in keymap (keymap already exists)
- [ ] Allow pattern filtering for event listeners
@@ -39,7 +43,9 @@
- [ ] Handle resource cleanup + signal disconnecting
- [ ] Open url sanitize/humanize (add protocol if missing, remove quotes, etc)
- [ ] static linking for qt
-- [ ] static linking for libluv
+- [X] static linking for libluv
+- [ ] User scripts (greasemonkey?)
+- [ ] User stylesheets (per site and global?)
- [ ] Bookmarking
** Later
diff --git a/config.lua b/config.lua
index 76db77c..9b874d9 100644
--- a/config.lua
+++ b/config.lua
@@ -5,11 +5,6 @@ web = web
--- @type table
uv = uv
-local function trim(s)
- local res, _ = string.gsub(s, '^%s*(.-)%s*$', '%1')
- return res
-end
-
local function get_current_tab_index()
local currentTab = web.tabs.current();
for index, tab in ipairs(web.tabs.list()) do
@@ -29,18 +24,30 @@ web.event.add_listener('UrlChanged', {
end
})
+local function trim(s)
+ local res, _ = string.gsub(s, '^%s*(.-)%s*$', '%1')
+ return res
+end
+
+local function to_url(url)
+ if string.match(url, "^https?://") then
+ return trim(url)
+ end
+ return "https://" .. trim(url)
+end
+
-- Open in new tab
web.keymap.set('n', 'o', function()
dmenu.select(history.list(), { prompt = 'Open tab:' }, function(err, result)
if err or not result then return end
- web.tabs.new(trim(result))
+ web.tabs.new(to_url(result))
end)
end)
-- Open in current tab
web.keymap.set('n', '<s-o>', function()
dmenu.select(history.list(), { prompt = 'Open:' }, function(err, result)
if err or not result then return end
- web.tabs.set_url(trim(result))
+ web.tabs.set_url(to_url(result))
end)
end)
-- Delete from history
diff --git a/lua/null-browser/extras/dmenu.lua b/lua/null-browser/extras/dmenu.lua
index 3a82953..164533b 100644
--- a/lua/null-browser/extras/dmenu.lua
+++ b/lua/null-browser/extras/dmenu.lua
@@ -7,7 +7,12 @@ function dmenu.select(list, opts, callback)
local selection = nil
local stdin = uv.new_pipe();
local stdout = uv.new_pipe();
- local args = { '-p', opts.prompt or '>', '-it', opts.input or '' }
+ local args = opts.args or {}
+ if opts.prompt then
+ table.insert(args, '-p')
+ table.insert(args, opts.prompt)
+ end
+
uv.spawn('dmenu', { args = args, stdio = { stdin, stdout, nil } }, function(code)
uv.close(stdout)
uv.close(stdin)
diff --git a/src/main.cpp b/src/main.cpp
index 066a612..dc51342 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -25,20 +25,24 @@ int main(int argc, char *argv[]) {
auto *parser = create_cli_parser();
parser->process(app);
+ auto urls = parser->positionalArguments();
+ auto lua_expr = parser->value("expr");
+
InstanceManager instance_manager;
if (instance_manager.is_server()) {
auto *browser = new BrowserApp;
- browser->create_window();
+ browser->create_window(urls);
auto &lua = LuaRuntime::instance();
- QObject::connect(&instance_manager, &InstanceManager::lua_eval_requested,
- &lua, &LuaRuntime::evaluate);
- QObject::connect(&instance_manager, &InstanceManager::urls_open_requested,
- browser, &BrowserApp::create_window);
+ QObject::connect(&instance_manager, &InstanceManager::lua_eval_requested, &lua,
+ &LuaRuntime::evaluate);
+ QObject::connect(&instance_manager, &InstanceManager::urls_open_requested, browser,
+ &BrowserApp::create_window);
+
+ if (!lua_expr.isEmpty())
+ lua.evaluate(lua_expr);
} else {
qInfo() << "Using current instance";
- auto urls = parser->positionalArguments();
- auto lua_expr = parser->value("expr");
if (!urls.isEmpty() || lua_expr.isEmpty())
instance_manager.write_open_urls_to_socket(urls);