File: meta.go

package info (click to toggle)
golang-github-vbauerster-mpb 8.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,044 kB
  • sloc: sh: 7; makefile: 3
file content (34 lines) | stat: -rw-r--r-- 757 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package decor

var (
	_ Decorator = metaWrapper{}
	_ Wrapper   = metaWrapper{}
)

// Meta wrap decorator.
// Provided fn is supposed to wrap output of given decorator
// with meta information like ANSI escape codes for example.
// Primary usage intention is to set SGR display attributes.
//
//	`decorator` Decorator to wrap
//	`fn` func to apply meta information
func Meta(decorator Decorator, fn func(string) string) Decorator {
	if decorator == nil {
		return nil
	}
	return metaWrapper{decorator, fn}
}

type metaWrapper struct {
	Decorator
	fn func(string) string
}

func (d metaWrapper) Decor(s Statistics) (string, int) {
	str, width := d.Decorator.Decor(s)
	return d.fn(str), width
}

func (d metaWrapper) Unwrap() Decorator {
	return d.Decorator
}