From b6f1827ea5f373966ee44e54fd923a888469d2b0 Mon Sep 17 00:00:00 2001 From: echo <91651232+exhq@users.noreply.github.com> Date: Sun, 11 Sep 2022 16:25:08 +0430 Subject: [PATCH] base code for color added --- go.mod | 6 +++++ main.go | 24 ++++++++++-------- util/printing.go | 65 +++++++++++++++++++++++++++++++----------------- 3 files changed, 62 insertions(+), 33 deletions(-) diff --git a/go.mod b/go.mod index 2e8bfa6..4bfef1d 100644 --- a/go.mod +++ b/go.mod @@ -2,3 +2,9 @@ module github.com/exhq/neowofetch go 1.19 +require ( + github.com/fatih/color v1.13.0 + github.com/mattn/go-colorable v0.1.9 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect +) diff --git a/main.go b/main.go index 8a8485c..e4c1b48 100644 --- a/main.go +++ b/main.go @@ -45,8 +45,9 @@ func handleConfig() { body, _ := ioutil.ReadFile(getConfigFile()) fbody := strings.Split(string(body), "\n") util.InitUwuPrinter() - for _, s := range fbody { + for i, s := range fbody { w := strings.SplitN(s, " ", 2) + if len(w) < 2 { continue } @@ -58,14 +59,14 @@ func handleConfig() { argument = argument[5:] } if verb == "print" { - util.UwuPrint(argument, nouwu) + util.UwuPrint(argument, nouwu, fbody[i]) } else if verb == "println" { - util.UwuPrint(argument, nouwu) + util.UwuPrint(argument, nouwu, fbody[i]) util.UwuNewline() } else if verb == "info" { - PrintInfo(argument, nouwu) + PrintInfo(argument, nouwu, strings.Join(fbody, "")) } else if verb == "infoln" { - PrintInfo(argument, nouwu) + PrintInfo(argument, nouwu, strings.Join(fbody, "")) util.UwuNewline() } else { fmt.Printf("Unknown verb %s\n", verb) @@ -74,17 +75,20 @@ func handleConfig() { } } -func PrintInfo(infoType string, noUwuOverride bool) { +func PrintInfo(infoType string, noUwuOverride bool, whole string) { if infoType == "username" { - util.UwuPrint(getUsername(), noUwuOverride) + util.UwuPrint(getUsername(), noUwuOverride, whole) } else if infoType == "hostname" { - util.UwuPrint(getHostname(), noUwuOverride) + util.UwuPrint(getHostname(), noUwuOverride, whole) } else if infoType == "uptime" { among, _ := strconv.Atoi(getUptime()) - util.UwuPrint(formatTime(among), true) + util.UwuPrint(formatTime(among), true, whole) } else if infoType == "distro" { - util.UwuPrint(getDistro(), noUwuOverride) + util.UwuPrint(getDistro(), noUwuOverride, whole) + } else if infoType == "terminal" { + util.UwuPrint(getTerminal(), noUwuOverride, whole) } + } func handleArgs() { diff --git a/util/printing.go b/util/printing.go index 1363f15..d02170d 100644 --- a/util/printing.go +++ b/util/printing.go @@ -64,41 +64,60 @@ func initLine() { } } -func UwuPrint(message string, noUwuOverride bool) { +func UwuPrint(message string, noUwuOverride bool, whole string) { //will add color eventually, my brain hurts + var hadAnyContent bool + var wholeword string + var checkspaces int + isuwu := true initLine() if noUwuOverride || !shouldUwuify { - print(message) - return + isuwu = false + wholeword = message } - words := strings.Split(message, " ") - hadAnyContent := false - for _, word := range words { - if word == "" { - 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") + notuwuified := "" + if isuwu { + words := strings.Split(message, " ") + hadAnyContent = false + for _, word := range words { + notuwuified += word + if word == "" { + checkspaces += 1 + 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.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") + if strings.Contains(word, "u") && + !strings.Contains(word, "uwu") && + !strings.Contains(word, "owo") { + word = strings.ReplaceAll(word, "u", "uwu") + } + hadAnyContent = true + wholeword += word } - hadAnyContent = true - print(word) } if hadAnyContent && rand.Intn(5) == 0 { print(uwuEmotes[rand.Intn(len(uwuEmotes))]) } + wholeword = wholeword + strings.Repeat(" ", checkspaces) + + if strings.Contains(notuwuified, "blue") { + handlecolor(wholeword) + } else { + print(wholeword) + } +} + +func handlecolor(wholeword string) { + print(wholeword + "bruh") } func UwuNewline() {