Skip to content

Commit

Permalink
internal: added faint, reverse and blink styles
Browse files Browse the repository at this point in the history
  • Loading branch information
i582 committed Nov 15, 2020
1 parent 798493d commit d04f689
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ cfmt.Print(`
| ~~crossout~~ |
| <ins>underline</ins> |
| <span style="text-decoration:overline">overline</span> |
|faint|
|reverse|
|blink|


| Colors | | | |
Expand Down
11 changes: 11 additions & 0 deletions internal/bench/bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package bench

import (
"testing"

"github.com/i582/cfmt"
)

func TestParse(t *testing.T) {
cfmt.Println("{{some}}::faint")
}
5 changes: 4 additions & 1 deletion internal/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import (

type styleCallback func(func(string) string) func(string) string

// Map is the custom styles map
// CustomMap is the custom styles map
var CustomMap = map[string]styleCallback{
"overline": overline,
"faint": faint,
"reverse": reverse,
"blink": blink,
}

// Map is the styles map
Expand Down
3 changes: 0 additions & 3 deletions internal/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ func Parse(format string) string {

// ::
if inEndFormatGroup && s == ':' && index+1 < len(format) && format[index+1] == ':' && index+2 < len(format) && format[index+2] != ' ' {
// lastToken = string(tempToken)
// tempToken = nil

inFormatGroup = false
inFormat = true
inText = false
Expand Down
30 changes: 30 additions & 0 deletions internal/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,36 @@ func overline(f func(text string) string) func(text string) string {
}
}

func reverse(f func(text string) string) func(text string) string {
return func(text string) string {
t := f(text)
out := termenv.String(t)
out = out.Reverse()
t = out.String()
return t
}
}

func blink(f func(text string) string) func(text string) string {
return func(text string) string {
t := f(text)
out := termenv.String(t)
out = out.Blink()
t = out.String()
return t
}
}

func faint(f func(text string) string) func(text string) string {
return func(text string) string {
t := f(text)
out := termenv.String(t)
out = out.Faint()
t = out.String()
return t
}
}

func hexForegroundColor(cl string, f func(text string) string) func(text string) string {
return func(text string) string {
t := f(text)
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
//
// It will look like this:
//
// cfmt.RegisterStyle("code", func(s string) string {
// return cfmt.Sprintf("{{%s}}::red|underline", s)
// })
// cfmt.RegisterStyle("code", func(s string) string {
// return cfmt.Sprintf("{{%s}}::red|underline", s)
// })
//
// The first argument is the name by which this style will be used,
// and the second is the styling function itself.
Expand Down

0 comments on commit d04f689

Please sign in to comment.