diff options
| -rw-r--r-- | TODO.org | 2 | ||||
| -rw-r--r-- | init.lua | 29 | ||||
| -rw-r--r-- | lua/null-browser/extras/statusline.lua | 74 | ||||
| -rw-r--r-- | lua/null-browser/extras/tabline.lua | 7 | ||||
| -rw-r--r-- | src/WindowActionRouter.cpp | 8 | ||||
| -rw-r--r-- | src/events/ModeChangedEvent.hpp | 19 | ||||
| -rw-r--r-- | src/widgets/EdgeDecoration.cpp | 5 | ||||
| -rw-r--r-- | src/widgets/EdgeDecoration.hpp | 2 |
8 files changed, 112 insertions, 34 deletions
@@ -2,9 +2,9 @@ - [X] Decorations api (just for statusline) - [X] web.schedule - [X] Create view with html (web.view.set_html()) +- [X] Expose JS <-> lua in page (web.view.expose()) - [-] Tests for api - [ ] Run JS in page (web.view.eval_js()) -- [ ] Expose JS <-> lua in page (web.view.expose_js()) - [ ] web.decorations.*.set_size() - [ ] f-key navigation - [ ] Fullscreen @@ -54,33 +54,10 @@ web.event.add_listener('NotificationReceived', { end, }) -local start_clock = function(win_id) - local timer = web.uv.new_timer() - timer:start(500, 1000, function() - local view = web.decorations.bottom.view({ win = win_id }) - if view ~= nil then - local time = os.date("%X", os.time()) - web.view.set_html('Time: ' .. time, { view = view }) - end - end) -end - +-- Tabline require 'null-browser.extras.tabline'.init() --- Decorations config --- web.event.add_listener('WinCreated', { --- callback = function(event) --- web.decorations.bottom.enable({ win = event.win_id }) --- start_clock(event.win_id) --- end, --- }) - -web.keymap.set('n', '<space>gg', function() - if web.decorations.bottom.is_enabled({ win = 0 }) then - web.decorations.bottom.disable({ win = 0 }) - else - web.decorations.bottom.enable({ win = 0 }) - end -end) +-- Statusline +require 'null-browser.extras.statusline'.init() print('ending...') diff --git a/lua/null-browser/extras/statusline.lua b/lua/null-browser/extras/statusline.lua new file mode 100644 index 0000000..99b82cb --- /dev/null +++ b/lua/null-browser/extras/statusline.lua @@ -0,0 +1,74 @@ +local statusline = {} + +local mode_labels = { n = "NORMAL", i = "INSERT" } + +function statusline.init(opts) + local decoration = (opts or {}).decoration or web.decorations.bottom + + web.event.add_listener('WinCreated', { + callback = function(event) + decoration.enable({ win = event.win_id }) + statusline.show_status_in_window(event.win_id, decoration) + end, + }) + + web.keymap.set('n', '<space>gg', function() + if decoration.is_enabled({ win = 0 }) then + decoration.disable({ win = 0 }) + else + decoration.enable({ win = 0 }) + end + end) +end + +function statusline.show_status_in_window(win_id, decoration) + local show_statusline = function() + local view = decoration.view({ win = win_id }) + if view == nil then return end + web.view.set_html(statusline.html(), { view = view }) + end + + web.schedule(function() show_statusline() end) + web.event.add_listener('ModeChanged', { + callback = function(_) show_statusline() end, + }) +end + +local mode_styles = { + n = "background-color: #007070; color: white;", + i = "background-color: #e06c75; color: white;", +} + +function statusline.html() + local mode = web.keymap.get_mode() + local mode_label = mode_labels[mode] or mode + local styles = '<style>' .. statusline.css() .. '</style>' + local mode_style = mode_styles[mode] or "" + local html = '<div class="status">' .. + '<div class="mode" style="' .. mode_style .. '">' .. mode_label .. '</div>' .. + '</div>' + return styles .. html +end + +function statusline.css() + return [[ + .status { + width: 100%; + height: 100vh; + display: flex; + justify-content: flex-start; + align-items: stretch; + background-color: #000; + } + .mode { + display: flex; + justify-content: center; + align-items: center; + padding: 0 8px; + font-weight: bold; + background-color: #888; + } + ]] +end + +return statusline diff --git a/lua/null-browser/extras/tabline.lua b/lua/null-browser/extras/tabline.lua index b0d7761..42612e9 100644 --- a/lua/null-browser/extras/tabline.lua +++ b/lua/null-browser/extras/tabline.lua @@ -1,6 +1,5 @@ local tabline = {} --- TODO: click interaction -- TODO: vertical tabs function tabline.init(opts) local decoration = (opts or {}).decoration or web.decorations.top @@ -50,7 +49,7 @@ function tabline.tabs_html() local classes = 'tab' if web.view.current() == view.id then classes = classes .. ' current' end local onclick = '__nullbrowser.tab_select({ view: ' .. view.id .. ' })' - local html = '<div class="' .. classes .. '" onclick="' .. onclick .. '">' .. text .. '</div>' + local html = '<button class="' .. classes .. '" onclick="' .. onclick .. '">' .. text .. '</button>' views_html = views_html .. html end @@ -69,13 +68,17 @@ function tabline.css() height: 100vh; } .tab { + all: unset; flex: 1; width: 100%; overflow: hidden; text-overflow: ellipsis; text-wrap: nowrap; + text-align: left; min-width: 0; border-left: 1px solid white; + vertical-align: middle; + padding: 0 8px; } .tab.current { background: #333; diff --git a/src/WindowActionRouter.cpp b/src/WindowActionRouter.cpp index 3aeabc7..d0cc6d0 100644 --- a/src/WindowActionRouter.cpp +++ b/src/WindowActionRouter.cpp @@ -4,6 +4,7 @@ #include <unordered_map> #include "LuaRuntime.hpp" +#include "events/ModeChangedEvent.hpp" #include "keymap/KeymapEvaluator.hpp" #include "widgets/BrowserWindow.hpp" @@ -19,8 +20,11 @@ void WindowActionRouter::initialize(Configuration *config) { configuration = config; connect(&runtime, &LuaRuntime::keymap_add_requested, this, &WindowActionRouter::add_keymap); - connect(&runtime, &LuaRuntime::keymap_mode_update_requested, this, - [](const QString &mode) { KeymapEvaluator::instance().set_current_mode(mode); }); + connect(&runtime, &LuaRuntime::keymap_mode_update_requested, this, [](const QString &mode) { + KeymapEvaluator::instance().set_current_mode(mode); + auto *event = new ModeChangedEvent(mode); + WindowActionRouter::instance().dispatch_event(event); + }); // Configuration connect(&runtime, &LuaRuntime::config_updated, configuration, &Configuration::set_config); diff --git a/src/events/ModeChangedEvent.hpp b/src/events/ModeChangedEvent.hpp new file mode 100644 index 0000000..fcb7dd2 --- /dev/null +++ b/src/events/ModeChangedEvent.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include <QtCore> +#include <lua.hpp> + +#include "events/Event.hpp" +#include "keymap/KeymapEvaluator.hpp" + +class ModeChangedEvent : public Event { +public: + const KeyMode mode; + + ModeChangedEvent(KeyMode mode) : mode(std::move(mode)) { kind = "ModeChanged"; } + + void lua_push(lua_State *state) const override { + Event::lua_push(state); + SET_FIELD("mode", string, mode.toStdString().c_str()) + } +}; diff --git a/src/widgets/EdgeDecoration.cpp b/src/widgets/EdgeDecoration.cpp index ed48857..7351552 100644 --- a/src/widgets/EdgeDecoration.cpp +++ b/src/widgets/EdgeDecoration.cpp @@ -4,7 +4,6 @@ #include <qlabel.h> #include <qwebengineview.h> -#include "LuaRuntime.hpp" #include "widgets/WebView.hpp" #include "widgets/WebViewStack.hpp" @@ -28,9 +27,11 @@ QString default_html_layout = R"HTML( :where(html, body) { margin: 0; padding: 0; - background: #333; + background: #111; color: white; overflow: hidden; + text-size: 12px; + font-family: monospace; } </style> diff --git a/src/widgets/EdgeDecoration.hpp b/src/widgets/EdgeDecoration.hpp index 2af567c..3c90cfb 100644 --- a/src/widgets/EdgeDecoration.hpp +++ b/src/widgets/EdgeDecoration.hpp @@ -32,7 +32,7 @@ private: QWebEngineProfile *profile; bool enabled = false; QString html_content = ""; - uint16_t size = 24; + uint16_t size = 20; void setup_webview(); }; |
