hyprland/module: rewrite filter system with categories

parent bcbdfca7
...@@ -71,21 +71,21 @@ func CommandList() *cli.Command { ...@@ -71,21 +71,21 @@ func CommandList() *cli.Command {
ArgsUsage: "module", ArgsUsage: "module",
Flags: []cli.Flag{config.FormatFlag}, Flags: []cli.Flag{config.FormatFlag},
Action: HyprlandModuleCheckCommand, Action: HyprlandModuleCheckCommand,
ShellComplete: ShellCompleteModule("all"), ShellComplete: ShellCompleteModule(""),
}, },
{ {
Name: "edit", Name: "edit",
Usage: locale.T("Edit module file"), Usage: locale.T("Edit module file"),
ArgsUsage: "module", ArgsUsage: "module",
Action: HyprlandModuleEditCommand, Action: HyprlandModuleEditCommand,
ShellComplete: ShellCompleteModule("all"), ShellComplete: ShellCompleteModule(""),
}, },
{ {
Name: "status", Name: "status",
Usage: locale.T("Hyprland module status"), Usage: locale.T("Hyprland module status"),
ArgsUsage: "module", ArgsUsage: "module",
Action: HyprlandModuleStatusCommand, Action: HyprlandModuleStatusCommand,
ShellComplete: ShellCompleteModule("all"), ShellComplete: ShellCompleteModule(""),
}, },
{ {
Name: "show", Name: "show",
...@@ -95,7 +95,7 @@ func CommandList() *cli.Command { ...@@ -95,7 +95,7 @@ func CommandList() *cli.Command {
config.FormatFlag, config.FormatFlag,
}, },
Action: HyprlandModuleShowCommand, Action: HyprlandModuleShowCommand,
ShellComplete: ShellCompleteModule("all"), ShellComplete: ShellCompleteModule(""),
}, },
{ {
Name: "info", Name: "info",
...@@ -103,9 +103,8 @@ func CommandList() *cli.Command { ...@@ -103,9 +103,8 @@ func CommandList() *cli.Command {
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "filter", Name: "filter",
Usage: locale.T("status filter"), Usage: locale.T("module filter (e.g. status:enabled, type:user, group:themes)"),
Aliases: []string{"f"}, Aliases: []string{"f"},
Value: "all",
}, },
config.FormatFlag, config.FormatFlag,
}, },
...@@ -116,7 +115,7 @@ func CommandList() *cli.Command { ...@@ -116,7 +115,7 @@ func CommandList() *cli.Command {
Usage: locale.T("enable module"), Usage: locale.T("enable module"),
ArgsUsage: "module", ArgsUsage: "module",
Action: HyprlandModuleEnableCommand, Action: HyprlandModuleEnableCommand,
ShellComplete: ShellCompleteModule("disabled"), ShellComplete: ShellCompleteModule("status:disabled"),
}, },
{ {
Name: "disable", Name: "disable",
...@@ -131,14 +130,14 @@ func CommandList() *cli.Command { ...@@ -131,14 +130,14 @@ func CommandList() *cli.Command {
}, },
ArgsUsage: "module", ArgsUsage: "module",
Action: HyprlandModuleDisableCommand, Action: HyprlandModuleDisableCommand,
ShellComplete: ShellCompleteModule("enabled"), ShellComplete: ShellCompleteModule("status:enabled"),
}, },
{ {
Name: "toggle", Name: "toggle",
Usage: locale.T("toggle module"), Usage: locale.T("toggle module"),
ArgsUsage: "module", ArgsUsage: "module",
Action: HyprlandToggleModuleCommand, Action: HyprlandToggleModuleCommand,
ShellComplete: ShellCompleteModule("all"), ShellComplete: ShellCompleteModule(""),
}, },
}, },
}, },
......
...@@ -358,8 +358,7 @@ func (m *HyprlandManager) GetModulesList(filter string) []HyprModule { ...@@ -358,8 +358,7 @@ func (m *HyprlandManager) GetModulesList(filter string) []HyprModule {
} }
} }
groupFilter := strings.TrimPrefix(filter, "group:") filters := parseModuleFilter(filter)
isGroupFilter := groupFilter != filter
var res []HyprModule var res []HyprModule
for _, module := range allModules { for _, module := range allModules {
...@@ -369,17 +368,64 @@ func (m *HyprlandManager) GetModulesList(filter string) []HyprModule { ...@@ -369,17 +368,64 @@ func (m *HyprlandManager) GetModulesList(filter string) []HyprModule {
continue continue
} }
if filter == "" || filter == "all" || if !matchModuleFilter(info, filters) {
info.Status.Label == filter || continue
(filter == "user" && info.User) ||
(filter == "system" && !info.User) ||
(isGroupFilter && info.Meta != nil && info.Meta.Group == groupFilter) {
res = append(res, info)
} }
res = append(res, info)
} }
return res return res
} }
func parseModuleFilter(raw string) map[string]string {
filters := make(map[string]string)
for _, part := range strings.Split(raw, ",") {
part = strings.TrimSpace(part)
if part == "" || part == "all" {
continue
}
cat, val, _ := strings.Cut(part, ":")
filters[cat] = val
}
return filters
}
func matchModuleFilter(info HyprModule, filters map[string]string) bool {
if len(filters) == 0 {
return true
}
if v, ok := filters["status"]; ok {
if strings.HasPrefix(v, "no") {
if info.Status.Label == v[2:] {
return false
}
} else {
if info.Status.Label != v {
return false
}
}
}
if v, ok := filters["type"]; ok {
if (v == "user") != info.User {
return false
}
}
if v, ok := filters["group"]; ok {
group := ""
if info.Meta != nil {
group = info.Meta.Group
}
if group != v {
return false
}
}
return true
}
func (m *HyprlandManager) SetModule(action, module string, onlyNew bool) (string, error) { func (m *HyprlandManager) SetModule(action, module string, onlyNew bool) (string, error) {
info := m.GetModuleInfo(module) info := m.GetModuleInfo(module)
...@@ -406,7 +452,7 @@ func (m *HyprlandManager) SetModule(action, module string, onlyNew bool) (string ...@@ -406,7 +452,7 @@ func (m *HyprlandManager) SetModule(action, module string, onlyNew bool) (string
// отключить другие модули той же группы (кросс-типовое) // отключить другие модули той же группы (кросс-типовое)
var disabledGroup []string var disabledGroup []string
if info.Meta != nil && info.Meta.Group != "" { if info.Meta != nil && info.Meta.Group != "" {
for _, other := range m.GetModulesList("enabled") { for _, other := range m.GetModulesList("status:enabled") {
if other.Name == module { if other.Name == module {
continue continue
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment