diff --git a/ui/ui.go b/ui/ui.go index 930f646..f4f05e5 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -517,18 +517,20 @@ func (p *KeyValue) GetValue() string { } type EditableTextLine struct { - x, y int - h, w int - text string - style tcell.Style - visible bool - cursorPos int + x, y int + h, w int + text string + style tcell.Style + visible bool + cursorPos int + showCursor bool } func NewEditableTextLine(initialText string) *EditableTextLine { return &EditableTextLine{ - text: initialText, - visible: true, + text: initialText, + visible: true, + showCursor: true, } } @@ -547,6 +549,15 @@ func (p *EditableTextLine) Draw(s tcell.Screen) { for j, r := range p.text { s.SetContent(p.x+j, p.y, r, nil, p.style) } + s.ShowCursor(p.x+p.cursorPos, p.y) +} + +func (p *EditableTextLine) SetVisible(b bool) { + p.visible = b +} + +func (p *EditableTextLine) SetCursorVisible(b bool) { + p.showCursor = b } func (p *EditableTextLine) SetText(t string) { @@ -558,6 +569,10 @@ func (p *EditableTextLine) SetText(t string) { p.ResetCursor(false) } +func (p *EditableTextLine) Text() string { + return p.text +} + func (p *EditableTextLine) ResetCursor(beginning bool) { if beginning { p.cursorPos = 0