From f34ca241eeab56679f49dde006abe10cbc15e314 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 27 Jul 2025 14:55:17 +0530 Subject: Add url to statusline --- lua/null-browser/extras/statusline.lua | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'lua') diff --git a/lua/null-browser/extras/statusline.lua b/lua/null-browser/extras/statusline.lua index 99b82cb..33a0220 100644 --- a/lua/null-browser/extras/statusline.lua +++ b/lua/null-browser/extras/statusline.lua @@ -1,6 +1,6 @@ local statusline = {} -local mode_labels = { n = "NORMAL", i = "INSERT" } +local mode_labels = { n = 'NORMAL', i = 'INSERT' } function statusline.init(opts) local decoration = (opts or {}).decoration or web.decorations.bottom @@ -29,34 +29,46 @@ function statusline.show_status_in_window(win_id, decoration) end web.schedule(function() show_statusline() end) - web.event.add_listener('ModeChanged', { + web.event.add_listener({ 'ModeChanged', 'UrlChanged' }, { callback = function(_) show_statusline() end, }) end local mode_styles = { - n = "background-color: #007070; color: white;", - i = "background-color: #e06c75; color: white;", + n = 'background-color: #007070; color: white;', + i = 'background-color: #e06c75; color: white;', } +function statusline.current_url() + local current_view = web.view.current(); + for _, view in ipairs(web.view.list()) do + if view.id == current_view then + return view.url + end + end + return "" +end + function statusline.html() local mode = web.keymap.get_mode() + local url = statusline.current_url() local mode_label = mode_labels[mode] or mode local styles = '' - local mode_style = mode_styles[mode] or "" - local html = '
' .. + local mode_style = mode_styles[mode] or '' + local html = '
' .. '
' .. mode_label .. '
' .. + '
' .. url .. '
' .. '
' return styles .. html end function statusline.css() return [[ - .status { + .statusline { width: 100%; height: 100vh; display: flex; - justify-content: flex-start; + justify-content: space-between; align-items: stretch; background-color: #000; } @@ -68,6 +80,12 @@ function statusline.css() font-weight: bold; background-color: #888; } + .url { + display: flex; + justify-content: flex-end; + align-items: center; + padding: 0 8px; + } ]] end -- cgit v1.3.1