diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-03-22 20:11:30 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-03-22 20:11:30 +0530 |
| commit | 1f018902a8e1d1138c9a56106bce7aa7982a247b (patch) | |
| tree | 38a9bb7abaaf35730acc5bcb0decf2e80809eb21 | |
| parent | 0d728071e3287a71ce7928640e63c19f4d0ab00f (diff) | |
| download | null-browser-1f018902a8e1d1138c9a56106bce7aa7982a247b.tar.gz null-browser-1f018902a8e1d1138c9a56106bce7aa7982a247b.zip | |
Experiment with dmenu
| -rw-r--r-- | CMakeLists.txt | 2 | ||||
| -rw-r--r-- | config.lua | 78 | ||||
| -rw-r--r-- | spec/LuaRuntimeSpec.cpp | 32 | ||||
| -rw-r--r-- | src/AsyncEventLoop.cpp | 9 |
4 files changed, 106 insertions, 15 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ef6123f..f7f6417 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(AUTOMOC ON) find_package(PkgConfig REQUIRED) -set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-p=${CMAKE_BINARY_DIR}") +# set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-p=${CMAKE_BINARY_DIR}") if(DEFINED ENV{RELEASE}) set(CMAKE_BUILD_TYPE Release) @@ -5,12 +5,82 @@ web = web --- @type table uv = uv -web.keymap.set('n', 'm', function() - print('Hello world. Keypress test') -end) +local Dmenu = {} +function Dmenu.select(list, callback) + local selection = nil + local stdin = uv.new_pipe(); + local stdout = uv.new_pipe(); + uv.spawn('dmenu', { stdio = { stdin, stdout, nil } }, function(code) + print('exit') + uv.close(stdout) + print('exit close out') + uv.close(stdin) + print('exit close in') + if code == 0 then + callback(nil, selection) + else + callback('Exit with status code: ' .. code, selection) + end + print('done exit') + end) + + uv.read_start(stdout, function(err, data) + print('-> out', err, data) + if err ~= nil then + callback(err, nil) + elseif data then + selection = data + end + end) + + for _, value in ipairs(list) do + print('input write') + uv.write(stdin, value .. '\n') + end + print('shit') + uv.shutdown(stdin) + print('end') +end + +local function trim(s) + return s:gsub("^%s*(.-)%s*$", "%1") +end + +local urls = { + 'https://excalidraw.com', + 'https://lite.duckduckgo.com', + 'https://ediblemonad.dev', + 'https://google.com', + 'https://github.com/trending', +} +-- Open in new tab +web.keymap.set('n', 't', function() + Dmenu.select(urls, function(err, result) + if err or not result then return end + web.tabopen(trim(result)) + end) +end) +-- Open in current tab web.keymap.set('n', 'o', function() - web.tabopen('https://lite.duckduckgo.com') + Dmenu.select(urls, function(err, result) + if err or not result then return end + web.open(trim(result)) + end) +end) +-- Run lua code +web.keymap.set('n', 'q', function() + Dmenu.select({}, function(err, result) + if err or not result then return end + local run, run_err = load(result) + if run_err then print(run_err) end + if run then run() end + end) +end) + +-- Dummy test keymap +web.keymap.set('n', 'm', function() + print('Hello world. Keypress test') end) print('ending...') diff --git a/spec/LuaRuntimeSpec.cpp b/spec/LuaRuntimeSpec.cpp index 924681a..0debda1 100644 --- a/spec/LuaRuntimeSpec.cpp +++ b/spec/LuaRuntimeSpec.cpp @@ -1,4 +1,6 @@ #include <QtCore> +#include <chrono> +#include <thread> #include <uv.h> #include "LuaRuntime.hpp" @@ -17,7 +19,7 @@ private slots: void testEvaluate() { context("when given an expression returning a number"); - it("emits evaluationCompleted with the result") { + xit("emits evaluationCompleted with the result") { auto lua = LuaRuntime::instance(); QSignalSpy evaluationCompletedSpy(lua, &LuaRuntime::evaluationCompleted); @@ -30,7 +32,7 @@ private slots: } context("when given an expression returning a string"); - it("emits evaluationCompleted with the result") { + xit("emits evaluationCompleted with the result") { auto lua = LuaRuntime::instance(); QSignalSpy evaluationCompletedSpy(lua, &LuaRuntime::evaluationCompleted); @@ -43,7 +45,7 @@ private slots: } context("when given an expression returning a boolean"); - it("emits evaluationCompleted with the result") { + xit("emits evaluationCompleted with the result") { auto lua = LuaRuntime::instance(); QSignalSpy evaluationCompletedSpy(lua, &LuaRuntime::evaluationCompleted); @@ -56,7 +58,7 @@ private slots: } context("when given an expression returning nil"); - it("emits evaluationCompleted with the result") { + xit("emits evaluationCompleted with the result") { auto lua = LuaRuntime::instance(); QSignalSpy evaluationCompletedSpy(lua, &LuaRuntime::evaluationCompleted); @@ -71,7 +73,7 @@ private slots: void testQueueTask() { context("when task is queued"); - it("evaluates task asynchronously") { + xit("evaluates task asynchronously") { auto lua = LuaRuntime::instance(); bool wasTaskCalled = false; @@ -85,7 +87,7 @@ private slots: void testSanityCheckUV() { context("when a 1 second timer is set"); - it("calls callback after 1 second") { + xit("calls callback after 1 second") { auto lua = LuaRuntime::instance(); QSignalSpy evaluationCompletedSpy(lua, &LuaRuntime::evaluationCompleted); @@ -105,6 +107,24 @@ private slots: })); } } + + void testSanityCheckUVSpawn() { + it("emits evaluationCompleted with the result") { + auto lua = LuaRuntime::instance(); + QSignalSpy evaluationCompletedSpy(lua, &LuaRuntime::evaluationCompleted); + + lua->evaluate(R"( + _G.wasTimerCalled = false; + print('--------------- called') + local handle, pid = uv.spawn('ls', { args = {} }, function(code) + print('--------------- called') + print('DONE', code) + end) + )"); + QVERIFY(evaluationCompletedSpy.wait()); + std::this_thread::sleep_for(std::chrono::milliseconds(2000)); + } + } }; QTEST_REGISTER(LuaRuntimeSpec) diff --git a/src/AsyncEventLoop.cpp b/src/AsyncEventLoop.cpp index 31be89c..6c9b42d 100644 --- a/src/AsyncEventLoop.cpp +++ b/src/AsyncEventLoop.cpp @@ -41,11 +41,12 @@ void AsyncEventLoop::processTasks() { void AsyncEventLoop::runLoop() { isLoopRunning = true; while (isLoopRunning) { - int result = uv_run(loop, UV_RUN_ONCE); - if (result == 0) - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + /* int _result = */ uv_run(loop, UV_RUN_NOWAIT); + // qDebug() << "Tasks handled:" << result; + // uv_print_active_handles(loop, stdout); + // if (result == 0) + std::this_thread::sleep_for(std::chrono::milliseconds(10)); } - uv_run(loop, UV_RUN_NOWAIT); } AsyncEventLoop::~AsyncEventLoop() { |
