-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples): add p/printfdebugging (#2809)
Extracted from #2551. See #2551 (comment). <!-- please provide a detailed description of the changes made in this pull request. --> <details><summary>Contributors' checklist...</summary> - [ ] Added new tests, or not needed, or not feasible - [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [ ] Updated the official documentation or not needed - [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [ ] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Signed-off-by: moul <[email protected]>
- Loading branch information
Showing
3 changed files
with
103 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package printfdebugging | ||
|
||
// consts copied from https://github.com/fatih/color/blob/main/color.go | ||
|
||
// Attribute defines a single SGR Code | ||
type Attribute int | ||
|
||
const Escape = "\x1b" | ||
|
||
// Base attributes | ||
const ( | ||
Reset Attribute = iota | ||
Bold | ||
Faint | ||
Italic | ||
Underline | ||
BlinkSlow | ||
BlinkRapid | ||
ReverseVideo | ||
Concealed | ||
CrossedOut | ||
) | ||
|
||
const ( | ||
ResetBold Attribute = iota + 22 | ||
ResetItalic | ||
ResetUnderline | ||
ResetBlinking | ||
_ | ||
ResetReversed | ||
ResetConcealed | ||
ResetCrossedOut | ||
) | ||
|
||
// Foreground text colors | ||
const ( | ||
FgBlack Attribute = iota + 30 | ||
FgRed | ||
FgGreen | ||
FgYellow | ||
FgBlue | ||
FgMagenta | ||
FgCyan | ||
FgWhite | ||
) | ||
|
||
// Foreground Hi-Intensity text colors | ||
const ( | ||
FgHiBlack Attribute = iota + 90 | ||
FgHiRed | ||
FgHiGreen | ||
FgHiYellow | ||
FgHiBlue | ||
FgHiMagenta | ||
FgHiCyan | ||
FgHiWhite | ||
) | ||
|
||
// Background text colors | ||
const ( | ||
BgBlack Attribute = iota + 40 | ||
BgRed | ||
BgGreen | ||
BgYellow | ||
BgBlue | ||
BgMagenta | ||
BgCyan | ||
BgWhite | ||
) | ||
|
||
// Background Hi-Intensity text colors | ||
const ( | ||
BgHiBlack Attribute = iota + 100 | ||
BgHiRed | ||
BgHiGreen | ||
BgHiYellow | ||
BgHiBlue | ||
BgHiMagenta | ||
BgHiCyan | ||
BgHiWhite | ||
) |
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,3 @@ | ||
module gno.land/p/demo/printfdebugging | ||
|
||
require gno.land/p/demo/ufmt v0.0.0-latest |
19 changes: 19 additions & 0 deletions
19
examples/gno.land/p/moul/printfdebugging/printfdebugging.gno
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,19 @@ | ||
// this package is a joke... or not. | ||
package printfdebugging | ||
|
||
import ( | ||
"strings" | ||
|
||
"gno.land/p/demo/ufmt" | ||
) | ||
|
||
func BigRedLine(args ...string) { | ||
println(ufmt.Sprintf("%s[%dm####################################%s[%dm %s", | ||
Escape, int(BgRed), Escape, int(Reset), | ||
strings.Join(args, " "), | ||
)) | ||
} | ||
|
||
func Success() { | ||
println(" \033[31mS\033[33mU\033[32mC\033[36mC\033[34mE\033[35mS\033[31mS\033[0m ") | ||
} |