mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-23 00:38:10 +02:00
Write some tests for the style wrapper
This commit is contained in:
30
tools/utils/style/api.go
Normal file
30
tools/utils/style/api.go
Normal file
@@ -0,0 +1,30 @@
|
||||
// License: GPLv3 Copyright: 2022, Kovid Goyal, <kovid at kovidgoyal.net>
|
||||
|
||||
package style
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Context struct {
|
||||
AllowEscapeCodes bool
|
||||
}
|
||||
|
||||
func (self *Context) SprintFunc(spec string) func(args ...interface{}) string {
|
||||
p := prefix_for_spec(spec)
|
||||
s := suffix_for_spec(spec)
|
||||
|
||||
return func(args ...interface{}) string {
|
||||
body := fmt.Sprint(args...)
|
||||
if !self.AllowEscapeCodes {
|
||||
return body
|
||||
}
|
||||
b := strings.Builder{}
|
||||
b.Grow(len(p) + len(body) + len(s))
|
||||
b.WriteString(p)
|
||||
b.WriteString(body)
|
||||
b.WriteString(s)
|
||||
return b.String()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user