MCPcopy
hub / github.com/SurgeDM/Surge / submitInputForm

Method submitInputForm

internal/tui/update_input.go:65–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

63}
64
65func (m RootModel) submitInputForm() (tea.Model, tea.Cmd) {
66 inputVal := m.inputs[0].Value()
67 if inputVal == "" {
68 m.blurAllInputs()
69 m.focusedInput = 0
70 m.inputs[0].Focus()
71 return m, nil
72 }
73
74 url, mirrors := parseURLInput(inputVal)
75
76 // Append mirrors from dedicated mirror input
77 if mirrorsVal := m.inputs[1].Value(); mirrorsVal != "" {
78 for _, part := range strings.Split(mirrorsVal, ",") {
79 if cleaned := strings.TrimSpace(part); cleaned != "" {
80 mirrors = append(mirrors, cleaned)
81 }
82 }
83 }
84
85 if url == "" {
86 m.focusedInput = 0
87 m.inputs[0].Focus()
88 return m, nil
89 }
90
91 pathInput := strings.TrimSpace(m.inputs[2].Value())
92 path := pathInput
93 isDefaultPath := m.isDefaultDownloadPath(path)
94 if path == "" {
95 isDefaultPath = true
96 path = m.defaultDownloadPath()
97 }
98 filename := m.inputs[3].Value()
99
100 if d := m.checkForDuplicate(url); d != nil {
101 m.pendingURL = url
102 m.pendingMirrors = mirrors
103 m.pendingHeaders = nil
104 m.pendingPath = path
105 m.pendingIsDefaultPath = isDefaultPath
106 m.pendingFilename = filename
107 m.duplicateInfo = d.Filename
108 m.state = DuplicateWarningState
109 return m, nil
110 }
111
112 m.state = DashboardState
113 m.inputs[0].SetValue("")
114 m.inputs[1].SetValue("")
115 m.inputs[2].SetValue(path) // Keep path for next download
116 m.inputs[3].SetValue("")
117
118 return m.startDownload(url, mirrors, nil, path, isDefaultPath, filename, "")
119}
120
121// parseURLInput splits a comma-separated URL string into a primary URL and mirrors.
122func parseURLInput(input string) (url string, mirrors []string) {

Callers 1

updateInputMethod · 0.95

Calls 6

blurAllInputsMethod · 0.95
isDefaultDownloadPathMethod · 0.95
defaultDownloadPathMethod · 0.95
checkForDuplicateMethod · 0.95
startDownloadMethod · 0.95
parseURLInputFunction · 0.85

Tested by

no test coverage detected