diff options
| -rw-r--r-- | README.md | 7 | ||||
| -rw-r--r-- | TODO.org | 30 | ||||
| -rw-r--r-- | init.lua | 24 | ||||
| -rw-r--r-- | lua/null-browser/defaults/vi.lua | 14 | ||||
| -rw-r--r-- | lua/null-browser/extras/dmenu.lua | 32 |
5 files changed, 66 insertions, 41 deletions
@@ -11,16 +11,15 @@ This web browser is just a stack of web views that can be controlled using lua. - use dmenu, rofi, fzf in a terminal, etc. for url input - **No tab ui** - use dmenu, rofi, etc. to show a list of tabs on key - - use tabbed (x11) with multiple windows + - use [tabbed (X11)](https://tools.suckless.org/tabbed/) with multiple windows - use window manager with multiple windows - **No persistant history** - save it in a file on UrlChanged event and show as completion for your url input - same as above but in a sqlite db instead +- **No notifications** + - Call notify-send (or whatever) on NotificationReceived event - **No splits** - use a window manager -- **No tab ui** - - use a window manager - - use [tabbed (X11)](https://tools.suckless.org/tabbed/) - **No buttons** - define key bindings - **No built-in ad blocker** @@ -1,6 +1,6 @@ ** Usable - [-] Tests for api -- [ ] Permission list/allow/deny api +- [ ] Permission list/allow/deny lua api - [ ] Fullscreen - [ ] Zoom in/out - [ ] Run JS in page (web.view.eval_js()) @@ -11,6 +11,7 @@ ** Bugs - [ ] INVESTIGATE: Check why urlchanged doesnt fire for first url open sometimes - [ ] INVESTIGATE: Segfault on close sometimes +- [ ] API's don't validate types. (type conversion segfaults) ** Next - [ ] Configuration validation @@ -91,24 +92,15 @@ web.search.get_search_text() web.search.current() web.search.total() -web.keymap.set('n', '/', function() - dmenu.input({ prompt = 'Search:' }, function(err, input) - if err or not input then return end - web.search.set_search_text(input) - end) -end) -web.keymap.set('n', 'n', function() web.search.next() end) -web.keymap.set('n', 'p', function() web.search.prev() end) - -web.event.add_listener('SearchChanged', { - callback = function() - local label = - web.search.get_search_text() .. ': ' .. web.search.current() .. '/' .. web.search.total() - -- CALL notify-send - -- OR inject js into view to show ui - end, +web.decorations.configure('left', { + url = 'https://something.com', + size = 100, }) +local sidebar_decoration = web.decorations.left() +web.decorations.delete(sidebar_decoration) +web.decorations.hide(sidebar_decoration) -web.view.open_devtools() -web.view.open_devtools(2) +web.decorations.configure('top', { size = 28 }) +local tabline_decoration = web.decorations.top() +web.view.set_html('<div>Hello world</div>', { view_id = tabline_decoration.view_id }) #+end_src @@ -5,19 +5,30 @@ web.set('close_window_when_no_views', true) web.set('user_agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36') web.set('downloads_dir', os.getenv('HOME') .. '/Downloads/firefox') +web.set('permissions_persistance', 'never') 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['g'] = 'https://github.com/{}' +search_engines.urls['y'] = 'https://youtube.com/results?search_query={}' +search_engines.urls['r'] = 'https://reddit.com/{}' local Dmenu = require 'null-browser.extras.dmenu' local menu = Dmenu:new { - command = os.getenv('HOME') .. '/scripts/fzfmenu.sh', - prompt_arg = '--prompt', - query_arg = '-q', - args = { 'input', '--layout=default' }, + select_last_line = false, + args = { '-r' }, + transform_output = function(selections) + if type(selections) ~= "table" then return selections end + if #selections <= 1 then return selections[1] end + return selections[#selections - 1] + end, + -- command = os.getenv('HOME') .. '/scripts/fzfmenu.sh', + -- prompt_arg = '--prompt', + -- query_arg = '-q', + -- args = { 'input', '--layout=default', '--print-query' }, } require 'null-browser.defaults.vi'.setup { @@ -26,7 +37,10 @@ require 'null-browser.defaults.vi'.setup { transform_url_input = search_engines.transform_url_input, } -web.set('permissions_persistance', 'never') +-- web.keymap.set('zoom', 'j', function() web.view.zoom_out() end) +-- web.keymap.set('zoom', 'k', function() web.view.zoom_in() end) +-- web.keymap.set('zoom', '<esc>', function() web.keymap.set_mode('n') end) +-- web.keymap.set('n', 'z', function() web.keymap.set_mode('zoom') end) web.event.add_listener('NotificationReceived', { callback = function(event) diff --git a/lua/null-browser/defaults/vi.lua b/lua/null-browser/defaults/vi.lua index 86302ee..2213fc5 100644 --- a/lua/null-browser/defaults/vi.lua +++ b/lua/null-browser/defaults/vi.lua @@ -42,10 +42,11 @@ function M.initialize() end) -- Delete from history web.keymap.set('n', 'dh', function() - config.menu:select(config.history.list(), { prompt = 'Delete history:' }, function(err, result) - if err or not result then return end - config.history.delete(web.utils.string_trim(result)) - end) + config.menu:select(config.history.list(), { prompt = 'Delete history:', select_last_line = true }, + function(err, result) + if err or not result then return end + config.history.delete(web.utils.string_trim(result)) + end) end) -- Search @@ -85,7 +86,7 @@ function M.initialize() table.insert(views_list, index .. ': ' .. view.title .. ' (' .. view.url .. ')') end - config.menu:select(views_list, { prompt = 'Views:' }, function(err, result) + config.menu:select(views_list, { prompt = 'Views:', select_last_line = true }, function(err, result) if err or not result then return end local index_str, _ = string.gsub(result, '%s*:.*$', '') local index = tonumber(index_str) @@ -140,7 +141,8 @@ function M.initialize() web.event.add_listener('PermissionRequested', { callback = function(event) - config.menu:select({ 'Allow', 'Deny' }, { prompt = 'Requesting permission for ' .. event.permission_type }, + config.menu:select({ 'Allow', 'Deny' }, + { prompt = 'Requesting permission for ' .. event.permission_type, select_last_line = true }, function(err, choice) if err then return end if web.utils.string_trim(choice) == 'Allow' then diff --git a/lua/null-browser/extras/dmenu.lua b/lua/null-browser/extras/dmenu.lua index f817294..5d660bb 100644 --- a/lua/null-browser/extras/dmenu.lua +++ b/lua/null-browser/extras/dmenu.lua @@ -10,6 +10,8 @@ function Dmenu:new(opts) query_arg = '-it', prompt = nil, query = nil, + select_last_line = true, + transform_output = nil, } local obj = {} setmetatable(obj, self) @@ -18,7 +20,7 @@ function Dmenu:new(opts) return obj end -function Dmenu:prepare_command(opts) +function Dmenu:prepare_options(opts) opts = opts or {} local args = web.utils.table_merge({}, self.options.args or {}) for _, arg in ipairs(opts.args or {}) do @@ -37,29 +39,45 @@ function Dmenu:prepare_command(opts) table.insert(args, options.query) end - return { command = options.command, args = args } + return { + command = options.command, + args = args, + select_last_line = options.select_last_line, + transform_output = options.transform_output or function(s) return s end, + } end function Dmenu:select(list, opts, callback) - local cmd = self:prepare_command(opts) + local options = self:prepare_options(opts) local stdin = web.uv.new_pipe(); local stdout = web.uv.new_pipe(); local selection = nil - web.uv.spawn(cmd.command, { args = cmd.args, stdio = { stdin, stdout, nil } }, function(code) + if not options.select_last_line then + selection = {} + end + web.uv.spawn(options.command, { args = options.args, stdio = { stdin, stdout, nil } }, function(code) web.uv.close(stdout) web.uv.close(stdin) + local result = options.transform_output(selection) if code == 0 then - callback(nil, selection) + callback(nil, result) else - callback('[dmenu] Exit with status code: ' .. code, selection) + callback('[dmenu] Exit with status code: ' .. code, result) end end) web.uv.read_start(stdout, function(_, data) - if data then selection = data end + if data then + if options.select_last_line then + selection = data + else + selection = selection or {} + table.insert(selection, data) + end + end end) for _, value in ipairs(list) do |
