func()

in tui/picker.go [155:251]


func (p picker) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	switch msg := msg.(type) {
	case []list.Item:
		p.state = "displaying"
		items := []list.Item(msg)

		offset := len(p.list.Items())

		for i, v := range items {
			p.list.InsertItem(i+offset, v)
		}

		tmp, selectedIndex := positionDefault(p.list.Items(), p.defaultValue)
		p.list.SetItems(tmp)

		p.list.Select(selectedIndex)

		return p, p.spinner.Tick
	case errMsg:
		p.state = "idle"
		p.err = msg
		p.target = msg.target
		return p, nil
	case successMsg:
		p.state = "idle"
		newValue := p.value
		if msg.msg == "prependProject" {
			currentProject := p.queue.Get("currentProject").(string)
			newValue = fmt.Sprintf("%s-%s", currentProject, newValue)
		}

		if !msg.unset && !p.omitFromSettings {
			p.queue.stack.AddSetting(p.key, newValue)
		}

		return p.queue.next()
	case tea.KeyMsg:
		if p.list.FilterState() == list.Filtering {
			break
		}
		switch keypress := msg.String(); keypress {
		case "alt+b", "ctrl+b":
			return p.queue.prev()
		case "ctrl+c":
			return p.queue.exitPage()
		case "enter":
			if p.state == "displaying" {
				i, ok := p.list.SelectedItem().(item)
				if ok {
					p.value = string(i.value)
				}
				if !p.omitFromSettings {
					p.queue.stack.AddSetting(p.key, p.value)
				}

				if p.postProcessor != nil {
					if p.state != "querying" {
						p.state = "querying"
						p.err = nil

						var cmd tea.Cmd
						var cmdSpin tea.Cmd
						cmd = p.postProcessor(p.value, p.queue)
						p.spinner, cmdSpin = p.spinner.Update(msg)

						return p, tea.Batch(cmd, cmdSpin)
					}

					return p, nil
				}

				return p.queue.next()
			}
			if p.err != nil && p.target != "" {
				p.queue.clear(p.target)
				return p.queue.goToModel(p.target)
			}
		}

	default:
		var cmdList tea.Cmd
		var cmdSpin tea.Cmd
		p.list, cmdList = p.list.Update(msg)
		p.spinner, cmdSpin = p.spinner.Update(msg)
		return p, tea.Batch(cmdSpin, cmdList)
	}

	// If this isn't here, then keyPress events do not get responded to by
	// the list ¯\(°_o)/¯
	if p.state == "displaying" {
		var cmd tea.Cmd
		p.list, cmd = p.list.Update(msg)
		return p, cmd
	}

	return p, nil
}