hyprland/module: add short names and group/module format

parent dd3540e5
...@@ -17,6 +17,13 @@ import ( ...@@ -17,6 +17,13 @@ import (
"github.com/urfave/cli/v3" "github.com/urfave/cli/v3"
) )
func checkModuleAvailable(info HyprModule) error {
if !info.Available {
return errors.New(locale.T("invalid module name"))
}
return nil
}
func HyprlandFixConfigCommand(ctx context.Context, cmd *cli.Command) error { func HyprlandFixConfigCommand(ctx context.Context, cmd *cli.Command) error {
manager, err := GetHyprlandManager(ctx) manager, err := GetHyprlandManager(ctx)
if err != nil { if err != nil {
...@@ -65,8 +72,8 @@ func HyprlandModuleStatusCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -65,8 +72,8 @@ func HyprlandModuleStatusCommand(ctx context.Context, cmd *cli.Command) error {
} }
info := manager.GetModuleInfo(cmd.Args().Get(0)) info := manager.GetModuleInfo(cmd.Args().Get(0))
if !info.Available { if err := checkModuleAvailable(info); err != nil {
return errors.New(locale.T("invalid module name")) return err
} }
fmt.Println(info.Status.Label) fmt.Println(info.Status.Label)
return nil return nil
...@@ -85,9 +92,8 @@ func HyprlandModuleCheckCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -85,9 +92,8 @@ func HyprlandModuleCheckCommand(ctx context.Context, cmd *cli.Command) error {
} }
moduleinfo := manager.GetModuleInfo(module) moduleinfo := manager.GetModuleInfo(module)
if err := checkModuleAvailable(moduleinfo); err != nil {
if !moduleinfo.Available { return err
return errors.New(locale.T("invalid module name"))
} }
result, err := manager.CheckModule(module) result, err := manager.CheckModule(module)
...@@ -215,7 +221,7 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -215,7 +221,7 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error {
jsonItems := make([]ModuleInfoJSON, len(data)) jsonItems := make([]ModuleInfoJSON, len(data))
for i, d := range data { for i, d := range data {
jsonItems[i] = ModuleInfoJSON{ jsonItems[i] = ModuleInfoJSON{
Name: d.info.Name, Name: d.info.ShortName(),
User: d.info.User, User: d.info.User,
Status: d.info.Status.Label, Status: d.info.Status.Label,
Errors: d.errorNum, Errors: d.errorNum,
...@@ -237,9 +243,9 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -237,9 +243,9 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error {
if d.errorNum > 0 { if d.errorNum > 0 {
parts = append(parts, fmt.Sprintf(locale.T("(errors: %d)"), d.errorNum)) parts = append(parts, fmt.Sprintf(locale.T("(errors: %d)"), d.errorNum))
} }
name := d.info.Name name := d.info.ShortName()
if d.info.Meta != nil && d.info.Meta.Group != "" { if d.info.Meta != nil && d.info.Meta.Group != "" {
name = d.info.Meta.Group + "/" + d.info.Name name = d.info.Meta.Group + "/" + name
} }
item := ui.TreeItem{ item := ui.TreeItem{
Name: name, Name: name,
...@@ -289,13 +295,13 @@ func HyprlandModuleListCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -289,13 +295,13 @@ func HyprlandModuleListCommand(ctx context.Context, cmd *cli.Command) error {
if config.IsJSON(cmd) { if config.IsJSON(cmd) {
names := make([]string, len(modules)) names := make([]string, len(modules))
for i, m := range modules { for i, m := range modules {
names[i] = m.Name names[i] = m.ShortName()
} }
return ui.PrintJSON(names) return ui.PrintJSON(names)
} }
for _, m := range modules { for _, m := range modules {
fmt.Println(m.Name) fmt.Println(m.ShortName())
} }
return nil return nil
} }
...@@ -309,8 +315,8 @@ func HyprlandModuleEditCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -309,8 +315,8 @@ func HyprlandModuleEditCommand(ctx context.Context, cmd *cli.Command) error {
info := manager.GetModuleInfo(module) info := manager.GetModuleInfo(module)
if !info.Available { if err := checkModuleAvailable(info); err != nil {
return errors.New(locale.T("invalid module name")) return err
} }
if info.Path == "" { if info.Path == "" {
...@@ -344,8 +350,8 @@ func HyprlandModuleShowCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -344,8 +350,8 @@ func HyprlandModuleShowCommand(ctx context.Context, cmd *cli.Command) error {
} }
info := manager.GetModuleInfo(module) info := manager.GetModuleInfo(module)
if !info.Available { if err := checkModuleAvailable(info); err != nil {
return errors.New(locale.T("invalid module name")) return err
} }
errors, _ := manager.CheckModule(module) errors, _ := manager.CheckModule(module)
...@@ -362,7 +368,7 @@ func HyprlandModuleShowCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -362,7 +368,7 @@ func HyprlandModuleShowCommand(ctx context.Context, cmd *cli.Command) error {
} }
blue := color.New(color.FgBlue).SprintFunc() blue := color.New(color.FgBlue).SprintFunc()
fmt.Printf("%s: %s\n", blue(locale.T("Module")), info.Name) fmt.Printf("%s: %s\n", blue(locale.T("Module")), info.ShortName())
if info.Meta != nil { if info.Meta != nil {
if info.Meta.Group != "" { if info.Meta.Group != "" {
fmt.Printf("%s: %s\n", blue(locale.T("Group")), info.Meta.Group) fmt.Printf("%s: %s\n", blue(locale.T("Group")), info.Meta.Group)
......
...@@ -279,7 +279,7 @@ func ShellCompleteModule(filter string) func(ctx context.Context, cmd *cli.Comma ...@@ -279,7 +279,7 @@ func ShellCompleteModule(filter string) func(ctx context.Context, cmd *cli.Comma
modules := manager.GetModulesList(filter) modules := manager.GetModulesList(filter)
for _, m := range modules { for _, m := range modules {
fmt.Println(m.Name) fmt.Println(m.ShortName())
} }
} }
} }
......
...@@ -47,6 +47,13 @@ type HyprModule struct { ...@@ -47,6 +47,13 @@ type HyprModule struct {
Meta *ModuleMeta `json:"meta,omitempty"` Meta *ModuleMeta `json:"meta,omitempty"`
} }
func (m HyprModule) ShortName() string {
if m.Meta != nil && m.Meta.Group != "" && strings.HasPrefix(m.Name, m.Meta.Group+"-") {
return strings.TrimPrefix(m.Name, m.Meta.Group+"-")
}
return m.Name
}
type HyprVar struct { type HyprVar struct {
Name string Name string
Value string Value string
...@@ -170,15 +177,20 @@ func (m *HyprlandManager) CheckModule(module string) ([]HyprConfigError, error) ...@@ -170,15 +177,20 @@ func (m *HyprlandManager) CheckModule(module string) ([]HyprConfigError, error)
// Modules // Modules
func (m *HyprlandManager) resolveModule(name string) (user bool, found bool) { func (m *HyprlandManager) resolveModule(name string) (fullName string, user bool, found bool) {
// Формат group/module → group-module
if group, short, ok := strings.Cut(name, "/"); ok {
name = group + "-" + short
}
inUser := slices.Contains(m.UserModules, name) inUser := slices.Contains(m.UserModules, name)
inSystem := slices.Contains(m.SystemModules, name) inSystem := slices.Contains(m.SystemModules, name)
switch { switch {
case inUser: case inUser:
return true, true return name, true, true
case inSystem: case inSystem:
return false, true return name, false, true
} }
// Файла нет ни в одном каталоге — ищем по source-строкам // Файла нет ни в одном каталоге — ищем по source-строкам
...@@ -187,18 +199,18 @@ func (m *HyprlandManager) resolveModule(name string) (user bool, found bool) { ...@@ -187,18 +199,18 @@ func (m *HyprlandManager) resolveModule(name string) (user bool, found bool) {
for _, src := range m.Sources { for _, src := range m.Sources {
if src.Path == userConfPath { if src.Path == userConfPath {
return true, true return name, true, true
} }
if src.Path == sysConfPath { if src.Path == sysConfPath {
return false, true return name, false, true
} }
} }
return false, false return name, false, false
} }
func (m *HyprlandManager) GetModuleInfo(module string) HyprModule { func (m *HyprlandManager) GetModuleInfo(module string) HyprModule {
user, found := m.resolveModule(module) fullName, user, found := m.resolveModule(module)
if !found { if !found {
return HyprModule{ return HyprModule{
Name: module, Name: module,
...@@ -206,7 +218,7 @@ func (m *HyprlandManager) GetModuleInfo(module string) HyprModule { ...@@ -206,7 +218,7 @@ func (m *HyprlandManager) GetModuleInfo(module string) HyprModule {
Available: !slices.Contains(config.HyprlandSkipModules, module), Available: !slices.Contains(config.HyprlandSkipModules, module),
} }
} }
return m.getModuleInfo(module, user) return m.getModuleInfo(fullName, user)
} }
func (m *HyprlandManager) getModuleInfo(module string, user bool) HyprModule { func (m *HyprlandManager) getModuleInfo(module string, user bool) HyprModule {
......
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