improve the output style

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