mirror of https://github.com/cheat/cheat.git
feat(display): add methods to `display`
- Add `indent`, `faint`, and `underline` methods to `display` - Add tests for the above
This commit is contained in:
parent
367673d5d9
commit
aa16f68620
|
@ -0,0 +1,8 @@
|
|||
package display
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Faint returns an faint string
|
||||
func Faint(str string) string {
|
||||
return fmt.Sprintf(fmt.Sprintf("\033[2m%s\033[0m", str))
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package display
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestFaint asserts that Faint applies faint formatting
|
||||
func TestFaint(t *testing.T) {
|
||||
want := "\033[2mfoo\033[0m"
|
||||
got := Faint("foo")
|
||||
if want != got {
|
||||
t.Errorf("failed to faint: want: %s, got: %s", want, got)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package display
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Indent prepends each line of a string with a tab
|
||||
func Indent(str string) string {
|
||||
out := ""
|
||||
for _, line := range strings.Split(str, "\n") {
|
||||
out += fmt.Sprintf("\t%s\n", line)
|
||||
}
|
||||
|
||||
return strings.TrimSuffix(out, "\n")
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package display
|
||||
|
||||
import "testing"
|
||||
|
||||
// TestIndent asserts that Indent prepends a tab to each line
|
||||
func TestIndent(t *testing.T) {
|
||||
got := Indent("foo\nbar\nbaz")
|
||||
want := "\tfoo\n\tbar\n\tbaz"
|
||||
if got != want {
|
||||
t.Errorf("failed to indent: want: %s, got: %s", want, got)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package display
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Underline returns an underlined string
|
||||
func Underline(str string) string {
|
||||
return fmt.Sprintf(fmt.Sprintf("\033[4m%s\033[0m", str))
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package display
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestUnderline asserts that Underline applies underline formatting
|
||||
func TestUnderline(t *testing.T) {
|
||||
want := "\033[4mfoo\033[0m"
|
||||
got := Underline("foo")
|
||||
if want != got {
|
||||
t.Errorf("failed to underline: want: %s, got: %s", want, got)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue