hyprland/module: rewrite filter system with categories

parent bcbdfca7
......@@ -71,21 +71,21 @@ func CommandList() *cli.Command {
ArgsUsage: "module",
Flags: []cli.Flag{config.FormatFlag},
Action: HyprlandModuleCheckCommand,
ShellComplete: ShellCompleteModule("all"),
ShellComplete: ShellCompleteModule(""),
},
{
Name: "edit",
Usage: locale.T("Edit module file"),
ArgsUsage: "module",
Action: HyprlandModuleEditCommand,
ShellComplete: ShellCompleteModule("all"),
ShellComplete: ShellCompleteModule(""),
},
{
Name: "status",
Usage: locale.T("Hyprland module status"),
ArgsUsage: "module",
Action: HyprlandModuleStatusCommand,
ShellComplete: ShellCompleteModule("all"),
ShellComplete: ShellCompleteModule(""),
},
{
Name: "show",
......@@ -95,7 +95,7 @@ func CommandList() *cli.Command {
config.FormatFlag,
},
Action: HyprlandModuleShowCommand,
ShellComplete: ShellCompleteModule("all"),
ShellComplete: ShellCompleteModule(""),
},
{
Name: "info",
......@@ -103,9 +103,8 @@ func CommandList() *cli.Command {
Flags: []cli.Flag{
&cli.StringFlag{
Name: "filter",
Usage: locale.T("status filter"),
Usage: locale.T("module filter (e.g. status:enabled, type:user, group:themes)"),
Aliases: []string{"f"},
Value: "all",
},
config.FormatFlag,
},
......@@ -116,7 +115,7 @@ func CommandList() *cli.Command {
Usage: locale.T("enable module"),
ArgsUsage: "module",
Action: HyprlandModuleEnableCommand,
ShellComplete: ShellCompleteModule("disabled"),
ShellComplete: ShellCompleteModule("status:disabled"),
},
{
Name: "disable",
......@@ -131,14 +130,14 @@ func CommandList() *cli.Command {
},
ArgsUsage: "module",
Action: HyprlandModuleDisableCommand,
ShellComplete: ShellCompleteModule("enabled"),
ShellComplete: ShellCompleteModule("status:enabled"),
},
{
Name: "toggle",
Usage: locale.T("toggle module"),
ArgsUsage: "module",
Action: HyprlandToggleModuleCommand,
ShellComplete: ShellCompleteModule("all"),
ShellComplete: ShellCompleteModule(""),
},
},
},
......
......@@ -358,8 +358,7 @@ func (m *HyprlandManager) GetModulesList(filter string) []HyprModule {
}
}
groupFilter := strings.TrimPrefix(filter, "group:")
isGroupFilter := groupFilter != filter
filters := parseModuleFilter(filter)
var res []HyprModule
for _, module := range allModules {
......@@ -369,17 +368,64 @@ func (m *HyprlandManager) GetModulesList(filter string) []HyprModule {
continue
}
if filter == "" || filter == "all" ||
info.Status.Label == filter ||
(filter == "user" && info.User) ||
(filter == "system" && !info.User) ||
(isGroupFilter && info.Meta != nil && info.Meta.Group == groupFilter) {
res = append(res, info)
if !matchModuleFilter(info, filters) {
continue
}
res = append(res, info)
}
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) {
info := m.GetModuleInfo(module)
......@@ -406,7 +452,7 @@ func (m *HyprlandManager) SetModule(action, module string, onlyNew bool) (string
// отключить другие модули той же группы (кросс-типовое)
var disabledGroup []string
if info.Meta != nil && info.Meta.Group != "" {
for _, other := range m.GetModulesList("enabled") {
for _, other := range m.GetModulesList("status:enabled") {
if other.Name == module {
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