-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebbfe90
commit 772febf
Showing
4 changed files
with
184 additions
and
37 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
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,76 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
"flag" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
type Config struct { | ||
Colors Colors `json:"colors"` | ||
} | ||
|
||
type Colors struct { | ||
Reset string `json:"reset"` | ||
Black string `json:"black"` | ||
DarkGray string `json:"darkGray"` | ||
Red string `json:"red"` | ||
LightRed string `json:"lightRed"` | ||
Green string `json:"green"` | ||
LightGreen string `json:"lightGreen"` | ||
Brown string `json:"brown"` | ||
Yellow string `json:"yellow"` | ||
Blue string `json:"blue"` | ||
LightBlue string `json:"lightBlue"` | ||
Purple string `json:"purple"` | ||
LightPurple string `json:"lightPurple"` | ||
Cyan string `json:"cyan"` | ||
LightCyan string `json:"lightCyan"` | ||
LightGray string `json:"lightGray"` | ||
White string `json:"white"` | ||
} | ||
|
||
func Get() (Config, error) { | ||
cfg := createDefault() | ||
|
||
cfgPath := flag.String("c", "", "Config location") | ||
flag.Parse() | ||
|
||
if *cfgPath != "" { | ||
data, err := os.ReadFile(*cfgPath) | ||
if err != nil { | ||
return Config{}, fmt.Errorf("read file: %w", err) | ||
} | ||
|
||
if err = json.Unmarshal(data, &cfg); err != nil { | ||
return Config{}, fmt.Errorf("unmarshal: %w", err) | ||
} | ||
} | ||
|
||
return cfg, nil | ||
} | ||
|
||
func createDefault() Config { | ||
return Config{ | ||
Colors: Colors{ | ||
Reset: "\u001B[0m", | ||
Black: "\u001B[0;30m", | ||
DarkGray: "\u001B[1;30m", | ||
Red: "\u001B[0;31m", | ||
LightRed: "\u001B[1;31m", | ||
Green: "\u001B[0;32m", | ||
LightGreen: "\u001B[1;32m", | ||
Brown: "\u001B[0;33m", | ||
Yellow: "\u001B[1;33m", | ||
Blue: "\u001B[0;34m", | ||
LightBlue: "\u001B[1;34m", | ||
Purple: "\u001B[0;35m", | ||
LightPurple: "\u001B[1;35m", | ||
Cyan: "\u001B[0;36m", | ||
LightCyan: "\u001B[1;36m", | ||
LightGray: "\u001B[0;37m", | ||
White: "\u001B[1;37m", | ||
}, | ||
} | ||
} |
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 |
---|---|---|
@@ -1,85 +1,110 @@ | ||
package color | ||
|
||
const ( | ||
reset = "\033[0m" | ||
black = "\033[0;30m" | ||
darkGray = "\033[1;30m" | ||
red = "\033[0;31m" | ||
lightRed = "\033[1;31m" | ||
green = "\033[0;32m" | ||
lightGreen = "\033[1;32m" | ||
brown = "\033[0;33m" | ||
yellow = "\033[1;33m" | ||
blue = "\033[0;34m" | ||
lightBlue = "\033[1;34m" | ||
purple = "\033[0;35m" | ||
lightPurple = "\033[1;35m" | ||
cyan = "\033[0;36m" | ||
lightCyan = "\033[1;36m" | ||
lightGray = "\033[0;37m" | ||
white = "\033[1;37m" | ||
) | ||
type Palette struct { | ||
Reset string | ||
Black string | ||
DarkGray string | ||
Red string | ||
LightRed string | ||
Green string | ||
LightGreen string | ||
Brown string | ||
Yellow string | ||
Blue string | ||
LightBlue string | ||
Purple string | ||
LightPurple string | ||
Cyan string | ||
LightCyan string | ||
LightGray string | ||
White string | ||
} | ||
|
||
//nolint:gochecknoglobals | ||
var palette = Palette{ | ||
Reset: "\u001B[0m", | ||
Black: "\u001B[0;30m", | ||
DarkGray: "\u001B[1;30m", | ||
Red: "\u001B[0;31m", | ||
LightRed: "\u001B[1;31m", | ||
Green: "\u001B[0;32m", | ||
LightGreen: "\u001B[1;32m", | ||
Brown: "\u001B[0;33m", | ||
Yellow: "\u001B[1;33m", | ||
Blue: "\u001B[0;34m", | ||
LightBlue: "\u001B[1;34m", | ||
Purple: "\u001B[0;35m", | ||
LightPurple: "\u001B[1;35m", | ||
Cyan: "\u001B[0;36m", | ||
LightCyan: "\u001B[1;36m", | ||
LightGray: "\u001B[0;37m", | ||
White: "\u001B[1;37m", | ||
} | ||
|
||
func SetPalette(p Palette) { | ||
palette = p | ||
} | ||
|
||
func Black(value string) string { | ||
return black + value + reset | ||
return palette.Black + value + palette.Reset | ||
} | ||
|
||
func DarkGray(value string) string { | ||
return darkGray + value + reset | ||
return palette.DarkGray + value + palette.Reset | ||
} | ||
|
||
func Red(value string) string { | ||
return red + value + reset | ||
return palette.Red + value + palette.Reset | ||
} | ||
|
||
func LightRed(value string) string { | ||
return lightRed + value + reset | ||
return palette.LightRed + value + palette.Reset | ||
} | ||
|
||
func Green(value string) string { | ||
return green + value + reset | ||
return palette.Green + value + palette.Reset | ||
} | ||
|
||
func LightGreen(value string) string { | ||
return lightGreen + value + reset | ||
return palette.LightGreen + value + palette.Reset | ||
} | ||
|
||
func Brown(value string) string { | ||
return brown + value + reset | ||
return palette.Brown + value + palette.Reset | ||
} | ||
|
||
func Yellow(value string) string { | ||
return yellow + value + reset | ||
return palette.Yellow + value + palette.Reset | ||
} | ||
|
||
func Blue(value string) string { | ||
return blue + value + reset | ||
return palette.Blue + value + palette.Reset | ||
} | ||
|
||
func LightBlue(value string) string { | ||
return lightBlue + value + reset | ||
return palette.LightBlue + value + palette.Reset | ||
} | ||
|
||
func Purple(value string) string { | ||
return purple + value + reset | ||
return palette.Purple + value + palette.Reset | ||
} | ||
|
||
func LightPurple(value string) string { | ||
return lightPurple + value + reset | ||
return palette.LightPurple + value + palette.Reset | ||
} | ||
|
||
func Cyan(value string) string { | ||
return cyan + value + reset | ||
return palette.Cyan + value + palette.Reset | ||
} | ||
|
||
func LightCyan(value string) string { | ||
return lightCyan + value + reset | ||
return palette.LightCyan + value + palette.Reset | ||
} | ||
|
||
func LightGray(value string) string { | ||
return lightGray + value + reset | ||
return palette.LightGray + value + palette.Reset | ||
} | ||
|
||
func White(value string) string { | ||
return white + value + reset | ||
return palette.White + value + palette.Reset | ||
} |