129 lines
3.3 KiB
Go
129 lines
3.3 KiB
Go
package tui
|
|
|
|
import tea "github.com/charmbracelet/bubbletea"
|
|
|
|
func (m model) updateStaticForm(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
|
switch msg.String() {
|
|
case "esc":
|
|
m.screen = screenNetwork
|
|
m.formFields = nil
|
|
m.formIndex = 0
|
|
return m, nil
|
|
case "up", "shift+tab":
|
|
if m.formIndex > 0 {
|
|
m.formIndex--
|
|
}
|
|
case "down", "tab":
|
|
if m.formIndex < len(m.formFields)-1 {
|
|
m.formIndex++
|
|
}
|
|
case "enter":
|
|
if m.formIndex < len(m.formFields)-1 {
|
|
m.formIndex++
|
|
return m, nil
|
|
}
|
|
cfg := m.app.ParseStaticIPv4Config(m.selectedIface, []string{
|
|
m.formFields[0].Value,
|
|
m.formFields[1].Value,
|
|
m.formFields[2].Value,
|
|
m.formFields[3].Value,
|
|
})
|
|
m.busy = true
|
|
m.busyTitle = "Static IPv4: " + m.selectedIface
|
|
return m, func() tea.Msg {
|
|
result, err := m.app.SetStaticIPv4Result(cfg)
|
|
return resultMsg{title: result.Title, body: result.Body, err: err, back: screenNetwork}
|
|
}
|
|
case "backspace":
|
|
field := &m.formFields[m.formIndex]
|
|
if len(field.Value) > 0 {
|
|
field.Value = field.Value[:len(field.Value)-1]
|
|
}
|
|
default:
|
|
if msg.Type == tea.KeyRunes && len(msg.Runes) > 0 {
|
|
m.formFields[m.formIndex].Value += string(msg.Runes)
|
|
}
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
func (m model) updateConfirm(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
|
switch msg.String() {
|
|
case "left", "up", "tab":
|
|
if m.cursor > 0 {
|
|
m.cursor--
|
|
}
|
|
case "right", "down":
|
|
if m.cursor < 1 {
|
|
m.cursor++
|
|
}
|
|
case "esc":
|
|
m.screen = m.confirmCancelTarget()
|
|
m.cursor = 0
|
|
m.pendingAction = actionNone
|
|
return m, nil
|
|
case "enter":
|
|
if m.cursor == 1 {
|
|
m.screen = m.confirmCancelTarget()
|
|
m.cursor = 0
|
|
m.pendingAction = actionNone
|
|
return m, nil
|
|
}
|
|
m.busy = true
|
|
switch m.pendingAction {
|
|
case actionExportAudit:
|
|
m.busyTitle = "Export audit"
|
|
target := *m.selectedTarget
|
|
return m, func() tea.Msg {
|
|
result, err := m.app.ExportLatestAuditResult(target)
|
|
return resultMsg{title: result.Title, body: result.Body, err: err, back: screenMain}
|
|
}
|
|
case actionExportBundle:
|
|
m.busyTitle = "Export support bundle"
|
|
target := *m.selectedTarget
|
|
return m, func() tea.Msg {
|
|
result, err := m.app.ExportSupportBundleResult(target)
|
|
return resultMsg{title: result.Title, body: result.Body, err: err, back: screenMain}
|
|
}
|
|
case actionRunNvidiaSAT:
|
|
m.busyTitle = "NVIDIA SAT"
|
|
return m, func() tea.Msg {
|
|
result, err := m.app.RunNvidiaAcceptancePackResult("")
|
|
return resultMsg{title: result.Title, body: result.Body, err: err, back: screenAcceptance}
|
|
}
|
|
case actionRunMemorySAT:
|
|
m.busyTitle = "Memory SAT"
|
|
return m, func() tea.Msg {
|
|
result, err := m.app.RunMemoryAcceptancePackResult("")
|
|
return resultMsg{title: result.Title, body: result.Body, err: err, back: screenAcceptance}
|
|
}
|
|
case actionRunStorageSAT:
|
|
m.busyTitle = "Storage SAT"
|
|
return m, func() tea.Msg {
|
|
result, err := m.app.RunStorageAcceptancePackResult("")
|
|
return resultMsg{title: result.Title, body: result.Body, err: err, back: screenAcceptance}
|
|
}
|
|
}
|
|
case "ctrl+c":
|
|
return m, tea.Quit
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
func (m model) confirmCancelTarget() screen {
|
|
switch m.pendingAction {
|
|
case actionExportAudit:
|
|
return screenExportTargets
|
|
case actionExportBundle:
|
|
return screenExportTargets
|
|
case actionRunNvidiaSAT:
|
|
fallthrough
|
|
case actionRunMemorySAT:
|
|
fallthrough
|
|
case actionRunStorageSAT:
|
|
return screenAcceptance
|
|
default:
|
|
return screenMain
|
|
}
|
|
}
|