mirror of
https://github.com/taigrr/wtf
synced 2026-04-02 03:38:52 -07:00
Vendor dependencies using golang/dep
Output from 'dep status': PROJECT CONSTRAINT VERSION REVISION LATEST PKGS USED cloud.google.com/go v0.23.0 v0.23.0 0fd7230 v0.23.0 1 github.com/briandowns/openweathermap ^0.11.0 0.11 1b87579 0.11 1 github.com/gdamore/encoding branch master branch master b23993c b23993c 1 github.com/gdamore/tcell ^1.0.0 v1.0.0 061d51a v1.0.0 2 github.com/go-test/deep ^1.0.1 v1.0.1 6592d9c v1.0.1 1 github.com/golang/protobuf v1.1.0 v1.1.0 b4deda0 v1.1.0 1 github.com/google/go-github branch master branch master 2ae5df7 2ae5df7 1 github.com/google/go-querystring branch master branch master 53e6ce1 53e6ce1 1 github.com/jessevdk/go-flags ^1.4.0 v1.4.0 c6ca198 v1.4.0 1 github.com/lucasb-eyer/go-colorful v1.0 v1.0 345fbb3 v1.0 1 github.com/mattn/go-runewidth v0.0.2 v0.0.2 9e777a8 v0.0.2 1 github.com/olebedev/config branch master branch master 9a10d05 9a10d05 1 github.com/radovskyb/watcher ^1.0.2 v1.0.2 6145e14 v1.0.2 1 github.com/rivo/tview branch master branch master 71ecf1f 71ecf1f 1 github.com/yfronto/newrelic branch master branch master f7fa0c6 f7fa0c6 1 golang.org/x/net branch master branch master 1e49130 1e49130 2 golang.org/x/oauth2 branch master branch master 1e0a3fa 1e0a3fa 5 golang.org/x/text v0.3.0 v0.3.0 f21a4df v0.3.0 5 google.golang.org/api branch master branch master 00e3bb8 00e3bb8 4 google.golang.org/appengine v1.0.0 v1.0.0 150dc57 v1.0.0 10 gopkg.in/yaml.v2 ^2.2.1 v2.2.1 5420a8b v2.2.1 1 See https://golang.github.io/dep/docs/daily-dep.html
This commit is contained in:
137
vendor/github.com/rivo/tview/button.go
generated
vendored
Normal file
137
vendor/github.com/rivo/tview/button.go
generated
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
package tview
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
// Button is labeled box that triggers an action when selected.
|
||||
//
|
||||
// See https://github.com/rivo/tview/wiki/Button for an example.
|
||||
type Button struct {
|
||||
*Box
|
||||
|
||||
// The text to be displayed before the input area.
|
||||
label string
|
||||
|
||||
// The label color.
|
||||
labelColor tcell.Color
|
||||
|
||||
// The label color when the button is in focus.
|
||||
labelColorActivated tcell.Color
|
||||
|
||||
// The background color when the button is in focus.
|
||||
backgroundColorActivated tcell.Color
|
||||
|
||||
// An optional function which is called when the button was selected.
|
||||
selected func()
|
||||
|
||||
// An optional function which is called when the user leaves the button. A
|
||||
// key is provided indicating which key was pressed to leave (tab or backtab).
|
||||
blur func(tcell.Key)
|
||||
}
|
||||
|
||||
// NewButton returns a new input field.
|
||||
func NewButton(label string) *Button {
|
||||
box := NewBox().SetBackgroundColor(Styles.ContrastBackgroundColor)
|
||||
box.SetRect(0, 0, StringWidth(label)+4, 1)
|
||||
return &Button{
|
||||
Box: box,
|
||||
label: label,
|
||||
labelColor: Styles.PrimaryTextColor,
|
||||
labelColorActivated: Styles.InverseTextColor,
|
||||
backgroundColorActivated: Styles.PrimaryTextColor,
|
||||
}
|
||||
}
|
||||
|
||||
// SetLabel sets the button text.
|
||||
func (b *Button) SetLabel(label string) *Button {
|
||||
b.label = label
|
||||
return b
|
||||
}
|
||||
|
||||
// GetLabel returns the button text.
|
||||
func (b *Button) GetLabel() string {
|
||||
return b.label
|
||||
}
|
||||
|
||||
// SetLabelColor sets the color of the button text.
|
||||
func (b *Button) SetLabelColor(color tcell.Color) *Button {
|
||||
b.labelColor = color
|
||||
return b
|
||||
}
|
||||
|
||||
// SetLabelColorActivated sets the color of the button text when the button is
|
||||
// in focus.
|
||||
func (b *Button) SetLabelColorActivated(color tcell.Color) *Button {
|
||||
b.labelColorActivated = color
|
||||
return b
|
||||
}
|
||||
|
||||
// SetBackgroundColorActivated sets the background color of the button text when
|
||||
// the button is in focus.
|
||||
func (b *Button) SetBackgroundColorActivated(color tcell.Color) *Button {
|
||||
b.backgroundColorActivated = color
|
||||
return b
|
||||
}
|
||||
|
||||
// SetSelectedFunc sets a handler which is called when the button was selected.
|
||||
func (b *Button) SetSelectedFunc(handler func()) *Button {
|
||||
b.selected = handler
|
||||
return b
|
||||
}
|
||||
|
||||
// SetBlurFunc sets a handler which is called when the user leaves the button.
|
||||
// The callback function is provided with the key that was pressed, which is one
|
||||
// of the following:
|
||||
//
|
||||
// - KeyEscape: Leaving the button with no specific direction.
|
||||
// - KeyTab: Move to the next field.
|
||||
// - KeyBacktab: Move to the previous field.
|
||||
func (b *Button) SetBlurFunc(handler func(key tcell.Key)) *Button {
|
||||
b.blur = handler
|
||||
return b
|
||||
}
|
||||
|
||||
// Draw draws this primitive onto the screen.
|
||||
func (b *Button) Draw(screen tcell.Screen) {
|
||||
// Draw the box.
|
||||
borderColor := b.borderColor
|
||||
backgroundColor := b.backgroundColor
|
||||
if b.focus.HasFocus() {
|
||||
b.backgroundColor = b.backgroundColorActivated
|
||||
b.borderColor = b.labelColorActivated
|
||||
defer func() {
|
||||
b.borderColor = borderColor
|
||||
}()
|
||||
}
|
||||
b.Box.Draw(screen)
|
||||
b.backgroundColor = backgroundColor
|
||||
|
||||
// Draw label.
|
||||
x, y, width, height := b.GetInnerRect()
|
||||
if width > 0 && height > 0 {
|
||||
y = y + height/2
|
||||
labelColor := b.labelColor
|
||||
if b.focus.HasFocus() {
|
||||
labelColor = b.labelColorActivated
|
||||
}
|
||||
Print(screen, b.label, x, y, width, AlignCenter, labelColor)
|
||||
}
|
||||
}
|
||||
|
||||
// InputHandler returns the handler for this primitive.
|
||||
func (b *Button) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) {
|
||||
return b.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) {
|
||||
// Process key event.
|
||||
switch key := event.Key(); key {
|
||||
case tcell.KeyEnter: // Selected.
|
||||
if b.selected != nil {
|
||||
b.selected()
|
||||
}
|
||||
case tcell.KeyBacktab, tcell.KeyTab, tcell.KeyEscape: // Leave. No action.
|
||||
if b.blur != nil {
|
||||
b.blur(key)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user