Config view: Test connections below the service settings; hide a stale cursor
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -262,3 +262,56 @@ func (h *formHeading) Draw(screen tcell.Screen) {
|
||||
x, y, w, _ := h.GetInnerRect()
|
||||
tview.Print(screen, "[::b]"+tview.Escape(h.title)+"[::-]", x, y+1, w, tview.AlignLeft, tcell.ColorYellow)
|
||||
}
|
||||
|
||||
// formAction is a button inside a form's list of fields, so it can sit between
|
||||
// sections instead of at the end. Enter or Space presses it.
|
||||
type formAction struct {
|
||||
*tview.Button
|
||||
labelWidth int
|
||||
finished func(tcell.Key)
|
||||
}
|
||||
|
||||
func newFormAction(label string, pressed func()) *formAction {
|
||||
a := &formAction{Button: tview.NewButton(label)}
|
||||
a.SetSelectedFunc(pressed)
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *formAction) GetLabel() string { return "" } // the button text is its own label
|
||||
|
||||
func (a *formAction) SetFormAttributes(labelWidth int, _, _, _, _ tcell.Color) tview.FormItem {
|
||||
a.labelWidth = labelWidth
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *formAction) GetFieldWidth() int { return tview.TaggedStringWidth(a.GetLabel()) + 4 }
|
||||
|
||||
// GetFieldHeight is 2: an empty line above the button.
|
||||
func (a *formAction) GetFieldHeight() int { return 2 }
|
||||
|
||||
func (a *formAction) SetFinishedFunc(handler func(key tcell.Key)) tview.FormItem {
|
||||
a.SetExitFunc(handler) // Tab, Shift+Tab and Esc
|
||||
a.finished = handler
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *formAction) SetDisabled(disabled bool) tview.FormItem {
|
||||
a.Button.SetDisabled(disabled)
|
||||
return a
|
||||
}
|
||||
|
||||
// SetRect places the button under the field column, one line down, as wide as its text.
|
||||
func (a *formAction) SetRect(x, y, width, height int) {
|
||||
w := min(max(width-a.labelWidth, 0), tview.TaggedStringWidth(a.Button.GetLabel())+4)
|
||||
a.Button.SetRect(x+a.labelWidth, y+1, w, 1)
|
||||
}
|
||||
|
||||
func (a *formAction) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive)) {
|
||||
inner := a.Button.InputHandler()
|
||||
return func(event *tcell.EventKey, setFocus func(p tview.Primitive)) {
|
||||
if event.Key() == tcell.KeyRune && event.Rune() == ' ' {
|
||||
event = tcell.NewEventKey(tcell.KeyEnter, 0, 0)
|
||||
}
|
||||
inner(event, setFocus)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user