package tui import ( "fmt" "strings" "charm.land/bubbles/v2/list" "charm.land/bubbles/v2/textinput" tea "charm.land/bubbletea/v2" "gitgud.io/mike/mpv-manager/pkg/config" ) // setupInstallPathList builds the custom install path menu func (m *Model) setupInstallPathList() { items := []list.Item{ menuItem{ id: "edit-install-path", title: "✏️ Edit Custom Install Path", description: "Current: " + config.GetInstallPath(), recommended: false, }, menuItem{ id: "reset-install-path", title: "↩️ Reset to Default Install Path", description: "Clear the custom path and use the platform default", recommended: false, }, } m.installPathList = m.createStyledList("Custom Install Path", items) } // handleInstallPathUpdate handles the custom install path menu state func (m *Model) handleInstallPathUpdate(msg tea.Msg) (*Model, tea.Cmd) { var cmd tea.Cmd switch msg := msg.(type) { case tea.KeyPressMsg: switch keyCode(msg) { case tea.KeyEsc: m.setupConfigOptionsList() m.state = StateConfigOptions return m, nil case tea.KeyEnter: selected := m.installPathList.SelectedItem() if selected != nil { item := selected.(menuItem) switch item.id { case "edit-install-path": ti := textinput.New() ti.Placeholder = "Enter absolute install path..." ti.SetValue(config.GetInstallPath()) ti.CharLimit = 256 ti.SetWidth(50) ti.Focus() m.installPathTextInput = ti m.installPathStatusMsg = "" m.state = StateInstallPathEdit return m, nil case "reset-install-path": if err := config.ClearInstallPath(); err != nil { m.installPathStatusMsg = "✗ Failed to save install path: " + err.Error() return m, nil } m.installPathStatusMsg = "✓ Install path reset to default: " + config.GetInstallPath() m.setupInstallPathList() return m, nil } } } } m.installPathList, cmd = m.installPathList.Update(msg) return m, cmd } // handleInstallPathEditUpdate handles the custom install path text input state func (m *Model) handleInstallPathEditUpdate(msg tea.Msg) (*Model, tea.Cmd) { var tiCmd tea.Cmd m.installPathTextInput, tiCmd = m.installPathTextInput.Update(msg) switch msg := msg.(type) { case tea.KeyPressMsg: switch keyCode(msg) { case tea.KeyEsc: m.installPathStatusMsg = "" m.state = StateInstallPath return m, nil case tea.KeyEnter: path := strings.TrimSpace(m.installPathTextInput.Value()) if err := config.ValidateCustomInstallPath(path); err != nil { m.installPathStatusMsg = fmt.Sprintf("✗ %v", err) return m, nil } if err := config.SetInstallPath(path); err != nil { m.installPathStatusMsg = "✗ Failed to save install path: " + err.Error() return m, nil } m.installPathStatusMsg = "✓ Install path set to: " + path m.setupInstallPathList() m.state = StateInstallPath return m, nil } } return m, tiCmd } // installPathView renders the custom install path menu func (m Model) installPathView() string { var content strings.Builder content.WriteString(titleStyle.Render("📁 Custom Install Path")) content.WriteString("\n") content.WriteString(subtitleStyle.Render("══════════════════════")) content.WriteString("\n\n") content.WriteString(infoStyle.Render("MPV binaries will be installed to:")) content.WriteString("\n") content.WriteString(subtitleStyle.Render(" " + config.GetInstallPath())) content.WriteString("\n\n") if m.installPathStatusMsg != "" { if strings.HasPrefix(m.installPathStatusMsg, "✓") { content.WriteString(successStyle.Render(m.installPathStatusMsg)) } else { content.WriteString(errorStyle.Render(m.installPathStatusMsg)) } content.WriteString("\n\n") } content.WriteString(m.installPathList.View()) content.WriteString("\n\n") content.WriteString(infoStyle.Render("Press ")) content.WriteString(subtitleStyle.Render("Enter")) content.WriteString(infoStyle.Render(" to select, ")) content.WriteString(subtitleStyle.Render("Esc")) content.WriteString(infoStyle.Render(" to go back")) return content.String() } // installPathEditView renders the custom install path text input func (m Model) installPathEditView() string { var content strings.Builder content.WriteString(titleStyle.Render("Edit Custom Install Path")) content.WriteString("\n") content.WriteString(subtitleStyle.Render("══════════════════════")) content.WriteString("\n\n") content.WriteString(m.installPathTextInput.View()) content.WriteString("\n\n") if m.installPathStatusMsg != "" { content.WriteString(errorStyle.Render(m.installPathStatusMsg)) content.WriteString("\n\n") } content.WriteString(infoStyle.Render("Press ")) content.WriteString(subtitleStyle.Render("Enter")) content.WriteString(infoStyle.Render(" to save, ")) content.WriteString(subtitleStyle.Render("Esc")) content.WriteString(infoStyle.Render(" to cancel")) return content.String() }