Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed handling of '%' in debugger styled output #260

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 35 additions & 37 deletions debugger/colors/color.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package colors

import (
"fmt"

"github.com/gdamore/tcell/v2"
)

Expand All @@ -12,74 +10,74 @@ const (

var Background = tcell.GetColor("#000000")

type ColorFunc func(format string, args ...any) string
type ColorFunc func(text string) string

// Text extensions
func Bold(format string, args ...any) string {
return fmt.Sprintf("[::b]"+format+"[::-]", args...)
func Bold(text string) string {
return "[::b]" + text + "[::-]"
}

func Underline(format string, args ...any) string {
return fmt.Sprintf("[::u]"+format+"[::-]", args...)
func Underline(text string) string {
return "[::u]" + text + "[::-]"
}

// Text colors
func Black(format string, args ...any) string {
return fmt.Sprintf("[black]"+format+"[white]", args...)
func Black(text string) string {
return "[black]" + text + "[white]"
}

func Maroon(format string, args ...any) string {
return fmt.Sprintf("[maroon]"+format+"[white]", args...)
func Maroon(text string) string {
return "[maroon]" + text + "[white]"
}

func Green(format string, args ...any) string {
return fmt.Sprintf("[green]"+format+"[white]", args...)
func Green(text string) string {
return "[green]" + text + "[white]"
}

func Olive(format string, args ...any) string {
return fmt.Sprintf("[olive]"+format+"[white]", args...)
func Olive(text string) string {
return "[olive]" + text + "[white]"
}

func Navy(format string, args ...any) string {
return fmt.Sprintf("[navy]"+format+"[white]", args...)
func Navy(text string) string {
return "[navy]" + text + "[white]"
}

func Purple(format string, args ...any) string {
return fmt.Sprintf("[purple]"+format+"[white]", args...)
func Purple(text string) string {
return "[purple]" + text + "[white]"
}

func Teal(format string, args ...any) string {
return fmt.Sprintf("[teal]"+format+"[white]", args...)
func Teal(text string) string {
return "[teal]" + text + "[white]"
}

func Silver(format string, args ...any) string {
return fmt.Sprintf("[silver]"+format+"[white]", args...)
func Silver(text string) string {
return "[silver]" + text + "[white]"
}

func Gray(format string, args ...any) string {
return fmt.Sprintf("[gray]"+format+"[white]", args...)
func Gray(text string) string {
return "[gray]" + text + "[white]"
}

func Red(format string, args ...any) string {
return fmt.Sprintf("[red]"+format+"[white]", args...)
func Red(text string) string {
return "[red]" + text + "[white]"
}

func Lime(format string, args ...any) string {
return fmt.Sprintf("[lime]"+format+"[white]", args...)
func Lime(text string) string {
return "[lime]" + text + "[white]"
}

func Yellow(format string, args ...any) string {
return fmt.Sprintf("[yellow]"+format+"[white]", args...)
func Yellow(text string) string {
return "[yellow]" + text + "[white]"
}

func Blue(format string, args ...any) string {
return fmt.Sprintf("[blue]"+format+"[white]", args...)
func Blue(text string) string {
return "[blue]" + text + "[white]"
}

func Fuchsia(format string, args ...any) string {
return fmt.Sprintf("[fuchsia]"+format+"[white]", args...)
func Fuchsia(text string) string {
return "[fuchsia]" + text + "[white]"
}

func Aqua(format string, args ...any) string {
return fmt.Sprintf("[aqua]"+format+"[white]", args...)
func Aqua(text string) string {
return "[aqua]" + text + "[white]"
}
38 changes: 19 additions & 19 deletions debugger/colors/color_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ func TestColorString(t *testing.T) {
text string
expect string
}{
{color: Black, text: "foo", expect: "[black]foo[white]"},
{color: Maroon, text: "foo", expect: "[maroon]foo[white]"},
{color: Green, text: "foo", expect: "[green]foo[white]"},
{color: Olive, text: "foo", expect: "[olive]foo[white]"},
{color: Navy, text: "foo", expect: "[navy]foo[white]"},
{color: Purple, text: "foo", expect: "[purple]foo[white]"},
{color: Teal, text: "foo", expect: "[teal]foo[white]"},
{color: Silver, text: "foo", expect: "[silver]foo[white]"},
{color: Gray, text: "foo", expect: "[gray]foo[white]"},
{color: Red, text: "foo", expect: "[red]foo[white]"},
{color: Lime, text: "foo", expect: "[lime]foo[white]"},
{color: Yellow, text: "foo", expect: "[yellow]foo[white]"},
{color: Blue, text: "foo", expect: "[blue]foo[white]"},
{color: Fuchsia, text: "foo", expect: "[fuchsia]foo[white]"},
{color: Aqua, text: "foo", expect: "[aqua]foo[white]"},
{color: Black, text: "foo%bar", expect: "[black]foo%bar[white]"},
{color: Maroon, text: "foo%bar", expect: "[maroon]foo%bar[white]"},
{color: Green, text: "foo%bar", expect: "[green]foo%bar[white]"},
{color: Olive, text: "foo%bar", expect: "[olive]foo%bar[white]"},
{color: Navy, text: "foo%bar", expect: "[navy]foo%bar[white]"},
{color: Purple, text: "foo%bar", expect: "[purple]foo%bar[white]"},
{color: Teal, text: "foo%bar", expect: "[teal]foo%bar[white]"},
{color: Silver, text: "foo%bar", expect: "[silver]foo%bar[white]"},
{color: Gray, text: "foo%bar", expect: "[gray]foo%bar[white]"},
{color: Red, text: "foo%bar", expect: "[red]foo%bar[white]"},
{color: Lime, text: "foo%bar", expect: "[lime]foo%bar[white]"},
{color: Yellow, text: "foo%bar", expect: "[yellow]foo%bar[white]"},
{color: Blue, text: "foo%bar", expect: "[blue]foo%bar[white]"},
{color: Fuchsia, text: "foo%bar", expect: "[fuchsia]foo%bar[white]"},
{color: Aqua, text: "foo%bar", expect: "[aqua]foo%bar[white]"},
}

for i := range tests {
Expand All @@ -39,14 +39,14 @@ func TestStyledColor(t *testing.T) {
colors []ColorFunc
expect string
}{
{colors: []ColorFunc{Black, Bold}, expect: "[::b][black]foo[white][::-]"},
{colors: []ColorFunc{Black, Underline}, expect: "[::u][black]foo[white][::-]"},
{colors: []ColorFunc{Black, Bold, Underline}, expect: "[::u][::b][black]foo[white][::-][::-]"},
{colors: []ColorFunc{Black, Bold}, expect: "[::b][black]foo%bar[white][::-]"},
{colors: []ColorFunc{Black, Underline}, expect: "[::u][black]foo%bar[white][::-]"},
{colors: []ColorFunc{Black, Bold, Underline}, expect: "[::u][::b][black]foo%bar[white][::-][::-]"},
}

for i := range tests {
tt := tests[i]
actual := "foo"
actual := "foo%bar"
for _, c := range tt.colors {
actual = c(actual)
}
Expand Down
Loading