1
0
mirror of https://github.com/br0xen/termbox-util.git synced 2024-11-25 23:03:13 +00:00

Remove the 'Active' flag... I didn't like it

This commit is contained in:
Brian Buller 2016-02-19 08:51:24 -06:00
parent 062c970c0d
commit c3e595e205
12 changed files with 102 additions and 232 deletions

View File

@ -19,7 +19,6 @@ type AlertModal struct {
isVisible bool
bordered bool
tabSkip bool
active bool
}
// CreateAlertModal Creates a confirmation modal with the specified attributes
@ -177,22 +176,12 @@ func (i *AlertModal) Clear() {
i.isDone = false
}
// SetActiveFlag sets this control's active flag
func (i *AlertModal) SetActiveFlag(b bool) {
i.active = b
}
// IsActive returns whether this control is active
func (i *AlertModal) IsActive() bool { return i.active }
// HandleEvent handles the termbox event and returns whether it was consumed
func (i *AlertModal) HandleEvent(event termbox.Event) bool {
if !i.active {
if event.Key == termbox.KeyEnter {
i.isDone = true
return true
}
}
return false
}

View File

@ -14,7 +14,6 @@ type ASCIIArt struct {
bg, fg termbox.Attribute
bordered bool
tabSkip bool
active bool
}
// CreateASCIIArt Create an ASCII art object from a string slice
@ -23,14 +22,6 @@ func CreateASCIIArt(c []string, x, y int, fg, bg termbox.Attribute) *ASCIIArt {
return &i
}
// SetActiveFlag sets this control's active flag
func (i *ASCIIArt) SetActiveFlag(b bool) {
i.active = b
}
// IsActive returns whether this control is active
func (i *ASCIIArt) IsActive() bool { return i.active }
// GetID returns this control's ID
func (i *ASCIIArt) GetID() string { return i.id }

View File

@ -19,7 +19,6 @@ type ConfirmModal struct {
isVisible bool
bordered bool
tabSkip bool
active bool
}
// CreateConfirmModal Creates a confirmation modal with the specified attributes
@ -32,14 +31,6 @@ func CreateConfirmModal(title string, x, y, width, height int, fg, bg termbox.At
return &i
}
// SetActiveFlag sets this control's active flag
func (i *ConfirmModal) SetActiveFlag(b bool) {
i.active = b
}
// IsActive returns whether this control is active
func (i *ConfirmModal) IsActive() bool { return i.active }
// GetID returns this control's ID
func (i *ConfirmModal) GetID() string { return i.id }
@ -171,7 +162,6 @@ func (i *ConfirmModal) SetTabSkip(b bool) {
// HandleEvent handles the termbox event and returns whether it was consumed
func (i *ConfirmModal) HandleEvent(event termbox.Event) bool {
if i.active {
if event.Ch == 'Y' || event.Ch == 'y' {
i.accepted = true
i.isDone = true
@ -181,7 +171,6 @@ func (i *ConfirmModal) HandleEvent(event termbox.Event) bool {
i.isDone = true
return true
}
}
return false
}

View File

@ -14,7 +14,6 @@ type DropMenu struct {
showMenu bool
bordered bool
tabSkip bool
active bool
}
// CreateDropMenu Creates a menu with the specified attributes
@ -125,16 +124,6 @@ func (i *DropMenu) SetTabSkip(b bool) {
i.tabSkip = b
}
// SetActiveFlag sets the dropmenu active flag
func (i *DropMenu) SetActiveFlag(b bool) {
i.active = b
}
// IsActive returns whether the DropMenu is active
func (i *DropMenu) IsActive() bool {
return i.active
}
// ShowMenu tells the menu to draw the options
func (i *DropMenu) ShowMenu() {
i.showMenu = true
@ -149,7 +138,6 @@ func (i *DropMenu) HideMenu() {
// HandleEvent handles the termbox event and returns whether it was consumed
func (i *DropMenu) HandleEvent(event termbox.Event) bool {
if i.active {
moveUp := (event.Key == termbox.KeyArrowUp || (i.menu.vimMode && event.Ch == 'k'))
moveDown := (event.Key == termbox.KeyArrowDown || (i.menu.vimMode && event.Ch == 'j'))
if i.menuSelected {
@ -168,7 +156,6 @@ func (i *DropMenu) HandleEvent(event termbox.Event) bool {
i.ShowMenu()
return true
}
}
return false
}
@ -176,7 +163,7 @@ func (i *DropMenu) HandleEvent(event termbox.Event) bool {
func (i *DropMenu) Draw() {
// The title
ttlFg, ttlBg := i.fg, i.bg
if i.active && !i.menuSelected {
if !i.menuSelected {
ttlFg, ttlBg = i.selectedFg, i.selectedBg
}
ttlTxt := i.title

View File

@ -12,7 +12,6 @@ type Frame struct {
bordered bool
controls []termboxControl
tabSkip bool
active bool
}
// CreateFrame creates a Frame at x, y that is w by h
@ -21,14 +20,6 @@ func CreateFrame(x, y, w, h int, fg, bg termbox.Attribute) *Frame {
return &s
}
// SetActiveFlag sets this control's active flag
func (i *Frame) SetActiveFlag(b bool) {
i.active = b
}
// IsActive returns whether this control is active
func (i *Frame) IsActive() bool { return i.active }
// GetID returns this control's ID
func (i *Frame) GetID() string { return i.id }
@ -163,15 +154,12 @@ func (i *Frame) GetBottomY() int {
// HandleEvent accepts the termbox event and returns whether it was consumed
func (i *Frame) HandleEvent(event termbox.Event) bool {
if i.active {
if event.Key == termbox.KeyTab {
i.FindNextTabStop()
return true
}
return i.controls[i.tabIdx].HandleEvent(event)
}
return false
}
// FindNextTabStop finds the next control that can be tabbed to
// A return of true means it found a different one than we started on.
@ -184,9 +172,6 @@ func (i *Frame) FindNextTabStop() bool {
break
}
}
for idx := range i.controls {
i.controls[idx].SetActiveFlag(idx == i.tabIdx)
}
return i.tabIdx != startTab
}

View File

@ -9,27 +9,19 @@ type InputField struct {
x, y, width, height int
cursor int
fg, bg termbox.Attribute
cursorFg, cursorBg termbox.Attribute
bordered bool
wrap bool
multiline bool
tabSkip bool
active bool
}
// CreateInputField creates an input field at x, y that is w by h
func CreateInputField(x, y, w, h int, fg, bg termbox.Attribute) *InputField {
i := InputField{x: x, y: y, width: w, height: h, fg: fg, bg: bg, active: true}
i := InputField{x: x, y: y, width: w, height: h, fg: fg, bg: bg, cursorFg: bg, cursorBg: fg}
return &i
}
// SetActiveFlag sets this control's active flag
func (i *InputField) SetActiveFlag(b bool) {
i.active = b
}
// IsActive returns whether this control is active
func (i *InputField) IsActive() bool { return i.active }
// GetID returns this control's ID
func (i *InputField) GetID() string { return i.id }
@ -130,7 +122,6 @@ func (i *InputField) SetMultiline(b bool) {
// HandleEvent accepts the termbox event and returns whether it was consumed
func (i *InputField) HandleEvent(event termbox.Event) bool {
if i.active {
if event.Key == termbox.KeyBackspace || event.Key == termbox.KeyBackspace2 {
if len(i.value) > 0 {
i.value = i.value[:len(i.value)-1]
@ -179,8 +170,6 @@ func (i *InputField) HandleEvent(event termbox.Event) bool {
}
return true
}
return false
}
// Draw outputs the input field on the screen
func (i *InputField) Draw() {
@ -238,11 +227,7 @@ func (i *InputField) Draw() {
y++
x = startX
}
if i.active {
termbox.SetCell(x, y, cursorRune, i.bg, i.fg)
} else {
termbox.SetCell(x, y, cursorRune, i.fg, i.bg)
}
termbox.SetCell(x, y, cursorRune, i.cursorFg, i.cursorBg)
x++
if len(strPt2) > 0 {
lenLeft := maxWidth - len(strPt1) - 1
@ -271,11 +256,7 @@ func (i *InputField) Draw() {
}
}
x, y = DrawStringAtPoint(strPt1, i.x+1, i.y+1, i.fg, i.bg)
if i.active {
termbox.SetCell(x, y, cursorRune, i.bg, i.fg)
} else {
termbox.SetCell(x, y, cursorRune, i.fg, i.bg)
}
termbox.SetCell(x, y, cursorRune, i.cursorFg, i.cursorBg)
DrawStringAtPoint(strPt2, x+1, y, i.fg, i.bg)
}
}

View File

@ -18,7 +18,6 @@ type InputModal struct {
isVisible bool
bordered bool
tabSkip bool
active bool
}
// CreateInputModal Create an input modal with the given attributes
@ -31,14 +30,6 @@ func CreateInputModal(title string, x, y, width, height int, fg, bg termbox.Attr
return &i
}
// SetActiveFlag sets this control's active flag
func (i *InputModal) SetActiveFlag(b bool) {
i.active = b
}
// IsActive returns whether this control is active
func (i *InputModal) IsActive() bool { return i.active }
// GetID returns this control's ID
func (i *InputModal) GetID() string { return i.id }
@ -183,7 +174,6 @@ func (i *InputModal) Clear() {
// HandleEvent Handle the termbox event, return true if it was consumed
func (i *InputModal) HandleEvent(event termbox.Event) bool {
if i.active {
if event.Key == termbox.KeyEnter {
// Done editing
i.isDone = true
@ -191,8 +181,6 @@ func (i *InputModal) HandleEvent(event termbox.Event) bool {
}
return i.input.HandleEvent(event)
}
return false
}
// Draw Draw the modal
func (i *InputModal) Draw() {

View File

@ -12,7 +12,6 @@ type Label struct {
bordered bool
wrap bool
multiline bool
active bool
}
// CreateLabel creates an input field at x, y that is w by h
@ -21,14 +20,6 @@ func CreateLabel(lbl string, x, y, w, h int, fg, bg termbox.Attribute) *Label {
return &i
}
// SetActiveFlag sets this control's active flag
func (i *Label) SetActiveFlag(b bool) {
i.active = b
}
// IsActive returns whether this control is active
func (i *Label) IsActive() bool { return i.active }
// GetID returns this control's ID
func (i *Label) GetID() string { return i.id }

View File

@ -22,7 +22,6 @@ type Menu struct {
bordered bool
vimMode bool
tabSkip bool
active bool
}
// CreateMenu Creates a menu with the specified attributes
@ -250,17 +249,8 @@ func (i *Menu) DisableVimMode() {
i.vimMode = false
}
// SetActiveFlag sets this control's active flag
func (i *Menu) SetActiveFlag(b bool) {
i.active = b
}
// IsActive returns whether this control is active
func (i *Menu) IsActive() bool { return i.active }
// HandleEvent handles the termbox event and returns whether it was consumed
func (i *Menu) HandleEvent(event termbox.Event) bool {
if i.active {
if event.Key == termbox.KeyEnter || event.Key == termbox.KeySpace {
i.isDone = true
return true
@ -283,7 +273,6 @@ func (i *Menu) HandleEvent(event termbox.Event) bool {
if i.GetSelectedIndex() != currentIdx {
return true
}
}
return false
}

View File

@ -18,7 +18,6 @@ type ProgressBar struct {
x, y int
width, height int
bg, fg termbox.Attribute
active bool
}
// CreateProgressBar Create a progress bar object
@ -32,14 +31,6 @@ func CreateProgressBar(tot, x, y int, fg, bg termbox.Attribute) *ProgressBar {
return &i
}
// SetActiveFlag sets this control's active flag
func (i *ProgressBar) SetActiveFlag(b bool) {
i.active = b
}
// IsActive returns whether this control is active
func (i *ProgressBar) IsActive() bool { return i.active }
// GetID returns this control's ID
func (i *ProgressBar) GetID() string { return i.id }

View File

@ -12,7 +12,6 @@ type ScrollFrame struct {
fg, bg termbox.Attribute
bordered bool
controls []termboxControl
active bool
}
// CreateScrollFrame creates Scrolling Frame at x, y that is w by h
@ -21,14 +20,6 @@ func CreateScrollFrame(x, y, w, h int, fg, bg termbox.Attribute) *ScrollFrame {
return &s
}
// SetActiveFlag sets this control's active flag
func (i *ScrollFrame) SetActiveFlag(b bool) {
i.active = b
}
// IsActive returns whether this control is active
func (i *ScrollFrame) IsActive() bool { return i.active }
// GetID returns this control's ID
func (i *ScrollFrame) GetID() string { return i.id }

View File

@ -26,8 +26,6 @@ type termboxControl interface {
SetBordered(bool)
SetTabSkip(bool)
IsTabSkipped() bool
IsActive() bool
SetActiveFlag(bool)
Draw()
}