Merge mature Profile editor with contextual Help
This commit is contained in:
+42
-16
@@ -221,23 +221,46 @@ func (p terminalPresentation) formView(model presentationState) terminalPage {
|
||||
if model.form.originalName != "" {
|
||||
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)
|
||||
}
|
||||
var fields, bypassPreview strings.Builder
|
||||
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()
|
||||
bypassPreview.WriteString("Normalized Bypass preview:")
|
||||
if len(analysis) == 0 {
|
||||
bypassPreview.WriteString(" (none)")
|
||||
} else {
|
||||
for _, line := range analysis {
|
||||
bypassPreview.WriteString("\n " + line)
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(&fields, "%s%s: %s", cursor, label, value)
|
||||
}
|
||||
secondaryHints := "?: help q/Esc: cancel"
|
||||
if model.form.profile.Mode == profile.SingleMode && model.form.field == 1 {
|
||||
if model.form.currentField() == profile.BypassField {
|
||||
secondaryHints = "PgUp/PgDn: scroll form preview " + secondaryHints
|
||||
}
|
||||
if model.form.profile.Mode == profile.SingleMode && model.form.currentField() == profile.SingleURLField {
|
||||
probeHint := "Ctrl+D: probe"
|
||||
if model.form.probing {
|
||||
probeHint = "Protocol Probe in progress"
|
||||
@@ -246,9 +269,12 @@ func (p terminalPresentation) formView(model presentationState) terminalPage {
|
||||
}
|
||||
footer := "Tab/Shift+Tab/↑/↓: move Ctrl+T: mode Ctrl+S: save\n" + secondaryHints
|
||||
return terminalPage{
|
||||
header: p.theme.title.Render(fmt.Sprintf("%s Proxy Profile — %s mode", action, model.form.profile.Mode)),
|
||||
primary: fields.String(),
|
||||
footer: footer,
|
||||
focusLine: model.form.field,
|
||||
header: p.theme.title.Render(fmt.Sprintf("%s Proxy Profile — %s mode", action, model.form.profile.Mode)),
|
||||
primary: fields.String(),
|
||||
context: bypassPreview.String(),
|
||||
footer: footer,
|
||||
focusLine: focusLine,
|
||||
contextAnchor: model.form.bypassPreviewLine,
|
||||
anchorContext: true,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user