View implements tea.Model.
()
| 442 | |
| 443 | // View implements tea.Model. |
| 444 | func (a App) View() string { |
| 445 | if a.width == 0 { |
| 446 | return "Loading..." |
| 447 | } |
| 448 | |
| 449 | // Reserve 1 line for the status bar when a refresh message is active so |
| 450 | // that sub-views don't render into space that will be taken by the status. |
| 451 | statusLines := 0 |
| 452 | if a.metadataRefreshMsg != "" { |
| 453 | statusLines = 1 |
| 454 | } |
| 455 | |
| 456 | // Temporarily adjust the height passed to sub-views so they leave room |
| 457 | // for the status line. |
| 458 | effectiveHeight := a.height - statusLines |
| 459 | |
| 460 | var content string |
| 461 | switch a.viewMode { |
| 462 | case ViewModeInitAuth: |
| 463 | content = a.renderInitAuth() |
| 464 | case ViewModePricing: |
| 465 | a.pricingView.Height = effectiveHeight |
| 466 | content = a.pricingView.Render(true, a.version) |
| 467 | case ViewModeHistory: |
| 468 | a.historyView.Height = effectiveHeight |
| 469 | cacheCount, cacheBytes := 0, 0 |
| 470 | cachePath, _ := config.DBPath() |
| 471 | if a.db != nil { |
| 472 | cacheCount, cacheBytes, _ = a.db.GetCacheStats() |
| 473 | } |
| 474 | content = a.historyView.Render(true, cacheCount, cacheBytes, cachePath, a.version) |
| 475 | case ViewModeSettings: |
| 476 | a.settingsView.Height = effectiveHeight |
| 477 | configPath, _ := config.Path() |
| 478 | content = a.settingsView.Render(true, a.client.Config, configPath, a.version) |
| 479 | } |
| 480 | |
| 481 | if a.metadataRefreshMsg != "" { |
| 482 | color := lipgloss.Color("6") |
| 483 | if strings.Contains(a.metadataRefreshMsg, "Error") { |
| 484 | color = lipgloss.Color("1") |
| 485 | } else if strings.Contains(a.metadataRefreshMsg, "Succeeded") { |
| 486 | color = lipgloss.Color("2") |
| 487 | } |
| 488 | status := lipgloss.NewStyle().Foreground(color).Bold(true).Render(" ● " + a.metadataRefreshMsg) |
| 489 | content += "\n" + status |
| 490 | } |
| 491 | |
| 492 | // Ensure the output fills the entire terminal so there is no blank space. |
| 493 | return lipgloss.Place(a.width, a.height, lipgloss.Left, lipgloss.Top, content) |
| 494 | } |
| 495 | |
| 496 | func (a App) renderInitAuth() string { |
| 497 | spinners := []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧"} |
nothing calls this directly
no test coverage detected