aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-08-17 16:17:13 +0530
committerAkshay Nair <phenax5@gmail.com>2025-08-17 16:17:13 +0530
commitb2fb7cd3d765bda9c8bb7fdee93ce7494f30cc10 (patch)
tree6660fc758d9773f99bcd38668604e2ee8de5eda3
parent98f3281256e6ff435c67d83c6895fff5841b70be (diff)
downloadnull-browser-b2fb7cd3d765bda9c8bb7fdee93ce7494f30cc10.tar.gz
null-browser-b2fb7cd3d765bda9c8bb7fdee93ce7494f30cc10.zip
Update internal api options
-rw-r--r--TODO.org17
-rw-r--r--docs/api/index.html245
-rw-r--r--docs/api/symbols.json2
-rw-r--r--init.lua8
-rw-r--r--lua/null-browser/api.lua127
-rw-r--r--lua/null-browser/defaults/vi.lua4
-rw-r--r--lua/null-browser/utils.lua4
7 files changed, 257 insertions, 150 deletions
diff --git a/TODO.org b/TODO.org
index a654d64..1766d6e 100644
--- a/TODO.org
+++ b/TODO.org
@@ -23,7 +23,9 @@
- [X] Fix path to symbols.json in web.help.get_items (use docs path)
- [X] Document events and event opts
- [ ] Element focus (input focus)
-- [ ] Update all api to use opts table pattern
+- [X] Update all api to use opts table pattern
+- [ ] Update internal apis to use table
+- [ ] Add win options for web.view.list / web.view.current / web.view.current_index /etc
- [ ] web.keymap.configure_mode(modename, { passthrough = false })
- [ ] Fullscreen
- [ ] Zoom in/out/reset
@@ -31,6 +33,7 @@
- [ ] Api for enabling rpc api in view
- [ ] Hide/show decoration api
- [ ] Review all options and make sure they're passed correctly
+- [ ] Delay in tabline module updating (shows outdated titles)
** Bugs
- [ ] INVESTIGATE: Segfault on close sometimes
@@ -40,18 +43,18 @@
- [ ] INVESTIGATE: Check why urlchanged doesnt fire for first url open sometimes
** Next
+- [ ] Log stdout, errors and results from lua somewhere
+- [ ] User stylesheets (per site and global?)
- [ ] View focus event (between decorations/views)
+- [ ] Use table for all internals api options?
- [ ] User scripts (greasemonkey?)
-- [ ] User stylesheets (per site and global?)
-- [ ] Log stdout, errors and results from lua somewhere
-- [ ] Move view to a different window (`web.view.move_to_window(view, win)`)
- [ ] web.win.* apis (list, current_id)
-- [ ] Permission management (list/allow/deny) lua api
+- [ ] Move view to a different window (`web.view.move_to_window(view, win)`)
+- [ ] Permission management (list/allow/block) lua api
- [ ] Granular updates in statusline plugin instead of set_html multiple times
-- [ ] Use table for all internals api options?
- [ ] Tests for window
- [ ] More tests for stack
-- [ ] Tests for router
+- [ ] More tests for router
- [ ] User data/profiles management
- [ ] Create window with new profile
- [ ] Configuration validation
diff --git a/docs/api/index.html b/docs/api/index.html
index cfa0023..79588d7 100644
--- a/docs/api/index.html
+++ b/docs/api/index.html
@@ -69,7 +69,7 @@
<td class="summary">Get the current keymap mode</td>
</tr>
<tr>
- <td class="name" nowrap><a href="#web.view.close">web.view.close (view_id)</a></td>
+ <td class="name" nowrap><a href="#web.view.close">web.view.close (opts)</a></td>
<td class="summary">Close view</td>
</tr>
<tr>
@@ -81,6 +81,10 @@
<td class="summary">Get current view id</td>
</tr>
<tr>
+ <td class="name" nowrap><a href="#web.view.current_url">web.view.current_url ()</a></td>
+ <td class="summary">Get current url</td>
+ </tr>
+ <tr>
<td class="name" nowrap><a href="#web.view.list">web.view.list ()</a></td>
<td class="summary">Get a list of views in the current window</td>
</tr>
@@ -89,7 +93,7 @@
<td class="summary">Select a view in current window</td>
</tr>
<tr>
- <td class="name" nowrap><a href="#web.view.set_url">web.view.set_url (url, view_id)</a></td>
+ <td class="name" nowrap><a href="#web.view.set_url">web.view.set_url (url, opts)</a></td>
<td class="summary">Set url of a given view</td>
</tr>
<tr>
@@ -102,14 +106,14 @@
</tr>
<tr>
<td class="name" nowrap><a href="#web.view.reload">web.view.reload (opts)</a></td>
- <td class="summary">Relaod a given view</td>
+ <td class="summary">Reload a given view</td>
</tr>
<tr>
<td class="name" nowrap><a href="#web.view.expose">web.view.expose (name, action, opts)</a></td>
<td class="summary">Expose a lua function inside a view (Only works with decorations)</td>
</tr>
<tr>
- <td class="name" nowrap><a href="#web.view.open_devtools">web.view.open_devtools (view_id)</a></td>
+ <td class="name" nowrap><a href="#web.view.open_devtools">web.view.open_devtools (opts)</a></td>
<td class="summary">Open devtools window for the view</td>
</tr>
<tr>
@@ -129,19 +133,19 @@
<td class="summary">Get configuration value</td>
</tr>
<tr>
- <td class="name" nowrap><a href="#web.history.back">web.history.back (count, view_id)</a></td>
+ <td class="name" nowrap><a href="#web.history.back">web.history.back (count, opts)</a></td>
<td class="summary">Go back in history for given view</td>
</tr>
<tr>
- <td class="name" nowrap><a href="#web.history.forward">web.history.forward (count, view_id)</a></td>
+ <td class="name" nowrap><a href="#web.history.forward">web.history.forward (count, opts)</a></td>
<td class="summary">Go forward in history for given view</td>
</tr>
<tr>
- <td class="name" nowrap><a href="#web.search.set_text">web.search.set_text (text, view_id)</a></td>
+ <td class="name" nowrap><a href="#web.search.set_text">web.search.set_text (text, opts)</a></td>
<td class="summary">Search text inside a view</td>
</tr>
<tr>
- <td class="name" nowrap><a href="#web.search.reset">web.search.reset (view_id)</a></td>
+ <td class="name" nowrap><a href="#web.search.reset">web.search.reset (opts)</a></td>
<td class="summary">Reset searched text in a view (Same as web.search.set_text(''))</td>
</tr>
<tr>
@@ -149,23 +153,23 @@
<td class="summary">Get the last searched text</td>
</tr>
<tr>
- <td class="name" nowrap><a href="#web.search.next">web.search.next (view_id)</a></td>
+ <td class="name" nowrap><a href="#web.search.next">web.search.next (opts)</a></td>
<td class="summary">Highlight next search term for the last searched text</td>
</tr>
<tr>
- <td class="name" nowrap><a href="#web.search.previous">web.search.previous (view_id)</a></td>
+ <td class="name" nowrap><a href="#web.search.previous">web.search.previous (opts)</a></td>
<td class="summary">Highlight previous search term for the last searched text</td>
</tr>
<tr>
- <td class="name" nowrap><a href="#web.view.scroll">web.view.scroll (deltax, deltay, view_id)</a></td>
+ <td class="name" nowrap><a href="#web.view.scroll">web.view.scroll (deltax, deltay, opts)</a></td>
<td class="summary">TODO: Document</td>
</tr>
<tr>
- <td class="name" nowrap><a href="#web.view.scroll_to_top">web.view.scroll_to_top (view_id)</a></td>
+ <td class="name" nowrap><a href="#web.view.scroll_to_top">web.view.scroll_to_top (opts)</a></td>
<td class="summary">TODO: Document</td>
</tr>
<tr>
- <td class="name" nowrap><a href="#web.view.scroll_to_bottom">web.view.scroll_to_bottom (view_id)</a></td>
+ <td class="name" nowrap><a href="#web.view.scroll_to_bottom">web.view.scroll_to_bottom (opts)</a></td>
<td class="summary">TODO: Document</td>
</tr>
<tr>
@@ -383,7 +387,7 @@
</dd>
<dt>
<a name = "web.view.close"></a>
- <strong>web.view.close (view_id)</strong>
+ <strong>web.view.close (opts)</strong>
</dt>
<dd>
Close view
@@ -391,9 +395,12 @@
<h3>Parameters:</h3>
<ul>
- <li><span class="parameter">view_id</span>
- ? number View id to close
+ <li><span class="parameter">opts</span> Options
+ <ul>
+ <li><span class="parameter">view</span>
+ number? View id (default = 0)
</li>
+ </li></ul>
</ul>
@@ -402,7 +409,7 @@
<h3>Usage:</h3>
<ul>
<pre class="example">web.view.<span class="function-name">close</span>() <span class="comment">-- Close current view in active window
-</span>web.view.<span class="function-name">close</span>(<span class="number">3</span>) <span class="comment">-- Close view with id 3</span></pre>
+</span>web.view.<span class="function-name">close</span>({ view = <span class="number">3</span> }) <span class="comment">-- Close view with id 3</span></pre>
</ul>
</dd>
@@ -456,6 +463,30 @@
</dd>
<dt>
+ <a name = "web.view.current_url"></a>
+ <strong>web.view.current_url ()</strong>
+ </dt>
+ <dd>
+ Get current url
+
+
+
+ <h3>Returns:</h3>
+ <ol>
+
+ <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Current view url
+ </ol>
+
+
+
+ <h3>Usage:</h3>
+ <ul>
+ <pre class="example"><span class="keyword">local</span> url = web.view.<span class="function-name">current_url</span>()</pre>
+ </ul>
+
+</dd>
+ <dt>
<a name = "web.view.list"></a>
<strong>web.view.list ()</strong>
</dt>
@@ -507,7 +538,7 @@
</dd>
<dt>
<a name = "web.view.set_url"></a>
- <strong>web.view.set_url (url, view_id)</strong>
+ <strong>web.view.set_url (url, opts)</strong>
</dt>
<dd>
Set url of a given view
@@ -519,10 +550,12 @@
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
Url to open
</li>
- <li><span class="parameter">view_id</span>
- <span class="types"><span class="type">number</span></span>
- View id to select
+ <li><span class="parameter">opts</span> Options
+ <ul>
+ <li><span class="parameter">view</span>
+ number? View id (default = 0)
</li>
+ </li></ul>
</ul>
@@ -531,7 +564,7 @@
<h3>Usage:</h3>
<ul>
<pre class="example">web.view.<span class="function-name">set_url</span>(<span class="string">'https://foobar.com'</span>)
-web.view.<span class="function-name">set_url</span>(<span class="string">'https://foobar.com'</span>, <span class="number">3</span>) <span class="comment">-- Set url for view with id 3</span></pre>
+web.view.<span class="function-name">set_url</span>(<span class="string">'https://foobar.com'</span>, { view = <span class="number">3</span> }) <span class="comment">-- Set url for view with id 3</span></pre>
</ul>
</dd>
@@ -546,12 +579,12 @@ web.view.<span class="function-name">set_url</span>(<span class="string">'https:
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">html</span>
- string HTML string
+ string HTML string
</li>
- <li><span class="parameter">opts</span> table Options
+ <li><span class="parameter">opts</span>? table Options
<ul>
<li><span class="parameter">view</span>
- number View id
+ number? View id (default = 0)
</li>
</li></ul>
</ul>
@@ -578,11 +611,17 @@ web.view.<span class="function-name">set_html</span>(<span class="string">'&lt;h
<ul>
<li><span class="parameter">js</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
- HTML string
+ JS string
+ </li>
+ <li><span class="parameter">opts</span> Options
+ <ul>
+ <li><span class="parameter">view</span>
+ number? View id (default = 0)
</li>
- <li><span class="parameter">opts</span>
- ? RunJSOpts Options
+ <li><span class="parameter">on_result</span>
+ ? fun(v: any): nil Callback with serialized result of evaluation
</li>
+ </li></ul>
</ul>
@@ -591,7 +630,12 @@ web.view.<span class="function-name">set_html</span>(<span class="string">'&lt;h
<h3>Usage:</h3>
<ul>
<pre class="example">web.view.<span class="function-name">run_js</span>(<span class="string">'console.log(42)'</span>)
-web.view.<span class="function-name">run_js</span>(<span class="string">'console.log(42)'</span>, { view = <span class="number">3</span> }) <span class="comment">-- Set html for view with id 3</span></pre>
+web.view.<span class="function-name">run_js</span>(<span class="string">'console.log(42)'</span>, { view = <span class="number">3</span> }) <span class="comment">-- Set html for view with id 3
+</span>web.view.<span class="function-name">run_js</span>(<span class="string">'2 * 3'</span>, {
+ on_result = <span class="keyword">function</span>(result)
+ <span class="global">print</span>(result * <span class="number">7</span>)
+ <span class="keyword">end</span>,
+})</pre>
</ul>
</dd>
@@ -600,14 +644,17 @@ web.view.<span class="function-name">run_js</span>(<span class="string">'console
<strong>web.view.reload (opts)</strong>
</dt>
<dd>
- Relaod a given view
+ Reload a given view
<h3>Parameters:</h3>
<ul>
- <li><span class="parameter">opts</span>
- ? ReloadOpts Options
+ <li><span class="parameter">opts</span> Options
+ <ul>
+ <li><span class="parameter">view</span>
+ number? View id (default = 0)
</li>
+ </li></ul>
</ul>
@@ -631,14 +678,17 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">name</span>
- string Func name
+ string Func name
</li>
<li><span class="parameter">action</span>
- fun(table):nil Action to call when function is invoked in view
+ fun(table):nil Action to call when function is invoked in view
</li>
- <li><span class="parameter">opts</span>
- ExposeOpts? Options
+ <li><span class="parameter">opts</span> Options
+ <ul>
+ <li><span class="parameter">view</span>
+ number? View id (default = 0)
</li>
+ </li></ul>
</ul>
@@ -656,7 +706,7 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
</dd>
<dt>
<a name = "web.view.open_devtools"></a>
- <strong>web.view.open_devtools (view_id)</strong>
+ <strong>web.view.open_devtools (opts)</strong>
</dt>
<dd>
Open devtools window for the view
@@ -664,10 +714,12 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
<h3>Parameters:</h3>
<ul>
- <li><span class="parameter">view_id</span>
- <span class="types"><span class="type">number</span></span>
- Id of the view
+ <li><span class="parameter">opts</span> Options
+ <ul>
+ <li><span class="parameter">view</span>
+ number? View id (default = 0)
</li>
+ </li></ul>
</ul>
@@ -809,7 +861,7 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
</dd>
<dt>
<a name = "web.history.back"></a>
- <strong>web.history.back (count, view_id)</strong>
+ <strong>web.history.back (count, opts)</strong>
</dt>
<dd>
Go back in history for given view
@@ -820,10 +872,12 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
<li><span class="parameter">count</span>
number? Number of history items to go back in (default = 1)
</li>
- <li><span class="parameter">view_id</span>
- <span class="types"><span class="type">number</span></span>
- Id of the view
+ <li><span class="parameter">opts</span> Options
+ <ul>
+ <li><span class="parameter">view</span>
+ number? View id (default = 0)
</li>
+ </li></ul>
</ul>
@@ -831,13 +885,13 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
<h3>Usage:</h3>
<ul>
- <pre class="example">web.history.<span class="function-name">back</span>(<span class="number">2</span>, <span class="number">3</span>) <span class="comment">-- Go back 2 history items for view id 3</span></pre>
+ <pre class="example">web.history.<span class="function-name">back</span>(<span class="number">2</span>, { view = <span class="number">3</span> }) <span class="comment">-- Go back 2 history items for view id 3</span></pre>
</ul>
</dd>
<dt>
<a name = "web.history.forward"></a>
- <strong>web.history.forward (count, view_id)</strong>
+ <strong>web.history.forward (count, opts)</strong>
</dt>
<dd>
Go forward in history for given view
@@ -848,10 +902,12 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
<li><span class="parameter">count</span>
number? Number of history items to go forward in (default = 1)
</li>
- <li><span class="parameter">view_id</span>
- <span class="types"><span class="type">number</span></span>
- Id of the view
+ <li><span class="parameter">opts</span> Options
+ <ul>
+ <li><span class="parameter">view</span>
+ number? View id (default = 0)
</li>
+ </li></ul>
</ul>
@@ -859,13 +915,13 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
<h3>Usage:</h3>
<ul>
- <pre class="example">web.history.<span class="function-name">forward</span>(<span class="number">2</span>, <span class="number">3</span>) <span class="comment">-- Go forward 2 history items for view id 3</span></pre>
+ <pre class="example">web.history.<span class="function-name">forward</span>(<span class="number">2</span>, { view = <span class="number">3</span> }) <span class="comment">-- Go forward 2 history items for view id 3</span></pre>
</ul>
</dd>
<dt>
<a name = "web.search.set_text"></a>
- <strong>web.search.set_text (text, view_id)</strong>
+ <strong>web.search.set_text (text, opts)</strong>
</dt>
<dd>
Search text inside a view
@@ -876,10 +932,12 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
<li><span class="parameter">text</span>
string? Text to search
</li>
- <li><span class="parameter">view_id</span>
- <span class="types"><span class="type">number</span></span>
- Id of the view
+ <li><span class="parameter">opts</span> Options
+ <ul>
+ <li><span class="parameter">view</span>
+ number? View id (default = 0)
</li>
+ </li></ul>
</ul>
@@ -888,13 +946,13 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
<h3>Usage:</h3>
<ul>
<pre class="example">web.search.<span class="function-name">set_text</span>(<span class="string">'whatever'</span>) <span class="comment">-- Search in current view
-</span>web.search.<span class="function-name">set_text</span>(<span class="string">'whatever'</span>, <span class="number">5</span>) <span class="comment">-- Search in view id 5</span></pre>
+</span>web.search.<span class="function-name">set_text</span>(<span class="string">'whatever'</span>, { view = <span class="number">5</span> }) <span class="comment">-- Search in view id 5</span></pre>
</ul>
</dd>
<dt>
<a name = "web.search.reset"></a>
- <strong>web.search.reset (view_id)</strong>
+ <strong>web.search.reset (opts)</strong>
</dt>
<dd>
Reset searched text in a view (Same as web.search.set_text(''))
@@ -902,10 +960,12 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
<h3>Parameters:</h3>
<ul>
- <li><span class="parameter">view_id</span>
- <span class="types"><span class="type">number</span></span>
- Id of the view
+ <li><span class="parameter">opts</span> Options
+ <ul>
+ <li><span class="parameter">view</span>
+ number? View id (default = 0)
</li>
+ </li></ul>
</ul>
@@ -914,7 +974,7 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
<h3>Usage:</h3>
<ul>
<pre class="example">web.search.<span class="function-name">reset</span>() <span class="comment">-- Reset search state for current view
-</span>web.search.<span class="function-name">reset</span>(<span class="number">5</span>) <span class="comment">-- Reset search state for view id 5</span></pre>
+</span>web.search.<span class="function-name">reset</span>({ view = <span class="number">5</span> }) <span class="comment">-- Reset search state for view id 5</span></pre>
</ul>
</dd>
@@ -938,7 +998,7 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
</dd>
<dt>
<a name = "web.search.next"></a>
- <strong>web.search.next (view_id)</strong>
+ <strong>web.search.next (opts)</strong>
</dt>
<dd>
Highlight next search term for the last searched text
@@ -946,10 +1006,12 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
<h3>Parameters:</h3>
<ul>
- <li><span class="parameter">view_id</span>
- <span class="types"><span class="type">number</span></span>
- Id of the view
+ <li><span class="parameter">opts</span> Options
+ <ul>
+ <li><span class="parameter">view</span>
+ number? View id (default = 0)
</li>
+ </li></ul>
</ul>
@@ -958,13 +1020,13 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
<h3>Usage:</h3>
<ul>
<pre class="example">web.search.<span class="global">next</span>() <span class="comment">-- Next search result in current view
-</span>web.search.<span class="global">next</span>(<span class="number">5</span>) <span class="comment">-- Next search result in view id 5</span></pre>
+</span>web.search.<span class="global">next</span>({ view = <span class="number">5</span> }) <span class="comment">-- Next search result in view id 5</span></pre>
</ul>
</dd>
<dt>
<a name = "web.search.previous"></a>
- <strong>web.search.previous (view_id)</strong>
+ <strong>web.search.previous (opts)</strong>
</dt>
<dd>
Highlight previous search term for the last searched text
@@ -972,10 +1034,12 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
<h3>Parameters:</h3>
<ul>
- <li><span class="parameter">view_id</span>
- <span class="types"><span class="type">number</span></span>
- Id of the view
+ <li><span class="parameter">opts</span> Options
+ <ul>
+ <li><span class="parameter">view</span>
+ number? View id (default = 0)
</li>
+ </li></ul>
</ul>
@@ -990,7 +1054,7 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
</dd>
<dt>
<a name = "web.view.scroll"></a>
- <strong>web.view.scroll (deltax, deltay, view_id)</strong>
+ <strong>web.view.scroll (deltax, deltay, opts)</strong>
</dt>
<dd>
TODO: Document
@@ -999,14 +1063,19 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">deltax</span>
+ <span class="types"><span class="type">number</span></span>
</li>
<li><span class="parameter">deltay</span>
+ <span class="types"><span class="type">number</span></span>
</li>
- <li><span class="parameter">view_id</span>
-
+ <li><span class="parameter">opts</span> Options
+ <ul>
+ <li><span class="parameter">view</span>
+ number? View id (default = 0)
</li>
+ </li></ul>
</ul>
@@ -1016,7 +1085,7 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
</dd>
<dt>
<a name = "web.view.scroll_to_top"></a>
- <strong>web.view.scroll_to_top (view_id)</strong>
+ <strong>web.view.scroll_to_top (opts)</strong>
</dt>
<dd>
TODO: Document
@@ -1024,9 +1093,12 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
<h3>Parameters:</h3>
<ul>
- <li><span class="parameter">view_id</span>
-
+ <li><span class="parameter">opts</span> Options
+ <ul>
+ <li><span class="parameter">view</span>
+ number? View id (default = 0)
</li>
+ </li></ul>
</ul>
@@ -1036,7 +1108,7 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
</dd>
<dt>
<a name = "web.view.scroll_to_bottom"></a>
- <strong>web.view.scroll_to_bottom (view_id)</strong>
+ <strong>web.view.scroll_to_bottom (opts)</strong>
</dt>
<dd>
TODO: Document
@@ -1044,9 +1116,12 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
<h3>Parameters:</h3>
<ul>
- <li><span class="parameter">view_id</span>
-
+ <li><span class="parameter">opts</span> Options
+ <ul>
+ <li><span class="parameter">view</span>
+ number? View id (default = 0)
</li>
+ </li></ul>
</ul>
@@ -1063,6 +1138,12 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
+ <h3>Returns:</h3>
+ <ol>
+
+ <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
+ <string> help_items List of help item names
+ </ol>
@@ -1080,12 +1161,12 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
<ul>
<li><span class="parameter">item</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
-
+ Help item name
</li>
- <li><span class="parameter">opts</span>
+ <li><span class="parameter">opts</span> Options
<ul>
<li><span class="parameter">view</span>
- number?
+ number? View id (default = 0)
</li>
</li></ul>
</ul>
@@ -1166,7 +1247,7 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
<li><span class="parameter">opts</span> Options
<ul>
<li><span class="parameter">null</span>
- any What to use as null value (default: nil)
+ any? What to use as null value (default: nil)
</li>
</li></ul>
</ul>
diff --git a/docs/api/symbols.json b/docs/api/symbols.json
index 8b5319e..baf9a1e 100644
--- a/docs/api/symbols.json
+++ b/docs/api/symbols.json
@@ -1 +1 @@
-["_G.__internals","schedule","web.keymap.set","web.keymap.set_mode","web.keymap.get_mode","web.view.close","web.view.create","web.view.current","web.view.list","web.view.select","web.view.set_url","web.view.set_html","web.view.run_js","web.view.reload","web.view.expose","web.view.open_devtools","web.view.current_index","web.event.add_listener","set","get","WebOpts","opts","web.history.back","web.history.forward","web.search.set_text","web.search.reset","web.search.get_text","web.search.next","web.search.previous","web.view.scroll","web.view.scroll_to_top","web.view.scroll_to_bottom","web.help.get_items","web.help.show","WebEvents","WinCreatedEventOpts","ViewCreatedEventOpts","ViewSelectedEventOpts","ViewClosedEventOpts","UrlChangedEventOpts","PermissionRequestedEventOpts","ModeChangedEventOpts","KeyPressedEventOpts","NotificationReceivedEventOpts","uv","inspect","print","web.json.encode","web.json.decode","web.utils.string_trim","web.utils.table_merge","web.utils.table_keys","web.utils.equals","web.utils.table_contains"] \ No newline at end of file
+["_G.__internals","schedule","web.keymap.set","web.keymap.set_mode","web.keymap.get_mode","web.view.close","web.view.create","web.view.current","web.view.current_url","web.view.list","web.view.select","web.view.set_url","web.view.set_html","web.view.run_js","web.view.reload","web.view.expose","web.view.open_devtools","web.view.current_index","web.event.add_listener","set","get","WebOpts","opts","web.history.back","web.history.forward","web.search.set_text","web.search.reset","web.search.get_text","web.search.next","web.search.previous","web.view.scroll","web.view.scroll_to_top","web.view.scroll_to_bottom","web.help.get_items","web.help.show","WebEvents","WinCreatedEventOpts","ViewCreatedEventOpts","ViewSelectedEventOpts","ViewClosedEventOpts","UrlChangedEventOpts","PermissionRequestedEventOpts","ModeChangedEventOpts","KeyPressedEventOpts","NotificationReceivedEventOpts","uv","inspect","print","web.json.encode","web.json.decode","web.utils.string_trim","web.utils.table_merge","web.utils.table_keys","web.utils.equals","web.utils.table_contains"] \ No newline at end of file
diff --git a/init.lua b/init.lua
index b0f4f5f..7b38ece 100644
--- a/init.lua
+++ b/init.lua
@@ -1,6 +1,6 @@
print('hello starting up...')
-web.opts.downloads_dir = os.getenv('HOME') .. '/Downloads/firefox'
+web.opts.downloads_dir = os.getenv('HOME') .. '/Downloads'
web.opts.permissions_persistance = 'never'
web.opts.user_agent =
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36'
@@ -11,7 +11,7 @@ local history = require 'null-browser.extras.history'
history.attach_hooks()
local search_engines = require 'null-browser.extras.search-engines'
-search_engines.urls['ld'] = 'https://lite.duckduckgo.com/?q={}'
+search_engines.urls['ld'] = 'https://lite.duckduckgo.com/lite/?q={}'
search_engines.urls['g'] = 'https://github.com/{}'
search_engines.urls['y'] = 'https://youtube.com/results?search_query={}'
search_engines.urls['r'] = 'https://reddit.com/r/{}'
@@ -21,7 +21,7 @@ local menu = Dmenu:new {
select_last_line = false,
args = { '-r' },
transform_output = function(selections)
- if type(selections) ~= "table" then return selections end
+ if type(selections) ~= 'table' then return selections end
if #selections <= 1 then return selections[1] end
return selections[#selections - 1]
end,
@@ -31,7 +31,7 @@ local menu = Dmenu:new {
-- args = { 'input', '--layout=default', '--print-query' },
}
-require 'null-browser.defaults.vi'.setup {
+require 'null-browser.defaults.vi'.configure {
menu = menu,
history = history,
transform_url_input = search_engines.transform_url_input,
diff --git a/lua/null-browser/api.lua b/lua/null-browser/api.lua
index 4e96e29..c5f2de0 100644
--- a/lua/null-browser/api.lua
+++ b/lua/null-browser/api.lua
@@ -50,12 +50,13 @@ function web.keymap.get_mode() return __internals.keymap_get_mode() end
--- Close view
---
---- @param view_id? number View id to close
+--- @param opts table? Options
+--- @param opts.view number? View id (default = 0)
---
--- @usage
--- web.view.close() -- Close current view in active window
---- web.view.close(3) -- Close view with id 3
-function web.view.close(view_id) return __internals.view_close(view_id) end
+--- web.view.close({ view = 3 }) -- Close view with id 3
+function web.view.close(opts) return __internals.view_close((opts or {}).view) end
--- Create a new view with a url
---
@@ -105,45 +106,50 @@ function web.view.select(view_id) return __internals.view_select(view_id) end
--- Set url of a given view
---
---- @param url string Url to open
---- @param view_id number? View id to select
+--- @param url string Url to open
+--- @param opts table? Options
+--- @param opts.view number? View id (default = 0)
---
--- @usage
--- web.view.set_url('https://foobar.com')
---- web.view.set_url('https://foobar.com', 3) -- Set url for view with id 3
-function web.view.set_url(url, view_id) return __internals.view_set_url(url, view_id) end
+--- web.view.set_url('https://foobar.com', { view = 3 }) -- Set url for view with id 3
+function web.view.set_url(url, opts) return __internals.view_set_url(url, (opts or {}).view) end
--- Set html inside the page for a given view
---
---- @param html string HTML string
---- @param opts table Options
---- @param opts.view number View id
+--- @param html string HTML string
+--- @param opts? table Options
+--- @param opts.view number? View id (default = 0)
---
--- @usage
--- web.view.set_html('<h2>HJello</h2>')
--- web.view.set_html('<h2>HJello</h2>', { view = 3 }) -- Set html for view with id 3
function web.view.set_html(html, opts) return __internals.view_set_html(html, (opts or {}).view) end
---- @class RunJSOpts
---- @field view? number View id
---- @field on_result fun(v: any): nil Callback when
-
--- Run js in a view
---
---- @param js string HTML string
---- @param opts? RunJSOpts Options
+--- @param js string JS string
+--- @param opts table? Options
+--- @param opts.view number? View id (default = 0)
+--- @param opts.on_result? fun(v: any): nil Callback with serialized result of evaluation
---
--- @usage
--- web.view.run_js('console.log(42)')
--- web.view.run_js('console.log(42)', { view = 3 }) -- Set html for view with id 3
+--- web.view.run_js('2 * 3', {
+--- on_result = function(result)
+--- print(result * 7)
+--- end,
+--- })
function web.view.run_js(js, opts) return __internals.view_run_js(js, opts or {}) end
--- @class ReloadOpts
--- @field view? number View id
---- Relaod a given view
+--- Reload a given view
---
---- @param opts? ReloadOpts Options
+--- @param opts table? Options
+--- @param opts.view number? View id (default = 0)
---
--- @usage
--- web.view.reload()
@@ -151,13 +157,14 @@ function web.view.run_js(js, opts) return __internals.view_run_js(js, opts or {}
function web.view.reload(opts) return __internals.view_reload((opts or {}).view) end
--- @class ExposeOpts
---- @field view? number View id
+--- @field view? number View id (default = 0)
--- Expose a lua function inside a view (Only works with decorations)
---
---- @param name string Func name
---- @param action fun(table):nil Action to call when function is invoked in view
---- @param opts ExposeOpts? Options
+--- @param name string Func name
+--- @param action fun(table):nil Action to call when function is invoked in view
+--- @param opts table? Options
+--- @param opts.view number? View id (default = 0)
---
--- @usage
--- web.view.expose('tabSelect', function(args)
@@ -171,12 +178,13 @@ function web.view.expose(name, action, opts) return __internals.view_expose(name
--- Open devtools window for the view
---
---- @param view_id number? Id of the view
+--- @param opts table? Options
+--- @param opts.view number? View id (default = 0)
---
--- @usage
--- web.view.open_devtools() -- Open devtools window for current view
--- web.view.open_devtools(5) -- Open devtools window for view id 5
-function web.view.open_devtools(view_id) return __internals.view_open_devtools(view_id) end
+function web.view.open_devtools(opts) return __internals.view_open_devtools((opts or {}).view) end
--- Get current view index
---
@@ -195,6 +203,7 @@ function web.view.current_index()
end
--- Listen to events from the browser
+---
--- @param events string|table Event or events to listen to
--- @param opts table Options
--- @param opts.callback fun(opts:any):nil Callback called when that event occurs
@@ -265,39 +274,43 @@ web.opts = setmetatable({}, {
--- Go back in history for given view
---
--- @param count number? Number of history items to go back in (default = 1)
---- @param view_id number? Id of the view
+--- @param opts table? Options
+--- @param opts.view number? View id (default = 0)
---
--- @usage
---- web.history.back(2, 3) -- Go back 2 history items for view id 3
-function web.history.back(count, view_id) return __internals.history_back(count, view_id) end
+--- web.history.back(2, { view = 3 }) -- Go back 2 history items for view id 3
+function web.history.back(count, opts) return __internals.history_back(count, (opts or {}).view) end
--- Go forward in history for given view
---
--- @param count number? Number of history items to go forward in (default = 1)
---- @param view_id number? Id of the view
+--- @param opts table? Options
+--- @param opts.view number? View id (default = 0)
---
--- @usage
---- web.history.forward(2, 3) -- Go forward 2 history items for view id 3
-function web.history.forward(count, view_id) return __internals.history_forward(count, view_id) end
+--- web.history.forward(2, { view = 3 }) -- Go forward 2 history items for view id 3
+function web.history.forward(count, opts) return __internals.history_forward(count, (opts or {}).view) end
--- Search text inside a view
---
--- @param text string? Text to search
---- @param view_id number? Id of the view
+--- @param opts table? Options
+--- @param opts.view number? View id (default = 0)
---
--- @usage
--- web.search.set_text('whatever') -- Search in current view
---- web.search.set_text('whatever', 5) -- Search in view id 5
-function web.search.set_text(text, view_id) return __internals.search_set_text(text, view_id) end
+--- web.search.set_text('whatever', { view = 5 }) -- Search in view id 5
+function web.search.set_text(text, opts) return __internals.search_set_text(text, (opts or {}).view) end
--- Reset searched text in a view (Same as web.search.set_text(''))
---
---- @param view_id number? Id of the view
+--- @param opts table? Options
+--- @param opts.view number? View id (default = 0)
---
--- @usage
--- web.search.reset() -- Reset search state for current view
---- web.search.reset(5) -- Reset search state for view id 5
-function web.search.reset(view_id) return __internals.search_set_text('', view_id) end
+--- web.search.reset({ view = 5 }) -- Reset search state for view id 5
+function web.search.reset(opts) return __internals.search_set_text('', (opts or {}).view) end
--- Get the last searched text
---
@@ -307,38 +320,48 @@ function web.search.get_text() return __internals.search_get_text() end
--- Highlight next search term for the last searched text
---
---- @param view_id number? Id of the view
+--- @param opts table? Options
+--- @param opts.view number? View id (default = 0)
---
--- @usage
--- web.search.next() -- Next search result in current view
---- web.search.next(5) -- Next search result in view id 5
-function web.search.next(view_id) return __internals.search_next(view_id) end
+--- web.search.next({ view = 5 }) -- Next search result in view id 5
+function web.search.next(opts) return __internals.search_next((opts or {}).view) end
--- Highlight previous search term for the last searched text
---
---- @param view_id number? Id of the view
+--- @param opts table? Options
+--- @param opts.view number? View id (default = 0)
---
--- @usage
--- web.search.previous() -- Previous search result in current view
--- web.search.previous(5) -- Previous search result in view id 5
-function web.search.previous(view_id) return __internals.search_previous(view_id) end
+function web.search.previous(opts) return __internals.search_previous((opts or {}).view) end
--- TODO: Document
-function web.view.scroll(deltax, deltay, view_id) return __internals.view_scroll(deltax, deltay, view_id) end
+--- @param deltax number
+--- @param deltay number
+--- @param opts table? Options
+--- @param opts.view number? View id (default = 0)
+function web.view.scroll(deltax, deltay, opts) return __internals.view_scroll(deltax, deltay, (opts or {}).view) end
--- TODO: Document
-function web.view.scroll_to_top(view_id) return __internals.view_scroll_to_top(view_id) end
+--- @param opts table? Options
+--- @param opts.view number? View id (default = 0)
+function web.view.scroll_to_top(opts) return __internals.view_scroll_to_top((opts or {}).view) end
--- TODO: Document
-function web.view.scroll_to_bottom(view_id) return __internals.view_scroll_to_bottom(view_id) end
+--- @param opts table? Options
+--- @param opts.view number? View id (default = 0)
+function web.view.scroll_to_bottom(opts) return __internals.view_scroll_to_bottom((opts or {}).view) end
--- Maps to values defined in ./src/widgets/Decorations.hpp
local DecorationType = { top = 1, bottom = 2, left = 3, right = 4 }
---- @class DecorationOpts
+--- @table DecorationOpts
--- @field win? number
---- @class Decoration
+--- @table Decoration
--- @field type fun(): 'left'|'right'|'top'|'bottom'
--- @field enable fun(opts?: DecorationOpts): nil
--- @field disable fun(opts?: DecorationOpts): nil
@@ -376,6 +399,7 @@ web.decorations.left = create_decoration_api('left')
web.decorations.right = create_decoration_api('right')
--- Get a list of items for help
+--- @return table<string> help_items List of help item names
function web.help.get_items()
local symbols_json = web.opts.null_docs_dir .. '/api/symbols.json'
local file, _ = io.open(symbols_json, 'r')
@@ -388,14 +412,13 @@ end
--- Open help docs for a given item
---
---- @param item string?
---- @param opts table?
---- @param opts.view number?
+--- @param item string? Help item name
+--- @param opts table? Options
+--- @param opts.view number? View id (default = 0)
function web.help.show(item, opts)
- opts = opts or {}
local url = 'null://docs/api/index.html#' .. (item or '')
- if opts.view ~= nil then
- web.view.set_url(url, opts.view)
+ if opts and opts.view ~= nil then
+ web.view.set_url(url, opts)
else
web.view.create(url)
end
diff --git a/lua/null-browser/defaults/vi.lua b/lua/null-browser/defaults/vi.lua
index 5d9210b..c3775bb 100644
--- a/lua/null-browser/defaults/vi.lua
+++ b/lua/null-browser/defaults/vi.lua
@@ -8,7 +8,7 @@ local config = {
transform_url_input = web.utils.string_trim,
}
-function M.setup(opts)
+function M.configure(opts)
config = web.utils.table_merge(config, opts)
end
@@ -140,7 +140,7 @@ function M.initialize()
local view = web.view.current()
config.menu:select(config.history.list(), { prompt = 'Set url:', query = url or '' }, function(err, result)
if err or not result then return end
- web.view.set_url(web.utils.string_trim(result), view)
+ web.view.set_url(web.utils.string_trim(result), { view = view })
end)
end)
diff --git a/lua/null-browser/utils.lua b/lua/null-browser/utils.lua
index 907f20c..4b1790a 100644
--- a/lua/null-browser/utils.lua
+++ b/lua/null-browser/utils.lua
@@ -40,8 +40,8 @@ end
--- Decodes a string into a lua object
--- @diagnostic disable-next-line: undefined-doc-param
--- @param json_str string Json string to decode
---- @param opts table Options
---- @param opts.null any What to use as null value (default: nil)
+--- @param opts table? Options
+--- @param opts.null any? What to use as null value (default: nil)
--- @return any
web.json.decode = function(json_str, opts)
opts = opts or {}