Ruin echos dreams

This commit is contained in:
nea 2022-09-22 14:05:20 +02:00
parent a4787e8df8
commit 0c1858e6bd
No known key found for this signature in database
GPG key ID: AA563E93EB628D91
4 changed files with 173 additions and 134 deletions

2
go.mod
View file

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

144
main.go
View file

@ -3,39 +3,26 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"neowofetch/utils"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"github.com/fatih/color" "github.com/exhq/neowofetch/utils"
) )
var isuwuified bool = true var isuwuified bool = true
var asciiart []string
var aa int
func getHome() string { func getHome() string {
return os.Getenv("HOME") return os.Getenv("HOME")
} }
func incrementaa() {
aa += 1
}
func getConfigFile() string { func getConfigFile() string {
return getHome() + "/.config/neowofetch/conf" return getHome() + "/.config/neowofetch/conf"
} }
func initascii() {
asciiart = utils.Asciioverwrite(utils.Getascii(getDistro()))
aa = 0
print(asciiart[aa])
aa = aa + 1
}
func handleConfig() { func handleConfig() {
_, folder := os.Stat(filepath.Dir(getConfigFile())) _, folder := os.Stat(filepath.Dir(getConfigFile()))
_, file := os.Stat(getConfigFile()) _, file := os.Stat(getConfigFile())
@ -66,118 +53,40 @@ func handleConfig() {
} }
func handlePrint(action, colour string, rest string) { func handlePrint(action, format string, rest string) {
if action == "print" { if action == "print" {
Cprint(colour, rest, true) utils.CutePrint(rest, format)
} else if action == "println" { } else if action == "println" {
Cprint(colour, rest, true) utils.CutePrint(rest, format)
print("\n") utils.CuteNewLine()
if aa < len(asciiart) {
print(asciiart[aa])
}
if aa == len(asciiart) || aa == len(asciiart)-1 {
print(strings.Repeat(" ", len(asciiart[1])))
}
if aa > len(asciiart) {
print(strings.Repeat(" ", len(asciiart[1])))
}
incrementaa()
} else if action == "info" || action == "infoln" { } else if action == "info" || action == "infoln" {
switch rest { switch rest {
case "distro": case "distro":
Cprint(colour, getDistro(), true) utils.CutePrint(getDistro(), format)
case "username": case "username":
Cprint(colour, getUsername(), true) utils.CutePrint(getUsername(), format)
case "uptime": case "uptime":
no, _ := strconv.Atoi(getUptime()) no, _ := strconv.Atoi(getUptime())
Cprint(colour, formatTime(no), false) utils.CutePrint(formatTime(no), format)
case "hostname": case "hostname":
Cprint(colour, getHostname(), true) utils.CutePrint(getHostname(), format)
case "GPU": case "GPU":
Cprint(colour, getGPU(), true) utils.CutePrint(getGPU(), format)
case "shell": case "shell":
Cprint(colour, getShell(), true) utils.CutePrint(getShell(), format)
case "terminal": case "terminal":
Cprint(colour, getTerminal(), true) utils.CutePrint(getTerminal(), format)
case "memoryAll": case "memoryAll":
Cprint(colour, getMemory(false), true) utils.CutePrint(getMemory(false), format)
case "memoryUsed": case "memoryUsed":
Cprint(colour, getMemory(true), true) utils.CutePrint(getMemory(true), format)
default: default:
print("{UNKNOWN KEYWORD}") print("{UNKNOWN KEYWORD}")
} }
}
if action == "infoln" { if action == "infoln" {
utils.CuteNewLine()
print("\n")
if aa < len(asciiart) {
print(asciiart[aa])
} else {
print(strings.Repeat(" ", len(asciiart[1])))
}
incrementaa()
} }
} }
func Cprint(colour string, message string, uwu bool) {
if uwu && utils.Woulduwuify() {
message = uwuify(message)
}
yellow := color.New(color.FgYellow).SprintFunc()
red := color.New(color.FgRed).SprintFunc()
green := color.New(color.FgGreen).SprintFunc()
magenta := color.New(color.FgMagenta).SprintFunc()
blue := color.New(color.FgBlue).SprintFunc()
black := color.New(color.FgBlack).SprintFunc()
switch colour {
case "yellow":
print(yellow(message))
case "white":
print(message)
case "magenta":
print(magenta(message))
case "red":
print(red(message))
case "blue":
print(blue(message))
case "black":
print(black(message))
case "green":
print(green(message))
}
}
func uwuify(message string) string {
var answer string
var sentence []string
var hasspace bool
if strings.Contains(message, " ") {
sentence = strings.Split(message, " ")
hasspace = true
} else {
sentence = strings.Split(message, " ")
hasspace = false
}
for _, word := range sentence {
if !strings.Contains(strings.ToLower(word), "uwu") {
word = strings.Replace(word, "u", "UwU", -1)
if strings.Contains(strings.ToLower(word), "owo") {
word = strings.Replace(word, "o", "OwO", -1)
}
word = strings.Replace(word, "r", "w", -1)
}
if hasspace {
answer += word + " "
} else {
answer += word
}
}
return answer
} }
func getHostname() string { func getHostname() string {
@ -190,9 +99,7 @@ func getUsername() string {
shell, _ := cmd.Output() shell, _ := cmd.Output()
return strings.Replace(string(shell), "\n", "", -1) return strings.Replace(string(shell), "\n", "", -1)
} }
func getLogo() {
}
func getDistro() string { func getDistro() string {
distro, err := os.Open("/etc/os-release") distro, err := os.Open("/etc/os-release")
if err != nil { if err != nil {
@ -201,7 +108,7 @@ func getDistro() string {
} }
distro_info := make([]byte, 1024) distro_info := make([]byte, 1024)
distro.Read(distro_info) distro.Read(distro_info)
distro.Close() defer distro.Close()
distro_list := strings.Split(string(distro_info), "\n") distro_list := strings.Split(string(distro_info), "\n")
distro_tuples := make(map[string]string) distro_tuples := make(map[string]string)
for _, v := range distro_list { for _, v := range distro_list {
@ -243,11 +150,11 @@ func getTheme() {
func getIcons() { func getIcons() {
} }
func getTerminal() string { func getTerminal() string {
_, existprgm := os.LookupEnv("TERM_PROGRAM") a, existprgm := os.LookupEnv("TERM_PROGRAM")
if !existprgm { if !existprgm {
return os.Getenv("TERM") return os.Getenv("TERM")
} else { } else {
return os.Getenv("TERM_PROGRAM") return a
} }
} }
@ -313,16 +220,6 @@ func getMemory(used bool) string {
} }
} }
func handleremainingascii() {
if aa < len(asciiart) {
for i := 0; i < len(asciiart)-aa; i++ {
print("\n", asciiart[aa])
incrementaa()
}
}
}
func formatTime(seconds int) string { func formatTime(seconds int) string {
minutes := seconds / 60 minutes := seconds / 60
secondsre := strconv.Itoa(seconds % 60) secondsre := strconv.Itoa(seconds % 60)
@ -336,8 +233,7 @@ func getColorPalette() {
func main() { func main() {
utils.Initargs() utils.Initargs()
initascii() utils.CutePrintInit(utils.Getascii(getDistro()))
handleConfig() handleConfig()
handleremainingascii() utils.CutePrintEnd()
print("\n")
} }

View file

@ -1,10 +1,6 @@
package utils package utils
import ( func Getascii(name string) string {
"strings"
)
func Getascii(name string) []string {
none := `!!!!!!!!!!!!!!! none := `!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!
!!!!noascii!!!! !!!!noascii!!!!
@ -20,11 +16,10 @@ func Getascii(name string) []string {
switch name { switch name {
case "Arch Linux": case "Arch Linux":
return strings.Split(arch, "\n") return arch
default: default:
return strings.Split(none, "\n") return none
} }
} }

148
utils/printing.go Normal file
View file

@ -0,0 +1,148 @@
package utils
import (
"fmt"
"math/rand"
"strings"
)
func rgb(r, g, b int) string {
return fmt.Sprintf("\x1b[38:2::%d:%d:%dm", r, g, b)
}
var colors = map[string]string{
"green": rgb(0, 255, 0),
"blue": rgb(0, 0, 255),
"red": rgb(255, 0, 0),
}
var uwuEmotes = [15]string{
"owo",
"UwU",
">w<",
"^w^",
"●w●",
"☆w☆",
"𝗨𝘄𝗨",
"(´꒳`)",
"♥(。U ω U。)",
"(˘ε˘)",
"( ˘ᴗ˘ )",
"(*ฅ́˘ฅ̀*)",
"*screams*",
"*twerks*",
"*sweats*",
}
var logoIndex = 0
var isInProgressLine = false
var logoLines []string
var logoWidth int
func CutePrintInit(logo string) {
if noascii {
logo = ""
}
logoLines = strings.Split(logo, "\n")
logoWidth = 0
for _, v := range logoLines {
lineLength := len([]rune(v))
if lineLength > logoWidth {
logoWidth = lineLength
}
}
}
func printLogoIfAtBeginningOfNewLine() {
if !isInProgressLine {
isInProgressLine = true
if logoIndex < len(logoLines) {
logoLine := logoLines[logoIndex]
logoIndex += 1
logoLineLength := len([]rune(logoLine))
padding := strings.Repeat(" ", logoWidth-logoLineLength)
fmt.Printf("%s%s", logoLine, padding)
} else {
fmt.Printf("%s", strings.Repeat(" ", logoWidth))
}
}
}
func uwuify(message string) (ret string) {
sentence := strings.Split(message, " ")
ret = ""
for i, word := range sentence {
if !strings.Contains(strings.ToLower(word), "uwu") {
word = strings.ReplaceAll(word, "u", "UwU")
if strings.Contains(strings.ToLower(word), "owo") {
word = strings.ReplaceAll(word, "o", "OwO")
}
word = strings.ReplaceAll(word, "r", "w")
}
if i != 0 {
ret += " "
}
ret += word
}
return ret
}
type Format struct {
noUwuOverride bool
colorFormat string
}
func parseFormat(format string) (parsedFormat Format) {
for _, v := range strings.Split(format, "|") {
colorFormat, isColor := colors[v]
if isColor {
parsedFormat.colorFormat += colorFormat
} else {
switch v {
case "italic":
parsedFormat.colorFormat += "\x1b[3m"
break
case "bold":
parsedFormat.colorFormat += "\x1b1"
break
case "nouwu":
parsedFormat.noUwuOverride = true
break
case "*":
break
default:
//println("Unknown format code: ", v)
}
}
}
return parsedFormat
}
func CutePrint(
message string,
format string,
) {
printLogoIfAtBeginningOfNewLine()
parsedFormat := parseFormat(format)
willUwuify := shoulduwuify && !parsedFormat.noUwuOverride
if willUwuify {
message = uwuify(message)
}
fmt.Printf("%s%s\x1b[0m", parsedFormat.colorFormat, message)
}
func CuteNewLine() {
printLogoIfAtBeginningOfNewLine()
if rand.Intn(5) == 0 && shoulduwuify {
fmt.Printf(" %s", uwuEmotes[rand.Intn(len(uwuEmotes))])
}
isInProgressLine = false
fmt.Println()
}
func CutePrintEnd() {
for logoIndex < len(logoLines) {
CuteNewLine()
}
}