This commit is contained in:
Aire-One 2024-10-28 03:53:06 +01:00
parent 44686975f4
commit 7978de8a37
26 changed files with 330 additions and 40 deletions

23
.busted Normal file
View File

@ -0,0 +1,23 @@
if os.getenv "LOCAL_LUA_DEBUGGER_VSCODE" == "1" then
require("lldebugger").start()
end
require("tl").loader()
local function lua_module_paths(module_base_path)
local paths = (module_base_path .. "/?.lua;") .. (module_base_path .. "/?/init.lua;")
return paths
end
return {
_all = {
-- lua_module_paths "/usr/share/awesome/lib" ..
lpath = lua_module_paths "types" .. lua_module_paths "src",
loaders = { "teal" },
helper = "spec/helper.lua",
},
coverage = {
coverage = true,
},
}

View File

@ -2,7 +2,9 @@
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
"version": "0.2",
"useGitignore": true,
"ignorePaths": [".git"],
"ignorePaths": [
".git"
],
"enableGlobDot": true,
"words": [
"Aire-One",
@ -15,8 +17,10 @@
"fatalwarnings",
"fullscreen",
"hasitem",
"ipairs",
"JohnnyMorganz",
"keygrabber",
"keygroup",
"ldoc",
"leafo",
"luacheck",
@ -24,7 +28,9 @@
"luadoc",
"luarocks",
"lunarmodules",
"metamethod",
"mktemp",
"mousebinding",
"mousebindings",
"mousegrabber",
"rockspec",

View File

@ -3,6 +3,7 @@ std = "min"
cache = true
include_files = {
".busted",
".luacheckrc",
"*.rockspec",
"src/",

25
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,25 @@
{
"version": "0.2.0",
"configurations": [
// {
// "name": "Debug",
// "type": "lua-local",
// "request": "launch",
// "program": {
// "command": "just"
// },
// "args": ["run"],
// "scriptFiles": ["${workspaceFolder}/**/*.tl"]
// },
{
"name": "Debug specs",
"type": "lua-local",
"request": "launch",
"program": {
"command": "make"
},
"args": ["test"],
"scriptFiles": ["${workspaceFolder}/**/*.tl"]
}
]
}

View File

@ -8,8 +8,10 @@
},
"stylua.targetReleaseVersion": "latest",
"files.associations": {
".busted": "lua",
".luacheckrc": "lua",
"*.rockspec": "lua",
"config.ld": "lua"
}
},
"debug.allowBreakpointsEverywhere": true
}

View File

@ -22,3 +22,6 @@ lint: luacheck stylua ldoc-dryrun cspell lint-rockspec
ldoc:
ldoc .
test:
luarocks test

View File

@ -1,9 +1,12 @@
rockspec_format = "3.0"
package = "awesome-slot"
version = "dev-1"
source = {
url = "git+https://github.com/Aire-One/awesome-slot.git",
}
description = {
summary = "A declarative API to connect signals for the AwesomeWM.",
detailed = "A declarative API to connect signals for the AwesomeWM.",
@ -15,6 +18,8 @@ description = {
"declarative",
},
}
-- TODO: Build Teal files
build = {
type = "builtin",
modules = {
@ -29,3 +34,11 @@ build = {
"doc",
},
}
test_dependencies = {
"busted-tl",
}
test = {
type = "busted",
}

1
spec/global_env_def.tl Normal file
View File

@ -0,0 +1 @@
require("busted")

15
spec/helper.lua Normal file
View File

@ -0,0 +1,15 @@
package.loaded["awful.button"] = setmetatable({}, {
__call = function()
return {}
end,
})
package.loaded["awful.key"] = setmetatable({}, {
__call = function()
return {}
end,
})
package.loaded["awful.keyboard"] = {}
package.loaded["awful.mouse"] = {}

View File

@ -0,0 +1,40 @@
local Key = require("awful.key")
local client = require("awesome-slot.slots.client")
local keyboard = require("awful.keyboard")
describe("Test awesome-slot.slots.client.append_keybindings", function()
-- Spies cannot be used with Teal since it doesn't allow to augment assert.
-- Instead, we will use a local variable to store the registered bindings and
-- override the append_client_keybinding function to store the bindings in
-- the local variable.
local registered_bindings: { Key } = {}
function keyboard.append_client_keybindings(bindings: { Key })
for _, binding in ipairs(bindings) do
table.insert(registered_bindings , binding)
end
end
before_each(function()
registered_bindings = {}
end)
it("should invoke awful.mouse.append_client_keybinding", function()
local bindings = {
Key {
modifiers = { "Mod1" },
key = "a",
on_press = function() end,
},
}
client.append_keybindings {
keybindings = bindings,
}
assert(#registered_bindings == #bindings)
for i=1,#bindings do
assert(registered_bindings[i] == bindings[i])
end
end)
end)

View File

@ -0,0 +1,40 @@
local type Button = require("awful.button")
local client = require("awesome-slot.slots.client")
local mouse = require("awful.mouse")
describe("Test awesome-slot.slots.client.append_mousebindings", function()
-- Spies cannot be used with Teal since it doesn't allow to augment assert.
-- Instead, we will use a local variable to store the registered bindings and
-- override the append_client_mousebinding function to store the bindings in
-- the local variable.
local registered_bindings: { Button } = {}
function mouse.append_client_mousebindings(bindings: { Button })
for _, binding in ipairs(bindings) do
table.insert(registered_bindings , binding)
end
end
before_each(function()
registered_bindings = {}
end)
it("should invoke awful.mouse.append_client_mousebinding", function()
local bindings = {
Button {
modifiers = { "Mod1" },
button = 1,
on_press = function() end,
},
}
client.append_mousebindings {
mousebindings = bindings,
}
assert(#registered_bindings == #bindings)
for i=1,#bindings do
assert(registered_bindings[i] == bindings[i])
end
end)
end)

7
spec/tlconfig.lua Normal file
View File

@ -0,0 +1,7 @@
return {
include_dir = {
"../src",
"../types",
},
global_env_def = "global_env_def",
}

View File

@ -1,19 +0,0 @@
local client_slots = {}
function client_slots.append_mousebindings(params)
local mouse = require "awful.mouse"
for _, bindings in pairs(params.mousebindings) do
mouse.append_client_mousebindings(bindings)
end
end
function client_slots.append_keybindings(params)
local keyboard = require "awful.keyboard"
for _, bindings in pairs(params.keybindings) do
keyboard.append_client_keybindings(bindings)
end
end
return client_slots

View File

@ -0,0 +1,25 @@
local type Button = require("awful.button")
local type Key = require("awful.key")
local keyboard = require("awful.keyboard")
local mouse = require("awful.mouse")
local record ClientSlots
end
local record AppendMousebindingsParams
mousebindings: { Button }
end
function ClientSlots.append_mousebindings(params: AppendMousebindingsParams)
mouse.append_client_mousebindings(params.mousebindings)
end
local record AppendKeybindingsParams
keybindings: { Key }
end
function ClientSlots.append_keybindings(params: AppendKeybindingsParams)
keyboard.append_client_keybindings(params.keybindings)
end
return ClientSlots

View File

@ -1,19 +0,0 @@
local ruled_slots = {}
function ruled_slots.append_client_rules(params)
local client = require "ruled.client"
for _, rule in pairs(params.rules) do
client.append_rule(rule)
end
end
function ruled_slots.append_notification_rules(params)
local notification = require "ruled.notification"
for _, rule in pairs(params.rules) do
notification.append_rule(rule)
end
end
return ruled_slots

View File

@ -0,0 +1,21 @@
local client = require("ruled.client")
local notification = require("ruled.notification")
local record RuledSlots
end
local record AppendClientRulesParams
rules: { client.RuleComponent }
end
function RuledSlots.append_client_rules(params: AppendClientRulesParams)
client.append_rules(params.rules)
end
function RuledSlots.append_notification_rules(params)
for _, rule in pairs(params.rules) do
notification.append_rule(rule)
end
end
return RuledSlots

8
tlconfig.lua Normal file
View File

@ -0,0 +1,8 @@
return {
build_dir = "build",
source_dir = "src",
include_dir = {
"src",
"types",
},
}

14
types/awful/button.d.tl Normal file
View File

@ -0,0 +1,14 @@
local type KeyModifier = require("awful.key_modifier")
local interface ButtonProps
modifiers: { KeyModifier }
button: number
on_press: function()
on_release: function()
end
local record Button is ButtonProps
metamethod __call: function(Button, ButtonProps): Button
end
return Button

15
types/awful/key.d.tl Normal file
View File

@ -0,0 +1,15 @@
local type KeyModifier = require("awful.key_modifier")
local interface KeyProps
modifiers: { KeyModifier }
key: string
keygroup: string
on_press: function()
on_release: function()
end
local record Key is KeyProps
metamethod __call: function(Key, KeyProps): Key
end
return Key

View File

@ -0,0 +1,13 @@
local enum KeyModifier
"Any"
"Mod1"
"Mod2"
"Mod3"
"Mod4"
"Mod5"
"Shift"
"Lock"
"Control"
end
return KeyModifier

View File

@ -0,0 +1,7 @@
local type Key = require("awful.key")
local record Keyboard
append_client_keybindings: function({ Key })
end
return Keyboard

7
types/awful/mouse.d.tl Normal file
View File

@ -0,0 +1,7 @@
local type Button = require("awful.button")
local record Mouse
append_client_mousebindings: function({ Button })
end
return Mouse

13
types/busted.d.tl Normal file
View File

@ -0,0 +1,13 @@
global describe: function(string, function())
global it: function(string, function())
global before_each: function(function())
global after_each: function(function())
global setup: function(function())
global teardown: function(function())
global async: function()
global done: function()
global insulate: function(string, function())
global expose: function(string, function())
global randomize: function()
global finally: function(function())
global pending: function(string)

25
types/ruled/client.d.tl Normal file
View File

@ -0,0 +1,25 @@
local record Client
record RuleRule
class: string | { string }
instance: string | { string }
name: string | { string }
role: string | { string }
end
record RuleComponent
properties: { string : any } -- should be every client's properties
callback: function(any) -- should be client
rule: RuleRule
rule_any: RuleRule
except: RuleRule
except_any: RuleRule
rule_every: RuleRule
rule_lesser: RuleRule
rule_greater: RuleRule
id: any
end
append_rules: function({ RuleComponent })
end
return Client

View File

@ -0,0 +1,4 @@
local record Notification
end
return Notification