in tui/text_input.go [60:138]
func (p textInput) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
keyTarget := strings.ReplaceAll(p.key, projNewSuffix, "")
// if the intended key for this setting is already set, skip
if p.queue.stack.GetSetting(p.key) != "" ||
p.queue.stack.GetSetting(keyTarget) != "" {
return p.queue.next()
}
switch msg := msg.(type) {
case tea.KeyMsg:
switch keypress := msg.String(); keypress {
case "ctrl+c":
return p.queue.exitPage()
case "alt+b", "ctrl+b":
return p.queue.prev()
case "enter":
val := p.ti.Value()
if val == "" {
val = p.ti.Placeholder
}
// TODO: see if you can figure out a test for these empty bits
if val == "" {
p.err = fmt.Errorf("You must enter a value")
return p, nil
}
p.value = val
// TODO: see if you can figure out a test for these untested bits
if p.postProcessor != nil {
if p.state != "querying" {
p.state = "querying"
p.err = nil
return p, p.postProcessor(p.value, p.queue)
}
return p, nil
}
if !p.omitFromSettings {
p.queue.stack.AddSetting(p.key, p.value)
}
return p.queue.next()
}
// We handle errors just like any other message
case errMsg:
p.err = msg
p.state = "idle"
if msg.quit {
return p, tea.Quit
}
var cmdSpin tea.Cmd
p.spinner, cmdSpin = p.spinner.Update(msg)
return p, cmdSpin
case successMsg:
// Filter project creation screens screeens
newKey := strings.ReplaceAll(p.key, projNewSuffix, "")
newValue := p.value
if msg.msg == "prependProject" {
currentProject := p.queue.Get("currentProject").(string)
newValue = fmt.Sprintf("%s-%s", currentProject, newValue)
}
if !p.omitFromSettings {
p.queue.stack.AddSetting(newKey, newValue)
}
return p.queue.next()
}
var cmdSpin tea.Cmd
p.spinner, cmdSpin = p.spinner.Update(msg)
p.ti, cmd = p.ti.Update(msg)
return p, tea.Batch(cmd, cmdSpin)
}