From ba89fbeab65da5ebf8b5bc7cc4060bbfbc20c4df Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Tue, 27 Feb 2024 12:01:35 -0500 Subject: [PATCH] Replace remaining ANSI escape codes with constants --- src/cli/entryList.go | 14 ++++++++------ src/offline/configParser.go | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/cli/entryList.go b/src/cli/entryList.go index 0310d01..8ed0f63 100644 --- a/src/cli/entryList.go +++ b/src/cli/entryList.go @@ -11,7 +11,9 @@ import ( // global constants used only in this file const ( - ansiAlternateEntryColor = "\033[38;5;8m" + ansiAlternateEntryColor = "\033[38;5;8m" + ansiDirectoryHeader = "\033[38;5;7;48;5;8m" + ansiEmptyDirectoryWarning = "\033[38;5;11m" ) // calculates and returns the final visual indentation multiplier (needed to adjust indentation for skipped parent directories) - also subtracts "old" text from directory header @@ -161,9 +163,9 @@ func EntryListGen() { skippedDirList[i] = false // the directory header is being printed, indicate that it is not being skipped indent, vanityDirectory = indentSubtractor(skippedDirList, dirList, i, indent) // calculate the final indentation multiplier if !offline.Windows { // for consistency, format directories with UNIX-style path separators on all platforms - fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+"\033[38;5;7;48;5;8m%s/"+offline.AnsiReset+"\n", vanityDirectory) + fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+ansiDirectoryHeader+"%s/"+offline.AnsiReset+"\n", vanityDirectory) } else { - fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+"\033[38;5;7;48;5;8m%s/"+offline.AnsiReset+"\n", strings.ReplaceAll(vanityDirectory, offline.PathSeparator, "/")) + fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+ansiDirectoryHeader+"%s/"+offline.AnsiReset+"\n", strings.ReplaceAll(vanityDirectory, offline.PathSeparator, "/")) } } @@ -177,11 +179,11 @@ func EntryListGen() { skippedDirList[i] = false // the directory header is being printed, indicate that it is not being skipped indent, vanityDirectory = indentSubtractor(skippedDirList, dirList, i, indent) // calculate the final indentation multiplier if !offline.Windows { // for consistency, format directories with UNIX-style path separators on all platforms - fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+"\033[38;5;7;48;5;8m%s/"+offline.AnsiReset+"\n", vanityDirectory) + fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+ansiDirectoryHeader+"%s/"+offline.AnsiReset+"\n", vanityDirectory) } else { - fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+"\033[38;5;7;48;5;8m%s/"+offline.AnsiReset+"\n", strings.ReplaceAll(vanityDirectory, offline.PathSeparator, "/")) + fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+ansiDirectoryHeader+"%s/"+offline.AnsiReset+"\n", strings.ReplaceAll(vanityDirectory, offline.PathSeparator, "/")) } - fmt.Print(strings.Repeat(" ", indent*2) + "\033[38;5;11m-empty directory-" + offline.AnsiReset) + fmt.Print(strings.Repeat(" ", indent*2) + ansiEmptyDirectoryWarning + "-empty directory-" + offline.AnsiReset) } else { // warn if the only thing that exists is the root-level directory fmt.Print("\n\nNothing's here! For help creating your first entry, run \"mutn help\".") } diff --git a/src/offline/configParser.go b/src/offline/configParser.go index be15361..60acb3e 100644 --- a/src/offline/configParser.go +++ b/src/offline/configParser.go @@ -11,7 +11,7 @@ var Config = make(map[string]interface{}) func ReadConfig() { cfg, err := ini.Load(home + "/.config/libmutton/libmutton.ini") if err != nil { - fmt.Println(AnsiError + "\033[38;5;9mFailed to load libmutton.ini" + AnsiReset) + fmt.Println(AnsiError + "Failed to load libmutton.ini" + AnsiReset) os.Exit(1) } @@ -22,7 +22,7 @@ func ReadConfig() { // ONLINE (conditional) onlineMode, err := cfg.Section("OFFLINE").Key("onlineMode").Bool() if err != nil { - fmt.Println(AnsiError + "\033[38;5;9mFailed to enable online (synced) mode - [OFFLINE]/onlineMode in libmutton.ini must be a boolean value - continuing in offline mode" + AnsiReset) + fmt.Println(AnsiError + "Failed to enable online (synced) mode - [OFFLINE]/onlineMode in libmutton.ini must be a boolean value - continuing in offline mode" + AnsiReset) onlineMode = false } if onlineMode { @@ -38,7 +38,7 @@ func ReadConfig() { Config["remoteIP"] = cfg.Section("ONLINE").Key("remoteIP").String() Config["remotePort"], err = cfg.Section("ONLINE").Key("remotePort").Int() if err != nil { - fmt.Println(AnsiError + "\033[38;5;9mFailed to enable online (synced) mode - [ONLINE]/remotePort in libmutton.ini must be an integer value- continuing in offline mode" + AnsiReset) + fmt.Println(AnsiError + "Failed to enable online (synced) mode - [ONLINE]/remotePort in libmutton.ini must be an integer value- continuing in offline mode" + AnsiReset) // remotePort == 0 represents offline-only mode Config["remotePort"] = 0 }