1package splash
2
3import (
4 "fmt"
5 "os"
6 "slices"
7 "strings"
8 "time"
9
10 "github.com/charmbracelet/bubbles/v2/key"
11 "github.com/charmbracelet/bubbles/v2/spinner"
12 tea "github.com/charmbracelet/bubbletea/v2"
13 "github.com/charmbracelet/catwalk/pkg/catwalk"
14 "github.com/charmbracelet/crush/internal/config"
15 "github.com/charmbracelet/crush/internal/llm/prompt"
16 "github.com/charmbracelet/crush/internal/tui/components/chat"
17 "github.com/charmbracelet/crush/internal/tui/components/core"
18 "github.com/charmbracelet/crush/internal/tui/components/core/layout"
19 "github.com/charmbracelet/crush/internal/tui/components/dialogs/models"
20 "github.com/charmbracelet/crush/internal/tui/components/logo"
21 "github.com/charmbracelet/crush/internal/tui/exp/list"
22 "github.com/charmbracelet/crush/internal/tui/styles"
23 "github.com/charmbracelet/crush/internal/tui/util"
24 "github.com/charmbracelet/crush/internal/version"
25 "github.com/charmbracelet/lipgloss/v2"
26)
27
28type Splash interface {
29 util.Model
30 layout.Sizeable
31 layout.Help
32 Cursor() *tea.Cursor
33 // SetOnboarding controls whether the splash shows model selection UI
34 SetOnboarding(bool)
35 // SetProjectInit controls whether the splash shows project initialization prompt
36 SetProjectInit(bool)
37
38 // Showing API key input
39 IsShowingAPIKey() bool
40
41 // IsAPIKeyValid returns whether the API key is valid
42 IsAPIKeyValid() bool
43}
44
45const (
46 SplashScreenPaddingY = 1 // Padding Y for the splash screen
47
48 LogoGap = 6
49)
50
51// OnboardingCompleteMsg is sent when onboarding is complete
52type (
53 OnboardingCompleteMsg struct{}
54 SubmitAPIKeyMsg struct{}
55)
56
57type splashCmp struct {
58 width, height int
59 keyMap KeyMap
60 logoRendered string
61
62 // State
63 isOnboarding bool
64 needsProjectInit bool
65 needsAPIKey bool
66 selectedNo bool
67
68 listHeight int
69 modelList *models.ModelListComponent
70 apiKeyInput *models.APIKeyInput
71 selectedModel *models.ModelOption
72 isAPIKeyValid bool
73 apiKeyValue string
74}
75
76func New() Splash {
77 keyMap := DefaultKeyMap()
78 listKeyMap := list.DefaultKeyMap()
79 listKeyMap.Down.SetEnabled(false)
80 listKeyMap.Up.SetEnabled(false)
81 listKeyMap.HalfPageDown.SetEnabled(false)
82 listKeyMap.HalfPageUp.SetEnabled(false)
83 listKeyMap.Home.SetEnabled(false)
84 listKeyMap.End.SetEnabled(false)
85 listKeyMap.DownOneItem = keyMap.Next
86 listKeyMap.UpOneItem = keyMap.Previous
87
88 modelList := models.NewModelListComponent(listKeyMap, "Find your fave", false)
89 apiKeyInput := models.NewAPIKeyInput()
90
91 return &splashCmp{
92 width: 0,
93 height: 0,
94 keyMap: keyMap,
95 logoRendered: "",
96 modelList: modelList,
97 apiKeyInput: apiKeyInput,
98 selectedNo: false,
99 }
100}
101
102func (s *splashCmp) SetOnboarding(onboarding bool) {
103 s.isOnboarding = onboarding
104 if onboarding {
105 providers, err := config.Providers()
106 if err != nil {
107 return
108 }
109 filteredProviders := []catwalk.Provider{}
110 simpleProviders := []string{
111 "anthropic",
112 "openai",
113 "gemini",
114 "xai",
115 "groq",
116 "openrouter",
117 }
118 for _, p := range providers {
119 if slices.Contains(simpleProviders, string(p.ID)) {
120 filteredProviders = append(filteredProviders, p)
121 }
122 }
123 s.modelList.SetProviders(filteredProviders)
124 }
125}
126
127func (s *splashCmp) SetProjectInit(needsInit bool) {
128 s.needsProjectInit = needsInit
129}
130
131// GetSize implements SplashPage.
132func (s *splashCmp) GetSize() (int, int) {
133 return s.width, s.height
134}
135
136// Init implements SplashPage.
137func (s *splashCmp) Init() tea.Cmd {
138 return tea.Batch(s.modelList.Init(), s.apiKeyInput.Init())
139}
140
141// SetSize implements SplashPage.
142func (s *splashCmp) SetSize(width int, height int) tea.Cmd {
143 wasSmallScreen := s.isSmallScreen()
144 rerenderLogo := width != s.width
145 s.height = height
146 s.width = width
147 if rerenderLogo || wasSmallScreen != s.isSmallScreen() {
148 s.logoRendered = s.logoBlock()
149 }
150 // remove padding, logo height, gap, title space
151 s.listHeight = s.height - lipgloss.Height(s.logoRendered) - (SplashScreenPaddingY * 2) - s.logoGap() - 2
152 listWidth := min(60, width)
153 s.apiKeyInput.SetWidth(width - 2)
154 return s.modelList.SetSize(listWidth, s.listHeight)
155}
156
157// Update implements SplashPage.
158func (s *splashCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
159 switch msg := msg.(type) {
160 case tea.WindowSizeMsg:
161 return s, s.SetSize(msg.Width, msg.Height)
162 case models.APIKeyStateChangeMsg:
163 u, cmd := s.apiKeyInput.Update(msg)
164 s.apiKeyInput = u.(*models.APIKeyInput)
165 if msg.State == models.APIKeyInputStateVerified {
166 return s, tea.Tick(5*time.Second, func(t time.Time) tea.Msg {
167 return SubmitAPIKeyMsg{}
168 })
169 }
170 return s, cmd
171 case SubmitAPIKeyMsg:
172 if s.isAPIKeyValid {
173 return s, s.saveAPIKeyAndContinue(s.apiKeyValue)
174 }
175 case tea.KeyPressMsg:
176 switch {
177 case key.Matches(msg, s.keyMap.Back):
178 if s.isAPIKeyValid {
179 return s, nil
180 }
181 if s.needsAPIKey {
182 // Go back to model selection
183 s.needsAPIKey = false
184 s.selectedModel = nil
185 s.isAPIKeyValid = false
186 s.apiKeyValue = ""
187 s.apiKeyInput.Reset()
188 return s, nil
189 }
190 case key.Matches(msg, s.keyMap.Select):
191 if s.isAPIKeyValid {
192 return s, s.saveAPIKeyAndContinue(s.apiKeyValue)
193 }
194 if s.isOnboarding && !s.needsAPIKey {
195 selectedItem := s.modelList.SelectedModel()
196 if selectedItem == nil {
197 return s, nil
198 }
199 if s.isProviderConfigured(string(selectedItem.Provider.ID)) {
200 cmd := s.setPreferredModel(*selectedItem)
201 s.isOnboarding = false
202 return s, tea.Batch(cmd, util.CmdHandler(OnboardingCompleteMsg{}))
203 } else {
204 // Provider not configured, show API key input
205 s.needsAPIKey = true
206 s.selectedModel = selectedItem
207 s.apiKeyInput.SetProviderName(selectedItem.Provider.Name)
208 return s, nil
209 }
210 } else if s.needsAPIKey {
211 // Handle API key submission
212 s.apiKeyValue = strings.TrimSpace(s.apiKeyInput.Value())
213 if s.apiKeyValue == "" {
214 return s, nil
215 }
216
217 provider, err := s.getProvider(s.selectedModel.Provider.ID)
218 if err != nil || provider == nil {
219 return s, util.ReportError(fmt.Errorf("provider %s not found", s.selectedModel.Provider.ID))
220 }
221 providerConfig := config.ProviderConfig{
222 ID: string(s.selectedModel.Provider.ID),
223 Name: s.selectedModel.Provider.Name,
224 APIKey: s.apiKeyValue,
225 Type: provider.Type,
226 BaseURL: provider.APIEndpoint,
227 }
228 return s, tea.Sequence(
229 util.CmdHandler(models.APIKeyStateChangeMsg{
230 State: models.APIKeyInputStateVerifying,
231 }),
232 func() tea.Msg {
233 start := time.Now()
234 err := providerConfig.TestConnection(config.Get().Resolver())
235 // intentionally wait for at least 750ms to make sure the user sees the spinner
236 elapsed := time.Since(start)
237 if elapsed < 750*time.Millisecond {
238 time.Sleep(750*time.Millisecond - elapsed)
239 }
240 if err == nil {
241 s.isAPIKeyValid = true
242 return models.APIKeyStateChangeMsg{
243 State: models.APIKeyInputStateVerified,
244 }
245 }
246 return models.APIKeyStateChangeMsg{
247 State: models.APIKeyInputStateError,
248 }
249 },
250 )
251 } else if s.needsProjectInit {
252 return s, s.initializeProject()
253 }
254 case key.Matches(msg, s.keyMap.Tab, s.keyMap.LeftRight):
255 if s.needsAPIKey {
256 u, cmd := s.apiKeyInput.Update(msg)
257 s.apiKeyInput = u.(*models.APIKeyInput)
258 return s, cmd
259 }
260 if s.needsProjectInit {
261 s.selectedNo = !s.selectedNo
262 return s, nil
263 }
264 case key.Matches(msg, s.keyMap.Yes):
265 if s.isOnboarding {
266 return s, nil
267 }
268 if s.needsAPIKey {
269 u, cmd := s.apiKeyInput.Update(msg)
270 s.apiKeyInput = u.(*models.APIKeyInput)
271 return s, cmd
272 }
273
274 if s.needsProjectInit {
275 return s, s.initializeProject()
276 }
277 case key.Matches(msg, s.keyMap.No):
278 if s.isOnboarding {
279 return s, nil
280 }
281 if s.needsAPIKey {
282 u, cmd := s.apiKeyInput.Update(msg)
283 s.apiKeyInput = u.(*models.APIKeyInput)
284 return s, cmd
285 }
286
287 s.selectedNo = true
288 return s, s.initializeProject()
289 default:
290 if s.needsAPIKey {
291 u, cmd := s.apiKeyInput.Update(msg)
292 s.apiKeyInput = u.(*models.APIKeyInput)
293 return s, cmd
294 } else if s.isOnboarding {
295 u, cmd := s.modelList.Update(msg)
296 s.modelList = u
297 return s, cmd
298 }
299 }
300 case tea.PasteMsg:
301 if s.needsAPIKey {
302 u, cmd := s.apiKeyInput.Update(msg)
303 s.apiKeyInput = u.(*models.APIKeyInput)
304 return s, cmd
305 } else if s.isOnboarding {
306 var cmd tea.Cmd
307 s.modelList, cmd = s.modelList.Update(msg)
308 return s, cmd
309 }
310 case spinner.TickMsg:
311 u, cmd := s.apiKeyInput.Update(msg)
312 s.apiKeyInput = u.(*models.APIKeyInput)
313 return s, cmd
314 }
315 return s, nil
316}
317
318func (s *splashCmp) saveAPIKeyAndContinue(apiKey string) tea.Cmd {
319 if s.selectedModel == nil {
320 return nil
321 }
322
323 cfg := config.Get()
324 err := cfg.SetProviderAPIKey(string(s.selectedModel.Provider.ID), apiKey)
325 if err != nil {
326 return util.ReportError(fmt.Errorf("failed to save API key: %w", err))
327 }
328
329 // Reset API key state and continue with model selection
330 s.needsAPIKey = false
331 cmd := s.setPreferredModel(*s.selectedModel)
332 s.isOnboarding = false
333 s.selectedModel = nil
334 s.isAPIKeyValid = false
335
336 return tea.Batch(cmd, util.CmdHandler(OnboardingCompleteMsg{}))
337}
338
339func (s *splashCmp) initializeProject() tea.Cmd {
340 s.needsProjectInit = false
341
342 if err := config.MarkProjectInitialized(); err != nil {
343 return util.ReportError(err)
344 }
345 var cmds []tea.Cmd
346
347 cmds = append(cmds, util.CmdHandler(OnboardingCompleteMsg{}))
348 if !s.selectedNo {
349 cmds = append(cmds,
350 util.CmdHandler(chat.SessionClearedMsg{}),
351 util.CmdHandler(chat.SendMsg{
352 Text: prompt.Initialize(),
353 }),
354 )
355 }
356 return tea.Sequence(cmds...)
357}
358
359func (s *splashCmp) setPreferredModel(selectedItem models.ModelOption) tea.Cmd {
360 cfg := config.Get()
361 model := cfg.GetModel(string(selectedItem.Provider.ID), selectedItem.Model.ID)
362 if model == nil {
363 return util.ReportError(fmt.Errorf("model %s not found for provider %s", selectedItem.Model.ID, selectedItem.Provider.ID))
364 }
365
366 selectedModel := config.SelectedModel{
367 Model: selectedItem.Model.ID,
368 Provider: string(selectedItem.Provider.ID),
369 ReasoningEffort: model.DefaultReasoningEffort,
370 MaxTokens: model.DefaultMaxTokens,
371 }
372
373 err := cfg.UpdatePreferredModel(config.SelectedModelTypeLarge, selectedModel)
374 if err != nil {
375 return util.ReportError(err)
376 }
377
378 // Now lets automatically setup the small model
379 knownProvider, err := s.getProvider(selectedItem.Provider.ID)
380 if err != nil {
381 return util.ReportError(err)
382 }
383 if knownProvider == nil {
384 // for local provider we just use the same model
385 err = cfg.UpdatePreferredModel(config.SelectedModelTypeSmall, selectedModel)
386 if err != nil {
387 return util.ReportError(err)
388 }
389 } else {
390 smallModel := knownProvider.DefaultSmallModelID
391 model := cfg.GetModel(string(selectedItem.Provider.ID), smallModel)
392 // should never happen
393 if model == nil {
394 err = cfg.UpdatePreferredModel(config.SelectedModelTypeSmall, selectedModel)
395 if err != nil {
396 return util.ReportError(err)
397 }
398 return nil
399 }
400 smallSelectedModel := config.SelectedModel{
401 Model: smallModel,
402 Provider: string(selectedItem.Provider.ID),
403 ReasoningEffort: model.DefaultReasoningEffort,
404 MaxTokens: model.DefaultMaxTokens,
405 }
406 err = cfg.UpdatePreferredModel(config.SelectedModelTypeSmall, smallSelectedModel)
407 if err != nil {
408 return util.ReportError(err)
409 }
410 }
411 cfg.SetupAgents()
412 return nil
413}
414
415func (s *splashCmp) getProvider(providerID catwalk.InferenceProvider) (*catwalk.Provider, error) {
416 providers, err := config.Providers()
417 if err != nil {
418 return nil, err
419 }
420 for _, p := range providers {
421 if p.ID == providerID {
422 return &p, nil
423 }
424 }
425 return nil, nil
426}
427
428func (s *splashCmp) isProviderConfigured(providerID string) bool {
429 cfg := config.Get()
430 if _, ok := cfg.Providers.Get(providerID); ok {
431 return true
432 }
433 return false
434}
435
436func (s *splashCmp) View() string {
437 t := styles.CurrentTheme()
438 var content string
439 if s.needsAPIKey {
440 remainingHeight := s.height - lipgloss.Height(s.logoRendered) - (SplashScreenPaddingY * 2)
441 apiKeyView := t.S().Base.PaddingLeft(1).Render(s.apiKeyInput.View())
442 apiKeySelector := t.S().Base.AlignVertical(lipgloss.Bottom).Height(remainingHeight).Render(
443 lipgloss.JoinVertical(
444 lipgloss.Left,
445 apiKeyView,
446 ),
447 )
448 content = lipgloss.JoinVertical(
449 lipgloss.Left,
450 s.logoRendered,
451 apiKeySelector,
452 )
453 } else if s.isOnboarding {
454 modelListView := s.modelList.View()
455 remainingHeight := s.height - lipgloss.Height(s.logoRendered) - (SplashScreenPaddingY * 2)
456 modelSelector := t.S().Base.AlignVertical(lipgloss.Bottom).Height(remainingHeight).Render(
457 lipgloss.JoinVertical(
458 lipgloss.Left,
459 t.S().Base.PaddingLeft(1).Foreground(t.Primary).Render("Choose a Model"),
460 "",
461 modelListView,
462 ),
463 )
464 content = lipgloss.JoinVertical(
465 lipgloss.Left,
466 s.logoRendered,
467 modelSelector,
468 )
469 } else if s.needsProjectInit {
470 titleStyle := t.S().Base.Foreground(t.FgBase)
471 bodyStyle := t.S().Base.Foreground(t.FgMuted)
472 shortcutStyle := t.S().Base.Foreground(t.Success)
473
474 initText := lipgloss.JoinVertical(
475 lipgloss.Left,
476 titleStyle.Render("Would you like to initialize this project?"),
477 "",
478 bodyStyle.Render("When I initialize your codebase I examine the project and put the"),
479 bodyStyle.Render("result into a CRUSH.md file which serves as general context."),
480 "",
481 bodyStyle.Render("You can also initialize anytime via ")+shortcutStyle.Render("ctrl+p")+bodyStyle.Render("."),
482 "",
483 bodyStyle.Render("Would you like to initialize now?"),
484 )
485
486 yesButton := core.SelectableButton(core.ButtonOpts{
487 Text: "Yep!",
488 UnderlineIndex: 0,
489 Selected: !s.selectedNo,
490 })
491
492 noButton := core.SelectableButton(core.ButtonOpts{
493 Text: "Nope",
494 UnderlineIndex: 0,
495 Selected: s.selectedNo,
496 })
497
498 buttons := lipgloss.JoinHorizontal(lipgloss.Left, yesButton, " ", noButton)
499 remainingHeight := s.height - lipgloss.Height(s.logoRendered) - (SplashScreenPaddingY * 2)
500
501 initContent := t.S().Base.AlignVertical(lipgloss.Bottom).PaddingLeft(1).Height(remainingHeight).Render(
502 lipgloss.JoinVertical(
503 lipgloss.Left,
504 initText,
505 "",
506 buttons,
507 ),
508 )
509
510 content = lipgloss.JoinVertical(
511 lipgloss.Left,
512 s.logoRendered,
513 "",
514 initContent,
515 )
516 } else {
517 parts := []string{
518 s.logoRendered,
519 s.infoSection(),
520 }
521 content = lipgloss.JoinVertical(lipgloss.Left, parts...)
522 }
523
524 return t.S().Base.
525 Width(s.width).
526 Height(s.height).
527 PaddingTop(SplashScreenPaddingY).
528 PaddingBottom(SplashScreenPaddingY).
529 Render(content)
530}
531
532func (s *splashCmp) Cursor() *tea.Cursor {
533 if s.needsAPIKey {
534 cursor := s.apiKeyInput.Cursor()
535 if cursor != nil {
536 return s.moveCursor(cursor)
537 }
538 } else if s.isOnboarding {
539 cursor := s.modelList.Cursor()
540 if cursor != nil {
541 return s.moveCursor(cursor)
542 }
543 } else {
544 return nil
545 }
546 return nil
547}
548
549func (s *splashCmp) isSmallScreen() bool {
550 // Consider a screen small if either the width is less than 40 or if the
551 // height is less than 20
552 return s.width < 55 || s.height < 20
553}
554
555func (s *splashCmp) infoSection() string {
556 t := styles.CurrentTheme()
557 infoStyle := t.S().Base.PaddingLeft(2)
558 if s.isSmallScreen() {
559 infoStyle = infoStyle.MarginTop(1)
560 }
561 return infoStyle.Render(
562 lipgloss.JoinVertical(
563 lipgloss.Left,
564 s.cwd(),
565 "",
566 s.currentModelBlock(),
567 "",
568 lipgloss.JoinHorizontal(lipgloss.Left, s.lspBlock(), s.mcpBlock()),
569 "",
570 ),
571 )
572}
573
574func (s *splashCmp) logoBlock() string {
575 t := styles.CurrentTheme()
576 logoStyle := t.S().Base.Padding(0, 2).Width(s.width)
577 if s.isSmallScreen() {
578 // If the width is too small, render a smaller version of the logo
579 // NOTE: 20 is not correct because [splashCmp.height] is not the
580 // *actual* window height, instead, it is the height of the splash
581 // component and that depends on other variables like compact mode and
582 // the height of the editor.
583 return logoStyle.Render(
584 logo.SmallRender(s.width - logoStyle.GetHorizontalFrameSize()),
585 )
586 }
587 return logoStyle.Render(
588 logo.Render(version.Version, false, logo.Opts{
589 FieldColor: t.Primary,
590 TitleColorA: t.Secondary,
591 TitleColorB: t.Primary,
592 CharmColor: t.Secondary,
593 VersionColor: t.Primary,
594 Width: s.width - logoStyle.GetHorizontalFrameSize(),
595 }),
596 )
597}
598
599func (s *splashCmp) moveCursor(cursor *tea.Cursor) *tea.Cursor {
600 if cursor == nil {
601 return nil
602 }
603 // Calculate the correct Y offset based on current state
604 logoHeight := lipgloss.Height(s.logoRendered)
605 if s.needsAPIKey {
606 infoSectionHeight := lipgloss.Height(s.infoSection())
607 baseOffset := logoHeight + SplashScreenPaddingY + infoSectionHeight
608 remainingHeight := s.height - baseOffset - lipgloss.Height(s.apiKeyInput.View()) - SplashScreenPaddingY
609 offset := baseOffset + remainingHeight
610 cursor.Y += offset
611 cursor.X = cursor.X + 1
612 } else if s.isOnboarding {
613 offset := logoHeight + SplashScreenPaddingY + s.logoGap() + 2
614 cursor.Y += offset
615 cursor.X = cursor.X + 1
616 }
617
618 return cursor
619}
620
621func (s *splashCmp) logoGap() int {
622 if s.height > 35 {
623 return LogoGap
624 }
625 return 0
626}
627
628// Bindings implements SplashPage.
629func (s *splashCmp) Bindings() []key.Binding {
630 if s.needsAPIKey {
631 return []key.Binding{
632 s.keyMap.Select,
633 s.keyMap.Back,
634 }
635 } else if s.isOnboarding {
636 return []key.Binding{
637 s.keyMap.Select,
638 s.keyMap.Next,
639 s.keyMap.Previous,
640 }
641 } else if s.needsProjectInit {
642 return []key.Binding{
643 s.keyMap.Select,
644 s.keyMap.Yes,
645 s.keyMap.No,
646 s.keyMap.Tab,
647 s.keyMap.LeftRight,
648 }
649 }
650 return []key.Binding{}
651}
652
653func (s *splashCmp) getMaxInfoWidth() int {
654 return min(s.width-2, 40) // 2 for left padding
655}
656
657func (s *splashCmp) cwd() string {
658 cwd := config.Get().WorkingDir()
659 t := styles.CurrentTheme()
660 homeDir, err := os.UserHomeDir()
661 if err == nil && cwd != homeDir {
662 cwd = strings.ReplaceAll(cwd, homeDir, "~")
663 }
664 maxWidth := s.getMaxInfoWidth()
665 return t.S().Muted.Width(maxWidth).Render(cwd)
666}
667
668func LSPList(maxWidth int) []string {
669 t := styles.CurrentTheme()
670 lspList := []string{}
671 lsp := config.Get().LSP.Sorted()
672 if len(lsp) == 0 {
673 return []string{t.S().Base.Foreground(t.Border).Render("None")}
674 }
675 for _, l := range lsp {
676 iconColor := t.Success
677 if l.LSP.Disabled {
678 iconColor = t.FgMuted
679 }
680 lspList = append(lspList,
681 core.Status(
682 core.StatusOpts{
683 IconColor: iconColor,
684 Title: l.Name,
685 Description: l.LSP.Command,
686 },
687 maxWidth,
688 ),
689 )
690 }
691 return lspList
692}
693
694func (s *splashCmp) lspBlock() string {
695 t := styles.CurrentTheme()
696 maxWidth := s.getMaxInfoWidth() / 2
697 section := t.S().Subtle.Render("LSPs")
698 lspList := append([]string{section, ""}, LSPList(maxWidth-1)...)
699 return t.S().Base.Width(maxWidth).PaddingRight(1).Render(
700 lipgloss.JoinVertical(
701 lipgloss.Left,
702 lspList...,
703 ),
704 )
705}
706
707func MCPList(maxWidth int) []string {
708 t := styles.CurrentTheme()
709 mcpList := []string{}
710 mcps := config.Get().MCP.Sorted()
711 if len(mcps) == 0 {
712 return []string{t.S().Base.Foreground(t.Border).Render("None")}
713 }
714 for _, l := range mcps {
715 iconColor := t.Success
716 if l.MCP.Disabled {
717 iconColor = t.FgMuted
718 }
719 mcpList = append(mcpList,
720 core.Status(
721 core.StatusOpts{
722 IconColor: iconColor,
723 Title: l.Name,
724 Description: l.MCP.Command,
725 },
726 maxWidth,
727 ),
728 )
729 }
730 return mcpList
731}
732
733func (s *splashCmp) mcpBlock() string {
734 t := styles.CurrentTheme()
735 maxWidth := s.getMaxInfoWidth() / 2
736 section := t.S().Subtle.Render("MCPs")
737 mcpList := append([]string{section, ""}, MCPList(maxWidth-1)...)
738 return t.S().Base.Width(maxWidth).PaddingRight(1).Render(
739 lipgloss.JoinVertical(
740 lipgloss.Left,
741 mcpList...,
742 ),
743 )
744}
745
746func (s *splashCmp) currentModelBlock() string {
747 cfg := config.Get()
748 agentCfg := cfg.Agents["coder"]
749 model := config.Get().GetModelByType(agentCfg.Model)
750 if model == nil {
751 return ""
752 }
753 t := styles.CurrentTheme()
754 modelIcon := t.S().Base.Foreground(t.FgSubtle).Render(styles.ModelIcon)
755 modelName := t.S().Text.Render(model.Name)
756 modelInfo := fmt.Sprintf("%s %s", modelIcon, modelName)
757 parts := []string{
758 modelInfo,
759 }
760
761 return lipgloss.JoinVertical(
762 lipgloss.Left,
763 parts...,
764 )
765}
766
767func (s *splashCmp) IsShowingAPIKey() bool {
768 return s.needsAPIKey
769}
770
771func (s *splashCmp) IsAPIKeyValid() bool {
772 return s.isAPIKeyValid
773}