mirror of
https://github.com/br0xen/termbox-util.git
synced 2024-11-26 15:13:15 +00:00
Add Show() and Hide()
This commit is contained in:
parent
c5cb0ca9fe
commit
c581974cc0
@ -14,6 +14,7 @@ type ConfirmModal struct {
|
|||||||
is_done bool
|
is_done bool
|
||||||
accepted bool
|
accepted bool
|
||||||
value string
|
value string
|
||||||
|
is_visible bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateConfirmModal(title string, x, y, width, height int, fg, bg termbox.Attribute) *ConfirmModal {
|
func CreateConfirmModal(title string, x, y, width, height int, fg, bg termbox.Attribute) *ConfirmModal {
|
||||||
@ -84,6 +85,15 @@ func (i *ConfirmModal) SetDone(b bool) *ConfirmModal {
|
|||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *ConfirmModal) Show() *ConfirmModal {
|
||||||
|
i.is_visible = true
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
func (i *ConfirmModal) Hide() *ConfirmModal {
|
||||||
|
i.is_visible = false
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
func (i *ConfirmModal) IsAccepted() bool { return i.accepted }
|
func (i *ConfirmModal) IsAccepted() bool { return i.accepted }
|
||||||
|
|
||||||
func (i *ConfirmModal) Clear() *ConfirmModal {
|
func (i *ConfirmModal) Clear() *ConfirmModal {
|
||||||
|
@ -13,6 +13,7 @@ type InputModal struct {
|
|||||||
cursor int
|
cursor int
|
||||||
bg, fg termbox.Attribute
|
bg, fg termbox.Attribute
|
||||||
is_done bool
|
is_done bool
|
||||||
|
is_visible bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateInputModal(title string, x, y, width, height int, fg, bg termbox.Attribute) *InputModal {
|
func CreateInputModal(title string, x, y, width, height int, fg, bg termbox.Attribute) *InputModal {
|
||||||
@ -75,6 +76,16 @@ func (i *InputModal) SetForeground(fg termbox.Attribute) *InputModal {
|
|||||||
i.fg = fg
|
i.fg = fg
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *InputModal) Show() *InputModal {
|
||||||
|
i.is_visible = true
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
func (i *InputModal) Hide() *InputModal {
|
||||||
|
i.is_visible = false
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
func (i *InputModal) SetDone(b bool) *InputModal {
|
func (i *InputModal) SetDone(b bool) *InputModal {
|
||||||
i.is_done = b
|
i.is_done = b
|
||||||
return i
|
return i
|
||||||
@ -94,6 +105,7 @@ func (i *InputModal) Clear() *InputModal {
|
|||||||
i.text = ""
|
i.text = ""
|
||||||
i.input.SetValue("")
|
i.input.SetValue("")
|
||||||
i.is_done = false
|
i.is_done = false
|
||||||
|
i.is_visible = false
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,6 +120,7 @@ func (i *InputModal) HandleKeyPress(event termbox.Event) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *InputModal) Draw() {
|
func (i *InputModal) Draw() {
|
||||||
|
if i.is_visible {
|
||||||
// First blank out the area we'll be putting the modal
|
// First blank out the area we'll be putting the modal
|
||||||
FillWithChar(' ', i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg)
|
FillWithChar(' ', i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg)
|
||||||
// Now draw the border
|
// Now draw the border
|
||||||
@ -134,3 +147,4 @@ func (i *InputModal) Draw() {
|
|||||||
DrawStringAtPoint(help_string, help_x, next_y, i.fg, i.bg)
|
DrawStringAtPoint(help_string, help_x, next_y, i.fg, i.bg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user