-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtext.go
37 lines (30 loc) · 798 Bytes
/
text.go
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
35
36
37
package glint
import (
"context"
)
// TextComponent is a Component that renders text.
type TextComponent struct {
terminalComponent
f func(rows, cols uint) string
}
// Text creates a TextComponent for static text. The text here will be word
// wrapped automatically based on the width of the terminal.
func Text(v string) *TextComponent {
return TextFunc(func(rows, cols uint) string { return v })
}
// TextFunc creates a TextComponent for text that is dependent on the
// size of the draw area.
func TextFunc(f func(rows, cols uint) string) *TextComponent {
return &TextComponent{
f: f,
}
}
func (el *TextComponent) Body(context.Context) Component {
return nil
}
func (el *TextComponent) Render(rows, cols uint) string {
if el.f == nil {
return ""
}
return el.f(rows, cols)
}