Skip to content

Commit

Permalink
feat(examples): add p/printfdebugging (#2809)
Browse files Browse the repository at this point in the history
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
moul authored Sep 20, 2024
1 parent 1fe3fe7 commit 35152a6
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
81 changes: 81 additions & 0 deletions examples/gno.land/p/moul/printfdebugging/color.gno
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
)
3 changes: 3 additions & 0 deletions examples/gno.land/p/moul/printfdebugging/gno.mod
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 examples/gno.land/p/moul/printfdebugging/printfdebugging.gno
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 ")
}

0 comments on commit 35152a6

Please sign in to comment.