improve the output style

parent f079c7dc
...@@ -187,7 +187,7 @@ func HyprlandToggleModuleCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -187,7 +187,7 @@ func HyprlandToggleModuleCommand(ctx context.Context, cmd *cli.Command) error {
return nil return nil
} }
func hyprlandListModules(user bool, filter string) { func hyprlandListModules(user bool, filter string) []string {
var dir string var dir string
if user { if user {
dir = config.Env.Hyprland.UserModulesDir dir = config.Env.Hyprland.UserModulesDir
...@@ -196,8 +196,7 @@ func hyprlandListModules(user bool, filter string) { ...@@ -196,8 +196,7 @@ func hyprlandListModules(user bool, filter string) {
} }
entries, err := os.ReadDir(dir) entries, err := os.ReadDir(dir)
if err != nil { if err != nil {
fmt.Printf("Каталог с модулями не найден: %s", dir) return nil
return
} }
skip := map[string]bool{ skip := map[string]bool{
"hyprland": true, "hypridle": true, "hyprland": true, "hypridle": true,
...@@ -205,6 +204,7 @@ func hyprlandListModules(user bool, filter string) { ...@@ -205,6 +204,7 @@ func hyprlandListModules(user bool, filter string) {
"hyprsunset": true, "xdph": true, "hyprsunset": true, "xdph": true,
} }
var modules []string
for _, e := range entries { for _, e := range entries {
if e.IsDir() || !strings.HasSuffix(e.Name(), ".conf") { if e.IsDir() || !strings.HasSuffix(e.Name(), ".conf") {
continue continue
...@@ -220,18 +220,46 @@ func hyprlandListModules(user bool, filter string) { ...@@ -220,18 +220,46 @@ func hyprlandListModules(user bool, filter string) {
if filter == "disabled" && status != "disabled" { if filter == "disabled" && status != "disabled" {
continue continue
} }
modules = append(modules, module)
}
return modules
}
func hyprlandInfoModules(user bool, filter string) {
modules := hyprlandListModules(user, filter)
if len(modules) == 0 {
color.Red("Нет доступных модулей")
return
}
color.Blue("Modules:")
for i, module := range modules {
status := hyprlandModuleStatus(module, user)
coloredStatus := ""
coloredModule := ""
switch status { switch status {
case "enabled": case "enabled":
color.Green(module) coloredStatus = color.GreenString("●")
coloredModule = color.GreenString(module)
case "disabled": case "disabled":
color.Yellow(module) coloredStatus = color.RedString("○")
coloredModule = color.RedString(module)
default: default:
color.Red(module) coloredStatus = color.HiBlackString("○")
coloredModule = color.HiBlackString(module)
}
prefix := "├──"
if i == len(modules)-1 {
prefix = "└──"
} }
fmt.Printf("%s %s %s\n", prefix, coloredStatus, coloredModule)
} }
} }
func HyprlandListModulesCommand(ctx context.Context, cmd *cli.Command) error { func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error {
hyprlandListModules(cmd.Bool("user"), "all") hyprlandInfoModules(cmd.Bool("user"), cmd.String("filter"))
return nil return nil
} }
...@@ -36,9 +36,17 @@ func CommandList() *cli.Command { ...@@ -36,9 +36,17 @@ func CommandList() *cli.Command {
Action: HyprlandModuleStatusCommand, Action: HyprlandModuleStatusCommand,
}, },
{ {
Name: "list", Name: "info",
Usage: "list modules", Usage: "Information about modules",
Action: HyprlandListModulesCommand, Flags: []cli.Flag{
&cli.StringFlag{
Name: "filter",
Usage: "status filter",
Aliases: []string{"f"},
Value: "all",
},
},
Action: HyprlandInfoModulesCommand,
}, },
{ {
Name: "enable", Name: "enable",
......
...@@ -2,6 +2,7 @@ package hyprland ...@@ -2,6 +2,7 @@ package hyprland
import ( import (
"context" "context"
"sort"
"ximperconf/config" "ximperconf/config"
"bufio" "bufio"
...@@ -80,9 +81,39 @@ func hyprlandVarInfo() (map[string]string, error) { ...@@ -80,9 +81,39 @@ func hyprlandVarInfo() (map[string]string, error) {
func HyprlandVarInfoCommand(ctx context.Context, cmd *cli.Command) error { func HyprlandVarInfoCommand(ctx context.Context, cmd *cli.Command) error {
info, _ := hyprlandVarInfo() info, _ := hyprlandVarInfo()
for k, v := range info {
fmt.Printf("%s = %s\n", k, v) if len(info) == 0 {
color.Yellow("Нет переменных в конфигурации")
return nil
}
color.Blue("Vars:")
keys := make([]string, 0, len(info))
for k := range info {
keys = append(keys, k)
}
sort.Strings(keys)
for i, k := range keys {
prefix := "├──"
if i == len(keys)-1 {
prefix = "└──"
}
v := info[k]
fmt.Printf("%s %s: %s\n",
prefix,
color.YellowString(k),
func() string {
if v == "" {
return color.HiBlackString("<empty>")
} }
return color.GreenString(v)
}(),
)
}
return nil return nil
} }
......
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