mirror of
https://github.com/cheat/cheat.git
synced 2024-11-21 13:31:36 +01:00
feat(display): make Faint
respect Colorize
Make `display.Faint` respect the `Colorize` config value.
This commit is contained in:
parent
cdddfbb516
commit
1a7b5c6127
@ -77,7 +77,7 @@ func cmdSearch(opts map[string]interface{}, conf config.Config) {
|
||||
// display the cheatsheet title and path
|
||||
out += fmt.Sprintf("\n%s %s\n",
|
||||
display.Underline(sheet.Title),
|
||||
display.Faint(fmt.Sprintf("(%s)", sheet.CheatPath)),
|
||||
display.Faint(fmt.Sprintf("(%s)", sheet.CheatPath), conf),
|
||||
)
|
||||
|
||||
// indent each line of content
|
||||
|
@ -41,7 +41,7 @@ func cmdView(opts map[string]interface{}, conf config.Config) {
|
||||
// identify the matching cheatsheet
|
||||
fmt.Println(fmt.Sprintf("%s %s",
|
||||
display.Underline(sheet.Title),
|
||||
display.Faint(fmt.Sprintf("(%s)", sheet.CheatPath)),
|
||||
display.Faint(fmt.Sprintf("(%s)", sheet.CheatPath), conf),
|
||||
))
|
||||
|
||||
// apply colorization if requested
|
||||
|
@ -1,8 +1,18 @@
|
||||
package display
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cheat/cheat/internal/config"
|
||||
)
|
||||
|
||||
// Faint returns an faint string
|
||||
func Faint(str string) string {
|
||||
return fmt.Sprintf(fmt.Sprintf("\033[2m%s\033[0m", str))
|
||||
func Faint(str string, conf config.Config) string {
|
||||
// make `str` faint only if colorization has been requested
|
||||
if conf.Colorize {
|
||||
return fmt.Sprintf(fmt.Sprintf("\033[2m%s\033[0m", str))
|
||||
}
|
||||
|
||||
// otherwise, return the string unmodified
|
||||
return str
|
||||
}
|
||||
|
@ -2,12 +2,25 @@ package display
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cheat/cheat/internal/config"
|
||||
)
|
||||
|
||||
// TestFaint asserts that Faint applies faint formatting
|
||||
func TestFaint(t *testing.T) {
|
||||
|
||||
// case: apply colorization
|
||||
conf := config.Config{Colorize: true}
|
||||
want := "\033[2mfoo\033[0m"
|
||||
got := Faint("foo")
|
||||
got := Faint("foo", conf)
|
||||
if want != got {
|
||||
t.Errorf("failed to faint: want: %s, got: %s", want, got)
|
||||
}
|
||||
|
||||
// case: do not apply colorization
|
||||
conf.Colorize = false
|
||||
want = "foo"
|
||||
got = Faint("foo", conf)
|
||||
if want != got {
|
||||
t.Errorf("failed to faint: want: %s, got: %s", want, got)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user