From 7270f98d31a1b52f001ed6ac4e379425e82ab2b7 Mon Sep 17 00:00:00 2001 From: nea Date: Fri, 9 Sep 2022 22:24:04 +0200 Subject: [PATCH] Printing padding and moving --- go.mod | 3 + main.go | 158 +++++++++++++------------------------------- subdirectory/sub.go | 5 ++ util/printing.go | 113 +++++++++++++++++++++++++++++++ 4 files changed, 166 insertions(+), 113 deletions(-) create mode 100644 go.mod create mode 100644 subdirectory/sub.go create mode 100644 util/printing.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6a67dc1 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/exhq/neowofetch + +go 1.19 diff --git a/main.go b/main.go index bc4f745..96e9ce9 100644 --- a/main.go +++ b/main.go @@ -3,16 +3,16 @@ package main import ( "fmt" "io/ioutil" - "math/rand" "os" "os/exec" "path/filepath" "strconv" "strings" + + "github.com/exhq/neowofetch/util" ) var isuwuified bool = true -var tempbool bool var arch = ` /\ / \ /\ \ @@ -22,119 +22,67 @@ var arch = ` /\ /_-'' ''-_\ ` -func cprint(input string, newline bool, uwuoverwrite bool) { +func getHome() string { + return os.Getenv("HOME") +} - endings := [15]string{ - "owo", - "UwU", - ">w<", - "^w^", - "●w●", - "☆w☆", - "𝗨𝘄𝗨", - "(´꒳`)", - "♥(。U ω U。)", - "(˘ε˘)", - "( ˘ᴗ˘ )", - "(*ฅ́˘ฅ̀*)", - "*screams*", - "*twearks*", - "*sweats*", - } - ninput := "" - if isuwuified && !uwuoverwrite { - bruh := strings.Split(input, " ") - for _, word := range bruh { - if word == "" { - continue - } - word = strings.ReplaceAll(word, "r", "w") - word = strings.ReplaceAll(word, "i", "iy") - word = strings.ReplaceAll(word, "l", "w") - - if strings.HasSuffix(word, "!") { - word = word[0:len(word)-1] + "1!11!1" - } - if strings.Contains(word, "u") && !strings.Contains(word, "uwu") && !strings.Contains(word, "owo") { - word = strings.ReplaceAll(word, "u", "uwu") - } - - ninput += word + " " - - } - if rand.Intn(5-1)+1 == 2 { - ninput += endings[rand.Intn(len(endings))] - - } - - } else { - ninput = input - } - farch := strings.Split(arch, "\n") - check := 0 - if newline == false { - fmt.Print(ninput) - } else { - fmt.Print(farch[0] + ninput + "\n") - check += 1 - } - if check < len(farch) { - for check < len(farch) { - print(farch[check] + "\n") - check += 1 - } - } +func getConfigFile() string { + return getHome() + "/.config/neowofetch/conf" } func handleConfig() { - _, folder := os.Stat("/home/" + getUsername() + "/.config/neowofetch") - _, file := os.Stat("/home/" + getUsername() + "/.config/neowofetch/conf") + _, folder := os.Stat(filepath.Dir(getConfigFile())) + _, file := os.Stat(getConfigFile()) if os.IsNotExist(folder) { - os.Mkdir("/home/"+getUsername()+"/.config/neowofetch", os.ModePerm) + os.Mkdir(filepath.Dir(getConfigFile()), os.ModePerm) } if os.IsNotExist(file) { println("bruh you aint got tha file? bruh fr fr bruh wtf") - f, _ := os.Create("/home/" + getUsername() + "/.config/neowofetch/conf") - _, _ = f.WriteString( - `test -among`) - + f, _ := os.Create(getConfigFile()) + _, _ = f.WriteString("test\namong") } else { - body, _ := ioutil.ReadFile("/home/" + getUsername() + "/.config/neowofetch/conf") + body, _ := ioutil.ReadFile(getConfigFile()) fbody := strings.Split(string(body), "\n") + util.InitUwuPrinter() for _, s := range fbody { - w := strings.Split(s, " ") - if len(w) == 1 { + w := strings.SplitN(s, " ", 2) + if len(w) < 2 { continue } - declr := w[0] - inf := w[1] - nouwu := w[len(w)-1] - if declr == "nn-prin" { - cprint(strings.Join(w[1:], " "), false, nouwu == "nouwu") + verb := w[0] + argument := w[1] + nouwu := false + if strings.HasPrefix(argument, "-uwu ") { + nouwu = true + argument = argument[5:] } - if declr == "prin" { - cprint(strings.Join(w[1:], " "), true, nouwu == "nouwu") - } - if declr == "nn-info" || declr == "info" { - if declr == "info" { - tempbool = true - } else { - tempbool = false - } - if inf == "username" { - cprint(getUsername(), tempbool, nouwu == "nouwu") - } else if inf == "hostname" { - cprint(getHostname(), tempbool, nouwu == "nouwu") - } else if inf == "uptime" { - among, _ := strconv.Atoi(getUptime()) - cprint(formatTime(among), tempbool, true) - } + if verb == "print" { + util.UwuPrint(argument, nouwu) + } else if verb == "println" { + util.UwuPrint(argument, nouwu) + util.UwuNewline() + } else if verb == "info" { + PrintInfo(argument, nouwu) + } else if verb == "infoln" { + PrintInfo(argument, nouwu) + util.UwuNewline() + } else { + fmt.Printf("Unknown verb %s\n", verb) } } } +} +func PrintInfo(infoType string, noUwuOverride bool) { + if infoType == "username" { + util.UwuPrint(getUsername(), noUwuOverride) + } else if infoType == "hostname" { + util.UwuPrint(getHostname(), noUwuOverride) + } else if infoType == "uptime" { + among, _ := strconv.Atoi(getUptime()) + util.UwuPrint(formatTime(among), true) + } } func handleArgs() { @@ -297,21 +245,5 @@ func getColorPalette() { func main() { handleArgs() handleConfig() - ex, err := os.Executable() - if err != nil { - panic(err) - } - exPath := filepath.Dir(ex) - fmt.Println(exPath) - - /* - mem, err := os.Open("/proc/meminfo") - if err != nil { - fmt.Println(err.Error()) - os.Exit(0) - } - mem_info := make([]byte, 1024) - mem.Read(mem_info) - mem.Close() - */ + util.UwuPrintRest() } diff --git a/subdirectory/sub.go b/subdirectory/sub.go new file mode 100644 index 0000000..9063c06 --- /dev/null +++ b/subdirectory/sub.go @@ -0,0 +1,5 @@ +package subdirectory; + + +func TestFun() { +} diff --git a/util/printing.go b/util/printing.go new file mode 100644 index 0000000..376d8b9 --- /dev/null +++ b/util/printing.go @@ -0,0 +1,113 @@ +package util + +import ( + "fmt" + "math/rand" + "strings" +) + +var uwuEmotes = [15]string{ + "owo", + "UwU", + ">w<", + "^w^", + "●w●", + "☆w☆", + "𝗨𝘄𝗨", + "(´꒳`)", + "♥(。U ω U。)", + "(˘ε˘)", + "( ˘ᴗ˘ )", + "(*ฅ́˘ฅ̀*)", + "*screams*", + "*twearks*", + "*sweats*", +} + +var logoIndex = 0 +var isInProgressLine = false +var logo = ` /\ + / \ + /\ \ + / > ω <\ + / __ \ + / __| |__-\ + /_-'' ''-_\ +` +var logoLines []string +var logoWidth int +var shouldUwuify = true + +func InitUwuPrinter() { + logoLines = strings.Split(logo, "\n") + logoWidth = 0 + for _, v := range logoLines { + lineLength := len([]rune(v)) + if lineLength > logoWidth { + logoWidth = lineLength + } + } +} + +func initLine() { + if !isInProgressLine { + isInProgressLine = true + if logoIndex < len(logoLines) { + logoLine := logoLines[logoIndex] + logoLineLength := len([]rune(logoLine)) + padding := strings.Repeat(" ", logoWidth-logoLineLength) + fmt.Printf("%s%s", logoLine, padding) + logoIndex += 1 + } else { + fmt.Printf("%s", strings.Repeat(" ", logoWidth)) + } + } +} + +func UwuPrint(message string, noUwuOverride bool) { + initLine() + if noUwuOverride || !shouldUwuify { + fmt.Printf("%s", message) + return + } + words := strings.Split(message, " ") + hadAnyContent := false + for _, word := range words { + if word == "" { + fmt.Print(" ") + continue + } + word = strings.ReplaceAll(word, "r", "w") + word = strings.ReplaceAll(word, "i", "iy") + word = strings.ReplaceAll(word, "iyy", "iy") + word = strings.ReplaceAll(word, "l", "w") + + if strings.HasSuffix(word, "!") { + word = word[:len(word)-1] + "1!11!1" + } + + if strings.Contains(word, "u") && + !strings.Contains(word, "uwu") && + !strings.Contains(word, "owo") { + word = strings.ReplaceAll(word, "u", "uwu") + } + hadAnyContent = true + fmt.Printf("%s ", word) + } + + if hadAnyContent && rand.Intn(5) == 0 { + fmt.Printf("%s", uwuEmotes[rand.Intn(len(uwuEmotes))]) + } +} + +func UwuNewline() { + initLine() + isInProgressLine = false + fmt.Println() +} + +func UwuPrintRest() { + for logoIndex < len(logoLines) { + UwuNewline() + } +}