-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide Go API by separating CLI from library (#6)
This commit splits tandem into a Go package and a CLI, letting users import the package and use it in their own Go programs. Fixes #5
- Loading branch information
1 parent
141ee97
commit 524b1e0
Showing
6 changed files
with
163 additions
and
57 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,57 @@ | ||
// Package ansi provides ANSI escape codes for color and formatting. | ||
package ansi | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
// NoColor disables ANSI color output. By default it is set to true if the | ||
// NO_COLOR environment variable is set. | ||
var NoColor = os.Getenv("NO_COLOR") != "" | ||
|
||
// Red returns a string wrapped in ANSI escape codes to make it red. | ||
func Red(s string) string { | ||
if NoColor { | ||
return s | ||
} | ||
return "\033[0;31m" + s + "\033[0m" | ||
} | ||
|
||
// Gray returns a string wrapped in ANSI escape codes to make it gray. | ||
func Gray(s string) string { | ||
if NoColor { | ||
return s | ||
} | ||
return "\033[0;38;5;8m" + s + "\033[0m" | ||
} | ||
|
||
// Dim returns a string wrapped in ANSI escape codes to make it dim. | ||
func Dim(s string) string { | ||
if NoColor { | ||
return s | ||
} | ||
return "\033[0;2m" + s + "\033[0m" | ||
} | ||
|
||
// Bold returns a string wrapped in ANSI escape codes to make it bold. | ||
func Bold(s string) string { | ||
if NoColor { | ||
return s | ||
} | ||
return "\033[1m" + s + "\033[0m" | ||
} | ||
|
||
func ColorStart(i int) string { | ||
if NoColor { | ||
return "" | ||
} | ||
return fmt.Sprintf("\033[0;38;5;%vm", i) | ||
} | ||
|
||
func ColorEnd() string { | ||
if NoColor { | ||
return "" | ||
} | ||
return "\033[0m" | ||
} |
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
Oops, something went wrong.