4 tea "charm.land/bubbletea/v2"
5 "charm.land/lipgloss/v2"
6 "github.com/charmbracelet/crush/internal/tui/styles"
7 "github.com/charmbracelet/crush/internal/tui/util"
13 AuthMethodAPIKey AuthMethod = iota
17type AuthMethodChooser struct {
23func NewAuthMethodChooser() *AuthMethodChooser {
24 return &AuthMethodChooser{
25 State: AuthMethodOAuth2,
29func (a *AuthMethodChooser) Init() tea.Cmd {
33func (a *AuthMethodChooser) Update(msg tea.Msg) (util.Model, tea.Cmd) {
37func (a *AuthMethodChooser) View() string {
38 t := styles.CurrentTheme()
40 white := lipgloss.NewStyle().Foreground(t.White)
41 primary := lipgloss.NewStyle().Foreground(t.Primary)
42 success := lipgloss.NewStyle().Foreground(t.Success)
52 Render(titleStyle.Render("How would you like to authenticate with ") + success.Render("Anthropic") + titleStyle.Render("?"))
54 squareWidth := (a.width - 2) / 2
55 squareHeight := squareWidth / 3
56 if isOdd(squareHeight) {
60 square := lipgloss.NewStyle().
64 Border(lipgloss.RoundedBorder())
66 squareText := lipgloss.NewStyle().
67 Width(squareWidth - 2).
69 Align(lipgloss.Center).
70 AlignVertical(lipgloss.Center)
72 oauthBorder := t.AuthBorderSelected
73 oauthText := t.AuthTextSelected
74 apiKeyBorder := t.AuthBorderUnselected
75 apiKeyText := t.AuthTextUnselected
77 if a.State == AuthMethodAPIKey {
78 oauthBorder, apiKeyBorder = apiKeyBorder, oauthBorder
79 oauthText, apiKeyText = apiKeyText, oauthText
82 return lipgloss.JoinVertical(
86 lipgloss.JoinHorizontal(
89 Inherit(oauthBorder).Render(squareText.Inherit(oauthText).Render("Claude Account\nwith Subscription")),
90 square.MarginRight(1).
91 Inherit(apiKeyBorder).Render(squareText.Inherit(apiKeyText).Render("API Key")),
96func (a *AuthMethodChooser) SetDefaults() {
97 a.State = AuthMethodOAuth2
100func (a *AuthMethodChooser) SetWidth(w int) {
104func (a *AuthMethodChooser) ToggleChoice() {
106 case AuthMethodAPIKey:
107 a.State = AuthMethodOAuth2
108 case AuthMethodOAuth2:
109 a.State = AuthMethodAPIKey
113func isOdd(n int) bool {
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list