Printing padding and moving

This commit is contained in:
nea 2022-09-09 22:24:04 +02:00 committed by echo
parent 0c0d0311a2
commit 169bb2cc22
4 changed files with 166 additions and 113 deletions

3
go.mod Normal file
View file

@ -0,0 +1,3 @@
module github.com/exhq/neowofetch
go 1.19

152
main.go
View file

@ -3,16 +3,16 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"math/rand"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"github.com/exhq/neowofetch/util"
) )
var isuwuified bool = true var isuwuified bool = true
var tempbool bool
var arch = ` /\ 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 + " " func getConfigFile() string {
return getHome() + "/.config/neowofetch/conf"
}
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 handleConfig() { func handleConfig() {
_, folder := os.Stat("/home/" + getUsername() + "/.config/neowofetch") _, folder := os.Stat(filepath.Dir(getConfigFile()))
_, file := os.Stat("/home/" + getUsername() + "/.config/neowofetch/conf") _, file := os.Stat(getConfigFile())
if os.IsNotExist(folder) { if os.IsNotExist(folder) {
os.Mkdir("/home/"+getUsername()+"/.config/neowofetch", os.ModePerm) os.Mkdir(filepath.Dir(getConfigFile()), os.ModePerm)
} }
if os.IsNotExist(file) { if os.IsNotExist(file) {
println("bruh you aint got tha file? bruh fr fr bruh wtf") println("bruh you aint got tha file? bruh fr fr bruh wtf")
f, _ := os.Create("/home/" + getUsername() + "/.config/neowofetch/conf") f, _ := os.Create(getConfigFile())
_, _ = f.WriteString( _, _ = f.WriteString("test\namong")
`test
among`)
} else { } else {
body, _ := ioutil.ReadFile("/home/" + getUsername() + "/.config/neowofetch/conf") body, _ := ioutil.ReadFile(getConfigFile())
fbody := strings.Split(string(body), "\n") fbody := strings.Split(string(body), "\n")
util.InitUwuPrinter()
for _, s := range fbody { for _, s := range fbody {
w := strings.Split(s, " ") w := strings.SplitN(s, " ", 2)
if len(w) == 1 { if len(w) < 2 {
continue continue
} }
declr := w[0] verb := w[0]
inf := w[1] argument := w[1]
nouwu := w[len(w)-1] nouwu := false
if declr == "nn-prin" { if strings.HasPrefix(argument, "-uwu ") {
cprint(strings.Join(w[1:], " "), false, nouwu == "nouwu") nouwu = true
argument = argument[5:]
} }
if declr == "prin" { if verb == "print" {
cprint(strings.Join(w[1:], " "), true, nouwu == "nouwu") util.UwuPrint(argument, nouwu)
} } else if verb == "println" {
if declr == "nn-info" || declr == "info" { util.UwuPrint(argument, nouwu)
if declr == "info" { util.UwuNewline()
tempbool = true } else if verb == "info" {
PrintInfo(argument, nouwu)
} else if verb == "infoln" {
PrintInfo(argument, nouwu)
util.UwuNewline()
} else { } else {
tempbool = false fmt.Printf("Unknown verb %s\n", verb)
}
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)
} }
} }
} }
} }
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() { func handleArgs() {
@ -297,21 +245,5 @@ func getColorPalette() {
func main() { func main() {
handleArgs() handleArgs()
handleConfig() handleConfig()
ex, err := os.Executable() util.UwuPrintRest()
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()
*/
} }

5
subdirectory/sub.go Normal file
View file

@ -0,0 +1,5 @@
package subdirectory;
func TestFun() {
}

113
util/printing.go Normal file
View file

@ -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()
}
}