Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ name: test
on:
push:
branches:
- '*'
- main
pull_request:
branches:
- main

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/gomod2nix-template
result/
.pre-commit-config.yaml
result
.direnv
Expand Down
2 changes: 1 addition & 1 deletion internal/luaformatter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewFormatter(system string) (*Formatter, error) {
table := state.NewTable()
table.RawSetString("lowercase", state.NewFunction(lowercase))
table.RawSetString("uppercase", state.NewFunction(uppercase))
table.RawSetString("hasKey", state.NewFunction(hasKey))
table.RawSetString("contains", state.NewFunction(contains))

state.SetGlobal("izu", table)

Expand Down
4 changes: 2 additions & 2 deletions internal/luaformatter/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func uppercase(state *lua.LState) int {
return 1
}

// hasKey will check if a key exists in a table
func hasKey(state *lua.LState) int {
// contains will check if a key exists in a table
func contains(state *lua.LState) int {
table := state.CheckTable(1)
key := state.CheckString(2)
result := false
Expand Down
4 changes: 2 additions & 2 deletions izu.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ pkgs }:
{ pkgs, lib }:
pkgs.buildGoApplication rec {
pname = "izu";
version = "0.2.2";
version = lib.readFile ./VERSION;

pwd = ./.;
src = ./.;
Expand Down
2 changes: 1 addition & 1 deletion pkg/izu/formatters/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.2
0.2.3
90 changes: 65 additions & 25 deletions pkg/izu/formatters/lua/hyprland.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,60 @@
local formatter = {}
local izu = izu

-- modifier order for `bind = Super+Shift, exec, echo hellow world
local modifiers = {
"Super",
"Shift",
"Alt",
"Ctrl",
"Shift_L",
"Shift_R",
"Alt_L",
"Alt_R",
"Ctrl_L",
"Ctrl_R",
"Super_L",
"Super_R",
}

local function order_keys(bind)
local mods = {}
local keys = {}
for _, v in ipairs(bind) do
if izu.contains(modifiers, v) then
table.insert(mods, v)
else
table.insert(keys, v)
end
end

return {
table.concat(mods, "+"),
table.concat(keys, "+"),
}
end

-- mousekeys for binds such as mouse:273, mouse:274, etc.
local mouse_keys = {
["mouse_lmb"] = "mouse:272",
["mouse_rmb"] = "mouse:273",
["mouse_mmb"] = "mouse:274",
}

local function replace_mousekey(key)
if mouse_keys[key] then
return mouse_keys[key]
end

if key:find("mouse_x") then
local x = key:match("mouse_x(%d)")
return "mouse:" .. (274 + tonumber(x))
end

return key
end

-- flags for binds, such as bindl, bindr, bindm, etc.
local bindflags = {
"l",
"r",
Expand All @@ -14,40 +68,26 @@ local bindflags = {
"p",
}

local modifiers = {
"super",
"shift",
"ctrl",
"ctrl_l",
"ctrl_r",
"alt",
"alt_l",
"alt_r",
"escape",
"apostrophe",
}

local function flag(f)
for _, v in pairs(bindflags) do
if v == f then
return v
local function get_flags(flags)
local bindflag = ""
for _, v in pairs(flags) do
if izu.contains(bindflags, v) then
bindflag = bindflag .. v
end
end
return ""
return bindflag
end

-- Formatter functions

function formatter.hotkey (args)
local flags = args.flags
local bindflag = ""
for _, v in pairs(flags) do
bindflag = bindflag .. flag(v)
end
local bindflag = get_flags(args.flags)
return "bind" .. bindflag .. " = " .. table.concat(args.value, ", ")
end

function formatter.binding (args)
if args.state == 1 then
return table.concat(args.value, ", ")
return table.concat(order_keys(args.value), ", ")
end
return table.concat(args.value, "")
end
Expand All @@ -57,7 +97,7 @@ function formatter.multiple (args)
end

function formatter.single (args)
return table.concat(args.value, "")
return replace_mousekey(table.concat(args.value, ""))
end

function formatter.string (args)
Expand Down
Loading