flatface.go: Added colors to text ouput
This commit is contained in:
parent
279e2d390d
commit
43108b31f6
73
flatface.go
73
flatface.go
@ -7,8 +7,18 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
func clearScreen() {
|
||||
cmd := exec.Command("clear")
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
searchRepo()
|
||||
}
|
||||
fmt.Print(string(out))
|
||||
}
|
||||
func input(s string) (string, error) {
|
||||
stdinBuf := bufio.NewReader(os.Stdin)
|
||||
|
||||
@ -22,11 +32,13 @@ func input(s string) (string, error) {
|
||||
}
|
||||
|
||||
func searchRepo() {
|
||||
print("\n| Search Repositories |\n\n")
|
||||
color.Set(color.FgHiCyan)
|
||||
print("\n| Search Repositories |\n")
|
||||
print("Enter a search term and copy the namespace to clipboard\n")
|
||||
print("Paste this later to the install menu.\n\n")
|
||||
print("Type: 'm' for main menu\n")
|
||||
print("Type: 'q' to quit the application\n\n")
|
||||
color.Unset()
|
||||
|
||||
var programName, _ = input(">> ")
|
||||
|
||||
@ -42,18 +54,24 @@ func searchRepo() {
|
||||
if err != nil {
|
||||
searchRepo()
|
||||
}
|
||||
fmt.Print("\n", "Results for ", trimInput, ": \n\n", string(out), "\n")
|
||||
color.Set(color.FgHiGreen)
|
||||
print("\n==============================================================\n")
|
||||
fmt.Print("Results for ", trimInput, ": \n\n", string(out), "\n")
|
||||
print("\n\n==============================================================\n")
|
||||
color.Unset()
|
||||
searchRepo()
|
||||
}
|
||||
}
|
||||
|
||||
func installPak() {
|
||||
color.Set(color.FgHiCyan)
|
||||
print("\n| Install Menu |\n\n")
|
||||
print("To Use: Copy paste a flatpak namespace from search results\n\n")
|
||||
print("EXAMPLE: 'com.play0ad.zeroad' - installs the Game '0ad'\n\n")
|
||||
print("Type: 'm' for main menu\n")
|
||||
print("Type: 'q' to quit the application\n\n")
|
||||
print("NOTE: install can take several seconds and appear to hang. Please be patient...\n\n")
|
||||
color.Unset()
|
||||
var programName, _ = input(">> ")
|
||||
|
||||
trimInput := strings.TrimSpace(programName)
|
||||
@ -71,27 +89,42 @@ func installPak() {
|
||||
if err != nil {
|
||||
installPak()
|
||||
}
|
||||
color.Set(color.FgHiGreen)
|
||||
print("\n==========================================================================\n\n")
|
||||
fmt.Print(string(out), "\n")
|
||||
print("\n============================================================================\n\n")
|
||||
color.Unset()
|
||||
installPak()
|
||||
}
|
||||
}
|
||||
|
||||
func listPak() {
|
||||
print("\n| List of installed Flatpaks |\n\n")
|
||||
color.Set(color.FgHiGreen)
|
||||
print("\n| List of installed Flatpaks |\n")
|
||||
color.Unset()
|
||||
cmd := exec.Command("flatpak", "list")
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Fatalf("cmd.Run() failed with %s\n", err)
|
||||
}
|
||||
|
||||
color.Set(color.FgHiYellow)
|
||||
print("\n============================================================================\n\n")
|
||||
fmt.Print(string(out), "\n\n")
|
||||
print("\n============================================================================\n\n")
|
||||
color.Unset()
|
||||
}
|
||||
|
||||
func removePak() {
|
||||
print("\n| Remove Flatpaks |\n\n")
|
||||
color.Set(color.FgHiCyan)
|
||||
print("\n| Remove Flatpaks |\n")
|
||||
color.Unset()
|
||||
listPak()
|
||||
color.Set(color.FgHiCyan)
|
||||
print("\n\nCopy and paste a namespace above and press enter to remove from system\n\n")
|
||||
print("Type: 'm' for main menu\n")
|
||||
print("Type: 'q' to quit the application\n\n")
|
||||
color.Unset()
|
||||
var programName, _ = input(">> ")
|
||||
|
||||
trimInput := strings.TrimSpace(programName)
|
||||
@ -106,7 +139,11 @@ func removePak() {
|
||||
if err != nil {
|
||||
removePak()
|
||||
}
|
||||
color.Set(color.FgHiRed)
|
||||
print("\n==========================================================================\n\n")
|
||||
fmt.Print(string(out), "\n\n")
|
||||
print("\n==========================================================================\n\n")
|
||||
color.Unset()
|
||||
removePak()
|
||||
}
|
||||
}
|
||||
@ -126,16 +163,23 @@ func optionsMenu() {
|
||||
}
|
||||
*/
|
||||
func syncRepo() {
|
||||
color.Set(color.FgHiMagenta)
|
||||
print("Syncing repo data...\n")
|
||||
color.Unset()
|
||||
cmd := exec.Command("flatpak", "update", "--appstream")
|
||||
|
||||
out, err := cmd.CombinedOutput()
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("cmd.Run() failed with %s\n", err)
|
||||
}
|
||||
color.Set(color.FgHiGreen)
|
||||
fmt.Print(string(out))
|
||||
color.Unset()
|
||||
}
|
||||
|
||||
func checkRepo() {
|
||||
color.Set(color.FgHiYellow)
|
||||
print("\nAdding flathub repo if needed...\n")
|
||||
cmd := exec.Command("flatpak", "remote-add", "--if-not-exists", "flathub", "https://flathub.org/repo/flathub.flatpakrepo")
|
||||
out, err := cmd.CombinedOutput()
|
||||
@ -147,23 +191,30 @@ func checkRepo() {
|
||||
}
|
||||
|
||||
func updatePak() {
|
||||
color.Set(color.FgHiYellow)
|
||||
print("Checking for app upgrades..\n")
|
||||
color.Unset()
|
||||
cmd := exec.Command("flatpak", "update")
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Fatalf("cmd.Run() failed with %s\n", err)
|
||||
}
|
||||
color.Set(color.FgHiGreen)
|
||||
fmt.Print(string(out))
|
||||
color.Unset()
|
||||
}
|
||||
func mainMenu() {
|
||||
print("\n\n| FlatFace v0.0.1a-3 |\n\n")
|
||||
color.Set(color.FgHiCyan)
|
||||
print("\n\n| FlatFace v0.0.1a-4 |\n\n")
|
||||
var choice string
|
||||
print("[S]earch remote for flatpaks\n")
|
||||
print("[I]nstall flatpaks from remote\n")
|
||||
print("[R]emove local flatpaks\n")
|
||||
print("[L]ist install flatpaks\n")
|
||||
print("[U]pdate\n")
|
||||
print("[Q]uit\n\n")
|
||||
|
||||
print("[s] Search remote for flatpaks\n")
|
||||
print("[l] Install flatpaks from remote\n")
|
||||
print("[r] Remove local flatpaks\n")
|
||||
print("[l] List install flatpaks\n")
|
||||
print("[u] Update\n")
|
||||
print("[q] Quit\n\n")
|
||||
color.Unset()
|
||||
|
||||
choice, _ = input(">> ")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user