diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-07-26 11:59:38 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-07-26 11:59:38 +0530 |
| commit | 2078c60477842d7cf6991148e23979565737a8b5 (patch) | |
| tree | 980e2aea150e85c6b87f2b521fce1006486244d8 /lua | |
| parent | 68448538172663279919b29dd09b5faa51e0628a (diff) | |
| download | null-browser-2078c60477842d7cf6991148e23979565737a8b5.tar.gz null-browser-2078c60477842d7cf6991148e23979565737a8b5.zip | |
Refactor heavy + extras.tabline module (incomplete)
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/null-browser/api.lua | 1 | ||||
| -rw-r--r-- | lua/null-browser/defaults/vi.lua | 2 | ||||
| -rw-r--r-- | lua/null-browser/extras/tabline.lua | 77 |
3 files changed, 79 insertions, 1 deletions
diff --git a/lua/null-browser/api.lua b/lua/null-browser/api.lua index 8b5cebd..598594e 100644 --- a/lua/null-browser/api.lua +++ b/lua/null-browser/api.lua @@ -318,6 +318,7 @@ local function create_decoration_api(type) __internals.decorations_set_enabled(type, enabled, (opts or {}).win) end; return { + type = function() return type end, enable = function(opts) set_enabled(true, opts) end, disable = function(opts) set_enabled(false, opts) end, is_enabled = function(opts) diff --git a/lua/null-browser/defaults/vi.lua b/lua/null-browser/defaults/vi.lua index 0ef5314..d6193de 100644 --- a/lua/null-browser/defaults/vi.lua +++ b/lua/null-browser/defaults/vi.lua @@ -82,7 +82,7 @@ function M.initialize() web.keymap.set('n', '<space>b', function() local views_list = {} local views = web.view.list() - for index, view in ipairs(web.view.list()) do + for index, view in ipairs(views) do table.insert(views_list, index .. ': ' .. view.title .. ' (' .. view.url .. ')') end diff --git a/lua/null-browser/extras/tabline.lua b/lua/null-browser/extras/tabline.lua new file mode 100644 index 0000000..c278df5 --- /dev/null +++ b/lua/null-browser/extras/tabline.lua @@ -0,0 +1,77 @@ +local tabline = {} + +-- TODO: click interaction +-- TODO: vertical tabs +function tabline.init(opts) + local decoration = (opts or {}).decoration or web.decorations.top + + web.event.add_listener('WinCreated', { + callback = function(event) + decoration.enable({ win = event.win_id }) + tabline.show_tabs_in_window(event.win_id, decoration); + end, + }) + + -- Toggle tabline in current window + web.keymap.set('n', '<c-b>', function() + if decoration.is_enabled({ win = 0 }) then + decoration.disable({ win = 0 }) + else + decoration.enable({ win = 0 }) + end + end) +end + +function tabline.show_tabs_in_window(win_id, decoration) + web.event.add_listener('UrlChanged', { + callback = function() + if not decoration.is_enabled({ win = win_id }) then return end + + web.view.set_html(tabline.tabs_html(), { + view = decoration.view({ win = win_id }), + }) + end, + }) +end + +function tabline.tabs_html() + local views_html = '' + for index, view in ipairs(web.view.list()) do + -- TODO: Sanitize this stuff + local text = index .. ': ' .. view.title .. ' (' .. view.url .. ')' + local classes = 'tab' + if web.view.current() == view.id then classes = classes .. ' current' end + local html = '<div class="' .. classes .. '">' .. text .. '</div>' + views_html = views_html .. html + end + + return '<style>' .. tabline.css() .. '</style>' .. + '<div class="tabs">' .. views_html .. '</div>' +end + +function tabline.css() + return [[ + html, body { + background: #000; + } + .tabs { + display: flex; + align-items: stretch; + height: 100vh; + } + .tab { + flex: 1; + width: 100%; + overflow: hidden; + text-overflow: ellipsis; + text-wrap: nowrap; + min-width: 0; + border-left: 1px solid white; + } + .tab.current { + background: #333; + } + ]] +end + +return tabline |
