Skip to content

Commit

Permalink
auto compile based on OS
Browse files Browse the repository at this point in the history
  • Loading branch information
cipheras committed Oct 10, 2020
1 parent a919eef commit bee30c7
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 5 deletions.
100 changes: 100 additions & 0 deletions linux_gohelper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// +build !windows

package gohelper

import (
"fmt"
"log"
"os"
)

/*
RESET
RED
GREEN
YELLOW
BLUE
PURPLE
CYAN
WHITE
BGBLACK
BOLD
UNDERLINE
BLINK
*/
const (
// ANSI color codes
RESET = "\033[0m"
RED = "\033[31m"
GREEN = "\033[32m"
YELLOW = "\033[33m"
BLUE = "\033[34m"
PURPLE = "\033[35m"
CYAN = "\033[36m"
WHITE = "\033[37m"
BGBLACK = "\033[40m"
BOLD = "\033[1m"
UNDERLINE = "\033[4m"
BLINK = "\033[5m"
CLEAR = "\033[2J\033[H"
)

const (
// N :
N = "normal"
// E :
E = "error"
// W :
W = "warning"
// T :
T = "text"
// I :
I = "info"
// S :
S = "shell"
)

// Try ...
func Try(msg string, err error, mode bool) { //msg,err,exit/noexit
if err != nil {
if msg != "" {
if mode == true {
Cprint(E, msg)
log.Println(msg)
os.Exit(0)
}
Cprint(W, msg)
log.Println(msg)
return
}
if mode == true {
Cprint(E, err)
log.Println(err)
os.Exit(0)
}
Cprint(W, err)
log.Println(err)
}
}

// Cprint ...
func Cprint(mode string, msg ...interface{}) {
var msgs string
for _, v := range msg {
msgs = msgs + fmt.Sprintf("%v ", v)
}
switch mode {
case N: //normal
fmt.Println("\n" + CYAN + "[" + GREEN + "+" + CYAN + "] " + GREEN + msgs + RESET)
case E: //error
fmt.Println("\n" + CYAN + "[" + RED + BLINK + "-" + RESET + CYAN + "] " + RED + BGBLACK + BOLD + "ERROR" + RESET + " " + RED + msgs + RESET)
case W: //warning
fmt.Println("\n" + CYAN + "[" + YELLOW + BLINK + "!" + RESET + CYAN + "] " + YELLOW + BGBLACK + BOLD + "WARN" + RESET + " " + YELLOW + msgs + RESET)
case T: //text
fmt.Println("\n" + CYAN + "[" + PURPLE + "*" + CYAN + "] " + PURPLE + msgs + RESET)
case I: //info
fmt.Println("\n" + CYAN + "[" + BLUE + "i" + CYAN + "] " + BLUE + msgs + RESET)
case S: //shell
fmt.Print("\n" + CYAN + "[" + PURPLE + "*" + CYAN + "] " + PURPLE + msgs + "\n" + GREEN + ">> " + RESET)
}
}
7 changes: 2 additions & 5 deletions gohelper.go → win_gohelper.go
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// +build windows

package gohelper

import (
"fmt"
"log"
"os"
"runtime"

"golang.org/x/sys/windows/registry"
)
Expand Down Expand Up @@ -102,10 +103,6 @@ func Cprint(mode string, msg ...interface{}) {

// Cwindows ...Edit registry to suppory ANSII
func Cwindows() error {
if runtime.GOOS != "windows" {
log.Println("Not building for windows")
return nil
}
reg, err := registry.OpenKey(registry.CURRENT_USER, `Console`, registry.WRITE)
if err != nil {
return err
Expand Down

0 comments on commit bee30c7

Please sign in to comment.