From b2fb7cd3d765bda9c8bb7fdee93ce7494f30cc10 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 17 Aug 2025 16:17:13 +0530 Subject: Update internal api options --- TODO.org | 17 +-- docs/api/index.html | 245 ++++++++++++++++++++++++++------------- docs/api/symbols.json | 2 +- init.lua | 8 +- lua/null-browser/api.lua | 127 +++++++++++--------- lua/null-browser/defaults/vi.lua | 4 +- lua/null-browser/utils.lua | 4 +- 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 @@ Get the current keymap mode - web.view.close (view_id) + web.view.close (opts) Close view @@ -81,6 +81,10 @@ Get current view id + web.view.current_url () + Get current url + + web.view.list () Get a list of views in the current window @@ -89,7 +93,7 @@ Select a view in current window - web.view.set_url (url, view_id) + web.view.set_url (url, opts) Set url of a given view @@ -102,14 +106,14 @@ web.view.reload (opts) - Relaod a given view + Reload a given view web.view.expose (name, action, opts) Expose a lua function inside a view (Only works with decorations) - web.view.open_devtools (view_id) + web.view.open_devtools (opts) Open devtools window for the view @@ -129,19 +133,19 @@ Get configuration value - web.history.back (count, view_id) + web.history.back (count, opts) Go back in history for given view - web.history.forward (count, view_id) + web.history.forward (count, opts) Go forward in history for given view - web.search.set_text (text, view_id) + web.search.set_text (text, opts) Search text inside a view - web.search.reset (view_id) + web.search.reset (opts) Reset searched text in a view (Same as web.search.set_text('')) @@ -149,23 +153,23 @@ Get the last searched text - web.search.next (view_id) + web.search.next (opts) Highlight next search term for the last searched text - web.search.previous (view_id) + web.search.previous (opts) Highlight previous search term for the last searched text - web.view.scroll (deltax, deltay, view_id) + web.view.scroll (deltax, deltay, opts) TODO: Document - web.view.scroll_to_top (view_id) + web.view.scroll_to_top (opts) TODO: Document - web.view.scroll_to_bottom (view_id) + web.view.scroll_to_bottom (opts) TODO: Document @@ -383,7 +387,7 @@
- web.view.close (view_id) + web.view.close (opts)
Close view @@ -391,9 +395,12 @@

Parameters:

@@ -402,7 +409,7 @@

Usage:

@@ -454,6 +461,30 @@
local view_id = web.view.current()
+ +
+ + web.view.current_url () +
+
+ Get current url + + + +

Returns:

+
    + + string + Current view url +
+ + + +

Usage:

+ +
@@ -507,7 +538,7 @@
- web.view.set_url (url, view_id) + web.view.set_url (url, opts)
Set url of a given view @@ -519,10 +550,12 @@ string Url to open -
  • view_id - number - View id to select +
  • opts Options +
      +
    • view + number? View id (default = 0)
    • +
    @@ -531,7 +564,7 @@

    Usage:

      web.view.set_url('https://foobar.com')
      -web.view.set_url('https://foobar.com', 3) -- Set url for view with id 3
      +web.view.set_url('https://foobar.com', { view = 3 }) -- Set url for view with id 3
  • @@ -546,12 +579,12 @@ web.view.set_url('https:

    Parameters:

    @@ -578,11 +611,17 @@ web.view.set_html('<h
    • js string - HTML string + JS string +
    • +
    • opts Options +
        +
      • view + number? View id (default = 0)
      • -
      • opts - ? RunJSOpts Options +
      • on_result + ? fun(v: any): nil Callback with serialized result of evaluation
      • +
    @@ -591,7 +630,12 @@ web.view.set_html('<h

    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('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, +})
    @@ -600,14 +644,17 @@ web.view.run_js('console web.view.reload (opts)
    - Relaod a given view + Reload a given view

    Parameters:

      -
    • opts - ? ReloadOpts Options +
    • opts Options +
        +
      • view + number? View id (default = 0)
      • +
    @@ -631,14 +678,17 @@ web.view.reload({ view = Parameters:
    • name - string Func name + string Func name
    • action - fun(table):nil Action to call when function is invoked in view + fun(table):nil Action to call when function is invoked in view
    • -
    • opts - ExposeOpts? Options +
    • opts Options +
        +
      • view + number? View id (default = 0)
      • +
    @@ -656,7 +706,7 @@ web.view.reload({ view =
    - web.view.open_devtools (view_id) + web.view.open_devtools (opts)
    Open devtools window for the view @@ -664,10 +714,12 @@ web.view.reload({ view = Parameters:
      -
    • view_id - number - Id of the view +
    • opts Options +
        +
      • view + number? View id (default = 0)
      • +
    @@ -809,7 +861,7 @@ web.view.reload({ view =
    - web.history.back (count, view_id) + web.history.back (count, opts)
    Go back in history for given view @@ -820,10 +872,12 @@ web.view.reload({ view = count number? Number of history items to go back in (default = 1) -
  • view_id - number - Id of the view +
  • opts Options +
      +
    • view + number? View id (default = 0)
    • +
    @@ -831,13 +885,13 @@ web.view.reload({ view = Usage:
      -
      web.history.back(2, 3) -- Go back 2 history items for view id 3
      +
      web.history.back(2, { view = 3 }) -- Go back 2 history items for view id 3
  • - web.history.forward (count, view_id) + web.history.forward (count, opts)
    Go forward in history for given view @@ -848,10 +902,12 @@ web.view.reload({ view = count number? Number of history items to go forward in (default = 1) -
  • view_id - number - Id of the view +
  • opts Options +
      +
    • view + number? View id (default = 0)
    • +
    @@ -859,13 +915,13 @@ web.view.reload({ view = Usage:
      -
      web.history.forward(2, 3) -- Go forward 2 history items for view id 3
      +
      web.history.forward(2, { view = 3 }) -- Go forward 2 history items for view id 3
  • - web.search.set_text (text, view_id) + web.search.set_text (text, opts)
    Search text inside a view @@ -876,10 +932,12 @@ web.view.reload({ view = text string? Text to search -
  • view_id - number - Id of the view +
  • opts Options +
      +
    • view + number? View id (default = 0)
    • +
    @@ -888,13 +946,13 @@ web.view.reload({ view = Usage:
      web.search.set_text('whatever') -- Search in current view
      -web.search.set_text('whatever', 5) -- Search in view id 5
      +web.search.set_text('whatever', { view = 5 }) -- Search in view id 5
  • - web.search.reset (view_id) + web.search.reset (opts)
    Reset searched text in a view (Same as web.search.set_text('')) @@ -902,10 +960,12 @@ web.view.reload({ view = Parameters:
      -
    • view_id - number - Id of the view +
    • opts Options +
        +
      • view + number? View id (default = 0)
      • +
    @@ -914,7 +974,7 @@ web.view.reload({ view = Usage:
      web.search.reset() -- Reset search state for current view
      -web.search.reset(5) -- Reset search state for view id 5
      +web.search.reset({ view = 5 }) -- Reset search state for view id 5
    @@ -938,7 +998,7 @@ web.view.reload({ view =
    - web.search.next (view_id) + web.search.next (opts)
    Highlight next search term for the last searched text @@ -946,10 +1006,12 @@ web.view.reload({ view = Parameters:
      -
    • view_id - number - Id of the view +
    • opts Options +
        +
      • view + number? View id (default = 0)
      • +
    @@ -958,13 +1020,13 @@ web.view.reload({ view = Usage:
      web.search.next() -- Next search result in current view
      -web.search.next(5) -- Next search result in view id 5
      +web.search.next({ view = 5 }) -- Next search result in view id 5
    - web.search.previous (view_id) + web.search.previous (opts)
    Highlight previous search term for the last searched text @@ -972,10 +1034,12 @@ web.view.reload({ view = Parameters:
      -
    • view_id - number - Id of the view +
    • opts Options +
        +
      • view + number? View id (default = 0)
      • +
    @@ -990,7 +1054,7 @@ web.view.reload({ view =
    - web.view.scroll (deltax, deltay, view_id) + web.view.scroll (deltax, deltay, opts)
    TODO: Document @@ -999,14 +1063,19 @@ web.view.reload({ view = Parameters:
    • deltax + number
    • deltay + number
    • -
    • view_id - +
    • opts Options +
        +
      • view + number? View id (default = 0)
      • +
    @@ -1016,7 +1085,7 @@ web.view.reload({ view =
    - web.view.scroll_to_top (view_id) + web.view.scroll_to_top (opts)
    TODO: Document @@ -1024,9 +1093,12 @@ web.view.reload({ view = Parameters:
      -
    • view_id - +
    • opts Options +
        +
      • view + number? View id (default = 0)
      • +
    @@ -1036,7 +1108,7 @@ web.view.reload({ view =
    - web.view.scroll_to_bottom (view_id) + web.view.scroll_to_bottom (opts)
    TODO: Document @@ -1044,9 +1116,12 @@ web.view.reload({ view = Parameters:
      -
    • view_id - +
    • opts Options +
        +
      • view + number? View id (default = 0)
      • +
    @@ -1063,6 +1138,12 @@ web.view.reload({ view = Returns: +
      + + table + help_items List of help item names +
    @@ -1080,12 +1161,12 @@ web.view.reload({ view =
  • item string - + Help item name
  • -
  • opts +
  • opts Options
    • view - number? + number? View id (default = 0)
    @@ -1166,7 +1247,7 @@ web.view.reload({ view = opts Options
    • null - any What to use as null value (default: nil) + any? What to use as null value (default: nil)
    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('

    HJello

    ') --- web.view.set_html('

    HJello

    ', { 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 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 {} -- cgit v1.3.1