-
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.
fix ANSI in cmd; respect NO_COLOR; print version on run
- Loading branch information
1 parent
309bb8e
commit 46aa0f2
Showing
5 changed files
with
144 additions
and
99 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,82 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/danbrakeley/frog/ansi" | ||
) | ||
|
||
type Printer struct { | ||
NoColor bool | ||
} | ||
|
||
func (p Printer) Header(a ...string) { | ||
var s strings.Builder | ||
s.Grow(256) | ||
if !p.NoColor { | ||
s.WriteString(ansi.SGR(ansi.FgBlue)) | ||
} | ||
for _, v := range a { | ||
s.WriteString(v) | ||
} | ||
if !p.NoColor { | ||
s.WriteString(ansi.SGR(ansi.FgReset)) | ||
} | ||
fmt.Println(s.String()) | ||
} | ||
|
||
func (p Printer) Print(a ...any) { | ||
fmt.Print(a...) | ||
} | ||
|
||
func (p Printer) BrightPrintln(msg string) { | ||
var s strings.Builder | ||
s.Grow(256) | ||
if !p.NoColor { | ||
s.WriteString(ansi.SGR(ansi.FgWhite)) | ||
} | ||
s.WriteString(msg) | ||
if !p.NoColor { | ||
s.WriteString(ansi.SGR(ansi.FgReset)) | ||
} | ||
fmt.Println(s.String()) | ||
} | ||
|
||
func (p Printer) Error(prefix string, err error) { | ||
var s strings.Builder | ||
s.Grow(256) | ||
if !p.NoColor { | ||
s.WriteString(ansi.SGR(ansi.FgRed)) | ||
} | ||
s.WriteString(prefix) | ||
s.WriteString(": ") | ||
if !p.NoColor { | ||
s.WriteString(ansi.SGR(ansi.FgYellow)) | ||
} | ||
s.WriteString(err.Error()) | ||
if !p.NoColor { | ||
s.WriteString(ansi.SGR(ansi.FgReset)) | ||
} | ||
fmt.Println(s.String()) | ||
} | ||
|
||
func (p Printer) BrightIPln(info *PublicInfo) { | ||
var s strings.Builder | ||
s.Grow(256) | ||
if !p.NoColor { | ||
s.WriteString(ansi.SGR(ansi.FgWhite)) | ||
} | ||
s.WriteString(info.IP) | ||
s.WriteRune(' ') | ||
if !p.NoColor { | ||
s.WriteString(ansi.SGR(ansi.FgCyan)) | ||
} | ||
s.WriteRune('(') | ||
s.WriteString(info.ISP) | ||
s.WriteRune(')') | ||
if !p.NoColor { | ||
s.WriteString(ansi.SGR(ansi.FgReset)) | ||
} | ||
fmt.Println(s.String()) | ||
} |
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