summary refs log tree commit diff stats
path: root/config/bindings_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'config/bindings_test.go')
0 files changed, 0 insertions, 0 deletions
/ui/text.go?h=0.6.0&id=05ec7357541bcc21dab041da01aec541f6c33cab'>05ec735 ^
5685a17 ^






05ec735 ^


dee0f89 ^




05ec735 ^













fa04a1e ^





80e891a ^
05ec735 ^





84965d6 ^





05ec735 ^

05ec735 ^






80e891a ^
fa04a1e ^


84965d6 ^


80e891a ^
6811143 ^
05ec735 ^

05ec735 ^
5685a17 ^
05ec735 ^
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85


          
                                  
                                       








                          






                            


                                 




                                         













                                              





                                      
                                                            





                      





                                            

                                             






                                            
                                                                     


                                        


                                           
                                                             
                                             

 
                             
                         
 
package ui

import (
	"github.com/gdamore/tcell"
	"github.com/mattn/go-runewidth"
)

const (
	TEXT_LEFT   = iota
	TEXT_CENTER = iota
	TEXT_RIGHT  = iota
)

type Text struct {
	Invalidatable
	text     string
	strategy uint
	fg       tcell.Color
	bg       tcell.Color
	bold     bool
	reverse  bool
}

func NewText(text string) *Text {
	return &Text{
		bg:   tcell.ColorDefault,
		fg:   tcell.ColorDefault,
		text: text,
	}
}

func (t *Text) Text(text string) *Text {
	t.text = text
	t.Invalidate()
	return t
}

func (t *Text) Strategy(strategy uint) *Text {
	t.strategy = strategy
	t.Invalidate()
	return t
}

func (t *Text) Bold(bold bool) *Text {
	t.bold = bold
	t.Invalidate()
	return t
}

func (t *Text) Color(fg tcell.Color, bg tcell.Color) *Text {
	t.fg = fg
	t.bg = bg
	t.Invalidate()
	return t
}

func (t *Text) Reverse(reverse bool) *Text {
	t.reverse = reverse
	t.Invalidate()
	return t
}

func (t *Text) Draw(ctx *Context) {
	size := runewidth.StringWidth(t.text)
	x := 0
	if t.strategy == TEXT_CENTER {
		x = (ctx.Width() - size) / 2
	}
	if t.strategy == TEXT_RIGHT {
		x = ctx.Width() - size
	}
	style := tcell.StyleDefault.Background(t.bg).Foreground(t.fg)
	if t.bold {
		style = style.Bold(true)
	}
	if t.reverse {
		style = style.Reverse(true)
	}
	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', style)
	ctx.Printf(x, 0, style, "%s", t.text)
}

func (t *Text) Invalidate() {
	t.DoInvalidate(t)
}