MCPcopy Create free account
hub / github.com/chip/pathos / Update

Method Update

pathos.go:198–270  ·  view source on GitHub ↗
(msg tea.Msg)

Source from the content-addressed store, hash-verified

196}
197
198func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
199 var cmd tea.Cmd
200 var cmds []tea.Cmd
201
202 switch msg := msg.(type) {
203 case tea.WindowSizeMsg:
204 m.list.SetWidth(msg.Width)
205 return m, nil
206
207 case savePathMsg:
208 m.list.InsertItem(msg.cursor, item(msg.path))
209 duplicatePaths = findDuplicatePaths(m.list.Items())
210 return m, nil
211
212 case deletePathMsg:
213
214 m.list.RemoveItem(int(msg))
215 duplicatePaths = findDuplicatePaths(m.list.Items())
216 return m, nil
217
218 case saveShellSourceMsg:
219 saveShellSource(m)
220 return m, nil
221
222 case tea.KeyMsg:
223 switch {
224
225 case key.Matches(msg, keys.Quit):
226 return m, tea.Quit
227
228 case key.Matches(msg, keys.Enter):
229
230 if m.state == inputView {
231 text := strings.TrimSpace(m.textInput.Value())
232 if text != "" {
233 cursor := m.list.Cursor()
234 value := m.textInput.Value()
235 cmds = append(cmds, savePathCmd(cursor, value))
236 m.state = listView
237 }
238 }
239
240 case key.Matches(msg, keys.NewPath):
241 m.state = inputView
242 return m, nil
243
244 case key.Matches(msg, keys.DeletePath):
245 if m.state == listView {
246 i := m.list.Index()
247 cmds = append(cmds, deletePathCmd(m, i))
248 }
249
250 case key.Matches(msg, keys.SaveShellSource):
251 cmds = append(cmds, saveShellSourceCmd(m))
252
253 }
254
255 // We handle errors just like any other message

Callers

nothing calls this directly

Calls 6

itemTypeAlias · 0.85
findDuplicatePathsFunction · 0.85
saveShellSourceFunction · 0.85
savePathCmdFunction · 0.85
deletePathCmdFunction · 0.85
saveShellSourceCmdFunction · 0.85

Tested by

no test coverage detected