-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from asciifaceman/feature/realterm
massive overhaul of the entire color system
- Loading branch information
Showing
12 changed files
with
486 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package hobocode | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/jedib0t/go-pretty/v6/text" | ||
) | ||
|
||
// Icolor prints the given string at the given indent | ||
// to the given os.File with the given text.Color, if colorable | ||
func Icolor(indent int, fd *os.File, color text.Color, message string) { | ||
id := Tindent(indent) | ||
if Colorable(fd) { | ||
fmt.Fprint(fd, id) | ||
Stdlin(fd, color.Sprint(message)) | ||
} else { | ||
fmt.Fprint(fd, id) | ||
Stdlin(fd, message) | ||
} | ||
} | ||
|
||
// Icolorf prints the given format at the given indent | ||
// to the given os.File with the given text.Color, if colorable | ||
func Icolorf(indent int, fd *os.File, color text.Color, format string, a ...interface{}) { | ||
id := Tindent(indent) | ||
if Colorable(fd) { | ||
fmt.Fprint(fd, id) | ||
Stdlin(fd, color.Sprintf(format, a...)) | ||
} else { | ||
fmt.Fprint(fd, id) | ||
Stdlin(fd, fmt.Sprintf(format, a...)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Hobocode Examples | ||
|
||
``` | ||
go run prints.go | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/asciifaceman/hobocode" | ||
) | ||
|
||
func main() { | ||
hobocode.Header("Info") | ||
hobocode.Info("This is an info message") | ||
hobocode.Infof("This is a formatted info message: %v", time.Now().Format("2006/01/02")) | ||
hobocode.Iinfo(1, "This is an info message indented once") | ||
hobocode.Iinfo(2, "This is an info message indented twice") | ||
hobocode.Iinfof(1, "This is a formatted info message indented once: %v", time.Now().Format("2006/01/02")) | ||
hobocode.Iinfof(2, "This is a formatted info message indented twice: %v", time.Now().Format("2006/01/02")) | ||
|
||
hobocode.Header("Warn") | ||
hobocode.Warn("This is a warn message") | ||
hobocode.Warnf("This is a formatted warn message: %v", time.Now().Format("2006/01/02")) | ||
|
||
hobocode.Header("Error") | ||
hobocode.Error("This is an error message") | ||
hobocode.Errorf("This is a formatted error message: %v", fmt.Errorf("error occured at %v", time.Now().Format("2006/01/02"))) | ||
|
||
hobocode.Header("Success") | ||
hobocode.Success("This is a success message!") | ||
hobocode.Successf("This is a formatted successs message! %v", time.Now().Format("2006/01/02")) | ||
|
||
hobocode.Header("Debug") | ||
hobocode.Debug("This is a debug message!") | ||
hobocode.Debugf("This is a formatted debug message! %v", time.Now().Format("2006/01/02")) | ||
|
||
hobocode.HeaderLeft("A left justified header!?") | ||
hobocode.HeaderLeft("Whoa!") | ||
hobocode.HeaderLeft("That's cool") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package hobocode | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/jedib0t/go-pretty/v6/text" | ||
) | ||
|
||
var ( | ||
out = os.Stdout | ||
err = os.Stderr | ||
) | ||
|
||
/* | ||
Stdout helpers | ||
*/ | ||
|
||
// Info prints the given message with bright cyan if Colorable | ||
// | ||
// Stdout | ||
func Info(message string) { | ||
Icolor(0, out, text.FgHiCyan, message) | ||
} | ||
|
||
// Infof prints the given formatted message with bright cyan if colorable | ||
// | ||
// Stdout | ||
func Infof(format string, a ...interface{}) { | ||
Icolorf(0, out, text.FgHiCyan, format, a...) | ||
} | ||
|
||
// Iinfo prints the given message with bright cyan if Colorable and an indent | ||
// | ||
// Stdout | ||
func Iinfo(indent int, message string) { | ||
Icolor(indent, out, text.FgHiCyan, message) | ||
} | ||
|
||
// Iinfof prints the given formatted message with bright cyan if Colorable and an indent | ||
// | ||
// Stdout | ||
func Iinfof(indent int, format string, a ...interface{}) { | ||
Icolorf(indent, out, text.FgHiCyan, format, a...) | ||
} | ||
|
||
// Success prints the given message with bright green if Colorable | ||
// | ||
// Stdout | ||
func Success(message string) { | ||
Icolor(0, out, text.FgHiGreen, message) | ||
} | ||
|
||
// Successf prints the given formatted message with bright green if Colorable | ||
// | ||
// Stdout | ||
func Successf(format string, a ...interface{}) { | ||
Icolorf(0, out, text.FgHiGreen, format, a...) | ||
} | ||
|
||
// Isuccess prints the given message with bright green if Colorable with an indent | ||
// | ||
// Stdout | ||
func Isuccess(indent int, message string) { | ||
Icolor(indent, out, text.FgHiGreen, message) | ||
} | ||
|
||
// Isuccessf prints the given formatted message with bright green if Colorable with an indent | ||
// | ||
// Stdout | ||
func Isuccessf(indent int, format string, a ...interface{}) { | ||
Icolorf(indent, out, text.FgHiGreen, format, a...) | ||
} | ||
|
||
// Debug prints the given message with bright green if Colorable | ||
// | ||
// Stdout | ||
func Debug(message string) { | ||
Icolor(0, out, text.FgHiBlue, message) | ||
} | ||
|
||
// Debugf prints the given formatted message with bright green if Colorable | ||
// | ||
// Stdout | ||
func Debugf(format string, a ...interface{}) { | ||
Icolorf(0, out, text.FgHiBlue, format, a...) | ||
} | ||
|
||
// Idebug prints the given message with bright green if Colorable with an indent | ||
// | ||
// Stdout | ||
func Idebug(indent int, message string) { | ||
Icolor(indent, out, text.FgHiBlue, message) | ||
} | ||
|
||
// Idebugf prints the given formatted message with bright green if Colorable with an indent | ||
// | ||
// Stdout | ||
func Idebugf(indent int, format string, a ...interface{}) { | ||
Icolorf(indent, out, text.FgHiBlue, format, a...) | ||
} | ||
|
||
/* | ||
Stderr helpers | ||
*/ | ||
|
||
// Warn prints the given message with bright yellow if Colorable | ||
// | ||
// Stderr | ||
func Warn(message string) { | ||
Icolor(0, err, text.FgHiYellow, message) | ||
} | ||
|
||
// Warnf prints the given formatted message with bright yellow if Colorable | ||
// | ||
// Stderr | ||
func Warnf(format string, a ...interface{}) { | ||
Icolorf(0, err, text.FgHiYellow, format, a...) | ||
} | ||
|
||
// Iwarn prints the given message with bright yellow if Colorable and an indent | ||
// | ||
// Stderr | ||
func Iwarn(indent int, message string) { | ||
Icolor(indent, err, text.FgHiYellow, message) | ||
} | ||
|
||
// Iwarnf prints the given formatted message with bright yellow if Colorable and an indent | ||
// | ||
// Stderr | ||
func Iwarnf(indent int, format string, a ...interface{}) { | ||
Icolorf(indent, err, text.FgHiYellow, format, a...) | ||
} | ||
|
||
// Error prints the given message with bright red if Colorable | ||
// | ||
// Stderr | ||
func Error(message string) { | ||
Icolor(0, err, text.FgHiRed, message) | ||
} | ||
|
||
// Errorf prints the given formatted message with bright red if Colorable | ||
// | ||
// Stderr | ||
func Errorf(format string, a ...interface{}) { | ||
Icolorf(0, err, text.FgHiRed, format, a...) | ||
} | ||
|
||
// Ierror prints the given message with bright red if Colorable and an indent | ||
// | ||
// Stderr | ||
func Ierror(indent int, message string) { | ||
Icolor(indent, err, text.FgHiRed, message) | ||
} | ||
|
||
// Ierrorf prints the given formatted message with bright red if Colorable and an indent | ||
// | ||
// Stderr | ||
func Ierrorf(indent int, format string, a ...interface{}) { | ||
Icolorf(indent, err, text.FgHiRed, format, a...) | ||
} |
Oops, something went wrong.