refactor: change user tui printout to remove weird line missalignment

This commit is contained in:
Slug-Boi
2024-10-28 12:24:26 +01:00
parent 246db95414
commit 301b8ca084
2 changed files with 35 additions and 34 deletions
+1 -1
View File
@@ -109,7 +109,7 @@ func loadData(author_file string) {
for scanner.Scan() { for scanner.Scan() {
//very hacky it basically just ensure glamour doesn't format the email //very hacky it basically just ensure glamour doesn't format the email
cnt.WriteString(":\b" + scanner.Text() + "\n") cnt.WriteString(" " + scanner.Text() + "\n")
} }
content = cnt.String() content = cnt.String()
+34 -33
View File
@@ -1,14 +1,15 @@
package cmd package cmd
import ( import (
"github.com/Slug-Boi/cocommit/src_code/go_src/cmd/tui"
"github.com/Slug-Boi/cocommit/src_code/go_src/cmd/utils"
"os" "os"
"os/exec" "os/exec"
"slices" "slices"
"sort" "sort"
"strings" "strings"
"github.com/Slug-Boi/cocommit/src_code/go_src/cmd/tui"
"github.com/Slug-Boi/cocommit/src_code/go_src/cmd/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@@ -17,39 +18,39 @@ var authorfile = utils.Find_authorfile()
// usersCmd represents the users command // usersCmd represents the users command
func UsersCmd() *cobra.Command { func UsersCmd() *cobra.Command {
return &cobra.Command{ return &cobra.Command{
Use: "users", Use: "users",
Short: "Displays all users from the author file located at: " + authorfile, Short: "Displays all users from the author file located at: " + authorfile,
Long: `Displays all users from the author file located at: ` + authorfile, Long: `Displays all users from the author file located at: ` + authorfile,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
//TODO: make this print a bit prettier (sort it and maybe use a table) //TODO: make this print a bit prettier (sort it and maybe use a table)
// check if the no pretty print flag is set // check if the no pretty print flag is set
np, _ := cmd.Flags().GetBool("np") np, _ := cmd.Flags().GetBool("np")
if np { if np {
println("List of users:\nFormat: <shortname>/<name> -> Username: <username> Email: <email>") println("List of users:\nFormat: <shortname>/<name> -> Username: <username> Email: <email>")
seen_users := []utils.User{} seen_users := []utils.User{}
user_sb := []string{} user_sb := []string{}
for name, usr := range utils.Users { for name, usr := range utils.Users {
if !slices.Contains(seen_users, usr) { if !slices.Contains(seen_users, usr) {
user_sb = append(user_sb, utils.Users[name].Names+" ->"+" Username: "+usr.Username+" Email: "+usr.Email+"\n") user_sb = append(user_sb, utils.Users[name].Names+" ->"+" Username: "+usr.Username+" Email: "+usr.Email+"\n")
seen_users = append(seen_users, usr) seen_users = append(seen_users, usr)
}
} }
sort.Strings(user_sb)
println(strings.Join(user_sb, ""))
os.Exit(0)
} }
sort.Strings(user_sb) bat_check := exec.Command("bat", "--version")
println(strings.Join(user_sb, "")) out, _ := bat_check.CombinedOutput()
os.Exit(0) if string(out) == "" {
} tui.Entry_US(authorfile)
bat_check := exec.Command("bat", "--version") os.Exit(0)
out, _ := bat_check.CombinedOutput() }
if string(out) == "" { bat := exec.Command("bat", authorfile)
tui.Entry_US(authorfile) bat.Stdout = os.Stdout
os.Exit(0) bat.Stderr = os.Stderr
} bat.Run()
bat := exec.Command("bat", authorfile) },
bat.Stdout = os.Stdout }
bat.Stderr = os.Stderr
bat.Run()
},
}
} }
func init() { func init() {