Merge pull request #1165 from harshavardhana/palette-theme
Add SetCustomPalette rather than theme
This commit is contained in:
+1
-1
@@ -119,7 +119,7 @@ func checkAccessSyntax(ctx *cli.Context) {
|
||||
func mainAccess(ctx *cli.Context) {
|
||||
checkAccessSyntax(ctx)
|
||||
|
||||
console.SetCustomTheme(map[string]*color.Color{
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Access": color.New(color.FgGreen, color.Bold),
|
||||
})
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ func mainConfigAlias(ctx *cli.Context) {
|
||||
checkConfigAliasSyntax(ctx)
|
||||
|
||||
// set new custom coloring
|
||||
console.SetCustomTheme(map[string]*color.Color{
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Alias": color.New(color.FgCyan, color.Bold),
|
||||
"AliasMessage": color.New(color.FgGreen, color.Bold),
|
||||
"URL": color.New(color.FgWhite, color.Bold),
|
||||
|
||||
+1
-1
@@ -113,7 +113,7 @@ func mainConfigHost(ctx *cli.Context) {
|
||||
checkConfigHostSyntax(ctx)
|
||||
|
||||
// set new custom coloring
|
||||
console.SetCustomTheme(map[string]*color.Color{
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Host": color.New(color.FgCyan, color.Bold),
|
||||
"API": color.New(color.FgYellow, color.Bold),
|
||||
"HostMessage": color.New(color.FgGreen, color.Bold),
|
||||
|
||||
+1
-1
@@ -312,7 +312,7 @@ func doCopySession(session *sessionV2) {
|
||||
func mainCopy(ctx *cli.Context) {
|
||||
checkCopySyntax(ctx)
|
||||
|
||||
console.SetCustomTheme(map[string]*color.Color{
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Copy": color.New(color.FgGreen, color.Bold),
|
||||
})
|
||||
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ func checkDiffSyntax(ctx *cli.Context) {
|
||||
func mainDiff(ctx *cli.Context) {
|
||||
checkDiffSyntax(ctx)
|
||||
|
||||
console.SetCustomTheme(map[string]*color.Color{
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"DiffMessage": color.New(color.FgGreen, color.Bold),
|
||||
"DiffOnlyInFirst": color.New(color.FgRed, color.Bold),
|
||||
"DiffType": color.New(color.FgYellow, color.Bold),
|
||||
|
||||
+1
-1
@@ -98,7 +98,7 @@ func mainList(ctx *cli.Context) {
|
||||
args = []string{"."}
|
||||
}
|
||||
|
||||
console.SetCustomTheme(map[string]*color.Color{
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"File": color.New(color.FgWhite),
|
||||
"Dir": color.New(color.FgCyan, color.Bold),
|
||||
"Size": color.New(color.FgYellow),
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ func checkMakeBucketSyntax(ctx *cli.Context) {
|
||||
func mainMakeBucket(ctx *cli.Context) {
|
||||
checkMakeBucketSyntax(ctx)
|
||||
|
||||
console.SetCustomTheme(map[string]*color.Color{
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"MakeBucket": color.New(color.FgGreen, color.Bold),
|
||||
})
|
||||
|
||||
|
||||
+1
-1
@@ -312,7 +312,7 @@ func doMirrorSession(session *sessionV2) {
|
||||
func mainMirror(ctx *cli.Context) {
|
||||
checkMirrorSyntax(ctx)
|
||||
|
||||
console.SetCustomTheme(map[string]*color.Color{
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Mirror": color.New(color.FgGreen, color.Bold),
|
||||
})
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ func getFixedWidth(width, percent int) int {
|
||||
|
||||
// newProgressBar - instantiate a pbBar.
|
||||
func newProgressBar() barSend {
|
||||
console.SetCustomTheme(map[string]*color.Color{
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Bar": color.New(color.FgGreen, color.Bold),
|
||||
})
|
||||
cmdCh := make(chan barMsg)
|
||||
|
||||
+24
-24
@@ -41,8 +41,8 @@ var IsExited = false
|
||||
// IsError sets this boolean value if Error is called when IsTesting is enabled
|
||||
var IsError = false
|
||||
|
||||
// Theme default map
|
||||
var Theme = map[string]*color.Color{
|
||||
// Palette default map
|
||||
var Palette = map[string]*color.Color{
|
||||
"Debug": color.New(color.FgWhite, color.Faint, color.Italic),
|
||||
"Fatal": color.New(color.FgRed, color.Italic, color.Bold),
|
||||
"Error": color.New(color.FgYellow, color.Italic),
|
||||
@@ -61,25 +61,25 @@ var (
|
||||
|
||||
// Print prints a message
|
||||
Print = func(data ...interface{}) {
|
||||
consolePrint("Print", Theme["Print"], data...)
|
||||
consolePrint("Print", Palette["Print"], data...)
|
||||
return
|
||||
}
|
||||
|
||||
// PrintC prints a message with color
|
||||
PrintC = func(data ...interface{}) {
|
||||
consolePrint("PrintC", Theme["PrintC"], data...)
|
||||
consolePrint("PrintC", Palette["PrintC"], data...)
|
||||
return
|
||||
}
|
||||
|
||||
// Printf prints a formatted message
|
||||
Printf = func(format string, data ...interface{}) {
|
||||
consolePrintf("Print", Theme["Print"], format, data...)
|
||||
consolePrintf("Print", Palette["Print"], format, data...)
|
||||
return
|
||||
}
|
||||
|
||||
// Println prints a message with a newline
|
||||
Println = func(data ...interface{}) {
|
||||
consolePrintln("Print", Theme["Print"], data...)
|
||||
consolePrintln("Print", Palette["Print"], data...)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -96,21 +96,21 @@ var (
|
||||
|
||||
// Fatal print a error message and exit
|
||||
Fatal = func(data ...interface{}) {
|
||||
consolePrint("Fatal", Theme["Fatal"], data...)
|
||||
consolePrint("Fatal", Palette["Fatal"], data...)
|
||||
fatalQuitRoutine()
|
||||
return
|
||||
}
|
||||
|
||||
// Fatalf print a error message with a format specified and exit
|
||||
Fatalf = func(format string, data ...interface{}) {
|
||||
consolePrintf("Fatal", Theme["Fatal"], format, data...)
|
||||
consolePrintf("Fatal", Palette["Fatal"], format, data...)
|
||||
fatalQuitRoutine()
|
||||
return
|
||||
}
|
||||
|
||||
// Fatalln print a error message with a new line and exit
|
||||
Fatalln = func(data ...interface{}) {
|
||||
consolePrintln("Fatal", Theme["Fatal"], data...)
|
||||
consolePrintln("Fatal", Palette["Fatal"], data...)
|
||||
fatalQuitRoutine()
|
||||
return
|
||||
}
|
||||
@@ -127,40 +127,40 @@ var (
|
||||
|
||||
// Error prints a error message
|
||||
Error = func(data ...interface{}) {
|
||||
consolePrint("Error", Theme["Error"], data...)
|
||||
consolePrint("Error", Palette["Error"], data...)
|
||||
errorQuitRoutine()
|
||||
return
|
||||
}
|
||||
|
||||
// Errorf print a error message with a format specified
|
||||
Errorf = func(format string, data ...interface{}) {
|
||||
consolePrintf("Error", Theme["Error"], format, data...)
|
||||
consolePrintf("Error", Palette["Error"], format, data...)
|
||||
errorQuitRoutine()
|
||||
return
|
||||
}
|
||||
|
||||
// Errorln prints a error message with a new line
|
||||
Errorln = func(data ...interface{}) {
|
||||
consolePrintln("Error", Theme["Error"], data...)
|
||||
consolePrintln("Error", Palette["Error"], data...)
|
||||
errorQuitRoutine()
|
||||
return
|
||||
}
|
||||
|
||||
// Info prints a informational message
|
||||
Info = func(data ...interface{}) {
|
||||
consolePrint("Info", Theme["Info"], data...)
|
||||
consolePrint("Info", Palette["Info"], data...)
|
||||
return
|
||||
}
|
||||
|
||||
// Infof prints a informational message in custom format
|
||||
Infof = func(format string, data ...interface{}) {
|
||||
consolePrintf("Info", Theme["Info"], format, data...)
|
||||
consolePrintf("Info", Palette["Info"], format, data...)
|
||||
return
|
||||
}
|
||||
|
||||
// Infoln prints a informational message with a new line
|
||||
Infoln = func(data ...interface{}) {
|
||||
consolePrintln("Info", Theme["Info"], data...)
|
||||
consolePrintln("Info", Palette["Info"], data...)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -168,36 +168,36 @@ var (
|
||||
// Debug prints a debug message
|
||||
Debug = func(data ...interface{}) {
|
||||
if !NoDebugPrint {
|
||||
consolePrint("Debug", Theme["Debug"], data...)
|
||||
consolePrint("Debug", Palette["Debug"], data...)
|
||||
}
|
||||
}
|
||||
|
||||
// Debugf prints a debug message with a new line
|
||||
Debugf = func(format string, data ...interface{}) {
|
||||
if !NoDebugPrint {
|
||||
consolePrintf("Debug", Theme["Debug"], format, data...)
|
||||
consolePrintf("Debug", Palette["Debug"], format, data...)
|
||||
}
|
||||
}
|
||||
|
||||
// Debugln prints a debug message with a new line
|
||||
Debugln = func(data ...interface{}) {
|
||||
if !NoDebugPrint {
|
||||
consolePrintln("Debug", Theme["Debug"], data...)
|
||||
consolePrintln("Debug", Palette["Debug"], data...)
|
||||
}
|
||||
}
|
||||
|
||||
// Colorize prints message in a colorized form, dictated by the corresponding tag argument
|
||||
Colorize = func(tag string, data interface{}) string {
|
||||
if isatty.IsTerminal(os.Stdout.Fd()) {
|
||||
return Theme[tag].SprintFunc()(data)
|
||||
return Palette[tag].SprintFunc()(data)
|
||||
}
|
||||
return fmt.Sprint(data)
|
||||
}
|
||||
|
||||
// Eraseline Print in new line and adjust to top so that we don't print over the ongoing progress bar
|
||||
Eraseline = func() {
|
||||
consolePrintf("Print", Theme["Print"], "%c[2K\n", 27)
|
||||
consolePrintf("Print", Theme["Print"], "%c[A", 27)
|
||||
consolePrintf("Print", Palette["Print"], "%c[2K\n", 27)
|
||||
consolePrintf("Print", Palette["Print"], "%c[A", 27)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -353,13 +353,13 @@ func Unlock() {
|
||||
publicMutex.Unlock()
|
||||
}
|
||||
|
||||
// SetCustomTheme sets a color theme
|
||||
func SetCustomTheme(theme map[string]*color.Color) *probe.Error {
|
||||
// SetCustomPalette sets a color theme
|
||||
func SetCustomPalette(theme map[string]*color.Color) *probe.Error {
|
||||
privateMutex.Lock()
|
||||
defer privateMutex.Unlock()
|
||||
// add new theme
|
||||
for k, v := range theme {
|
||||
Theme[k] = v
|
||||
Palette[k] = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -29,10 +29,10 @@ type MySuite struct{}
|
||||
|
||||
var _ = Suite(&MySuite{})
|
||||
|
||||
func (s *MySuite) TestSetTheme(c *C) {
|
||||
err := SetCustomTheme(map[string]*color.Color{"unknown": new(color.Color)})
|
||||
func (s *MySuite) TestSetPalette(c *C) {
|
||||
err := SetCustomPalette(map[string]*color.Color{"unknown": new(color.Color)})
|
||||
c.Assert(err, IsNil)
|
||||
_, ok := Theme["unknown"]
|
||||
_, ok := Palette["unknown"]
|
||||
c.Assert(ok, Equals, true)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -170,7 +170,7 @@ func mainSession(ctx *cli.Context) {
|
||||
fatalIf(createSessionDir().Trace(), "Unable to create session directory.")
|
||||
}
|
||||
|
||||
console.SetCustomTheme(map[string]*color.Color{
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Command": color.New(color.FgWhite, color.Bold),
|
||||
"SessionID": color.New(color.FgYellow, color.Bold),
|
||||
"SessionTime": color.New(color.FgGreen),
|
||||
|
||||
+1
-1
@@ -134,7 +134,7 @@ func mainShare(ctx *cli.Context) {
|
||||
fatalIf(createSharedURLsDataFile().Trace(), "Unable to create shared URL data file ‘"+shareFile+"’.")
|
||||
}
|
||||
|
||||
console.SetCustomTheme(map[string]*color.Color{
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Share": color.New(color.FgGreen, color.Bold),
|
||||
"Expires": color.New(color.FgRed, color.Bold),
|
||||
"URL": color.New(color.FgCyan, color.Bold),
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ func checkUpdateSyntax(ctx *cli.Context) {
|
||||
func mainUpdate(ctx *cli.Context) {
|
||||
checkUpdateSyntax(ctx)
|
||||
|
||||
console.SetCustomTheme(map[string]*color.Color{
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"UpdateMessage": color.New(color.FgGreen, color.Bold),
|
||||
})
|
||||
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ func mainVersion(ctx *cli.Context) {
|
||||
if ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "version", 1) // last argument is exit code
|
||||
}
|
||||
console.SetCustomTheme(map[string]*color.Color{
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Version": color.New(color.FgGreen, color.Bold),
|
||||
})
|
||||
if globalJSONFlag {
|
||||
|
||||
Reference in New Issue
Block a user