feat: add dedicated Profile management page
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"proxyctl/internal/app"
|
||||
)
|
||||
|
||||
type confirmationResult uint8
|
||||
|
||||
const (
|
||||
confirmationPending confirmationResult = iota
|
||||
confirmationAccepted
|
||||
confirmationCancelled
|
||||
)
|
||||
|
||||
// confirmationDialog is the reusable safe-default interaction used for
|
||||
// destructive Profile deletion and Application-requested confirmations.
|
||||
// confirmFocused is deliberately false in every new dialog.
|
||||
type confirmationDialog struct {
|
||||
request app.Confirmation
|
||||
confirmFocused bool
|
||||
}
|
||||
|
||||
func newConfirmationDialog(request app.Confirmation) confirmationDialog {
|
||||
return confirmationDialog{request: request}
|
||||
}
|
||||
|
||||
func (d *confirmationDialog) update(key string) confirmationResult {
|
||||
switch key {
|
||||
case "left", "right", "tab", "shift+tab":
|
||||
d.confirmFocused = !d.confirmFocused
|
||||
case "y":
|
||||
return confirmationAccepted
|
||||
case "n", "esc", "q":
|
||||
return confirmationCancelled
|
||||
case "enter":
|
||||
if d.confirmFocused {
|
||||
return confirmationAccepted
|
||||
}
|
||||
return confirmationCancelled
|
||||
}
|
||||
return confirmationPending
|
||||
}
|
||||
|
||||
func (d confirmationDialog) view() string {
|
||||
confirmLabel := d.request.ConfirmLabel
|
||||
if confirmLabel == "" {
|
||||
confirmLabel = "Confirm"
|
||||
}
|
||||
cancelLabel := d.request.CancelLabel
|
||||
if cancelLabel == "" {
|
||||
cancelLabel = "Cancel"
|
||||
}
|
||||
confirm, cancel := " "+confirmLabel, "> "+cancelLabel
|
||||
if d.confirmFocused {
|
||||
confirm, cancel = "> "+confirmLabel, " "+cancelLabel
|
||||
}
|
||||
|
||||
var body strings.Builder
|
||||
body.WriteString(d.request.Title)
|
||||
if d.request.Summary != "" {
|
||||
fmt.Fprintf(&body, "\n%s", d.request.Summary)
|
||||
}
|
||||
for _, detail := range d.request.Details {
|
||||
fmt.Fprintf(&body, "\n• %s", detail)
|
||||
}
|
||||
fmt.Fprintf(&body, "\n\n%s %s", cancel, confirm)
|
||||
return body.String()
|
||||
}
|
||||
Reference in New Issue
Block a user