pi-agent: Implement mature Profile editor
This commit is contained in:
+33
-11
@@ -209,24 +209,46 @@ func (p terminalPresentation) formView(model presentationState) terminalPage {
|
||||
action = "Edit"
|
||||
}
|
||||
var fields strings.Builder
|
||||
for i, label := range model.form.labels() {
|
||||
cursor := " "
|
||||
if i == model.form.field {
|
||||
cursor = "> "
|
||||
}
|
||||
value := model.form.valueAt(i)
|
||||
if label != "Name" && label != "Bypass" {
|
||||
value = profile.ObscureURL(value)
|
||||
}
|
||||
focusLine, currentLine := 0, 0
|
||||
for i, item := range model.form.inputs {
|
||||
if fields.Len() > 0 {
|
||||
fields.WriteByte('\n')
|
||||
currentLine++
|
||||
}
|
||||
cursor, focus := " ", ""
|
||||
if i == model.form.field {
|
||||
cursor, focus = "> ", " [focused]"
|
||||
focusLine = currentLine
|
||||
}
|
||||
fmt.Fprintf(&fields, "%s%s%s: %s", cursor, item.label, focus, model.form.renderedInput(i, model.width))
|
||||
validation := model.form.validationText(i)
|
||||
if item.field == profile.NameField {
|
||||
if conflict := model.form.nameConflict(model.snapshot.Profiles); conflict != "" {
|
||||
validation = conflict
|
||||
}
|
||||
}
|
||||
if validation != "" {
|
||||
fmt.Fprintf(&fields, "\n Error: %s", validation)
|
||||
currentLine++
|
||||
}
|
||||
if item.field == profile.BypassField {
|
||||
analysis := model.form.bypassAnalysis()
|
||||
fields.WriteString("\n Normalized Bypass preview:")
|
||||
currentLine++
|
||||
if len(analysis) == 0 {
|
||||
fields.WriteString(" (none)")
|
||||
} else {
|
||||
for _, line := range analysis {
|
||||
fields.WriteString("\n " + line)
|
||||
currentLine++
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(&fields, "%s%s: %s", cursor, label, value)
|
||||
}
|
||||
return terminalPage{
|
||||
header: p.theme.title.Render(fmt.Sprintf("%s Proxy Profile — %s mode", action, model.form.profile.Mode)),
|
||||
primary: fields.String(),
|
||||
footer: "Tab/↑/↓: move Ctrl+T: toggle Single/Advanced\nCtrl+S: save Ctrl+D: detect protocol Esc: cancel",
|
||||
focusLine: model.form.field,
|
||||
focusLine: focusLine,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user