on main help sign in
refactor(hyper): a couple of small adjustments
cddb306Andrey Nering
internal/tui/components/dialogs/hyper/device_flow.go+9−6
@@ -9,7 +9,6 @@ import (
9 "charm.land/bubbles/v2/spinner"
9 "charm.land/bubbles/v2/spinner"
10 tea "charm.land/bubbletea/v2"
10 tea "charm.land/bubbletea/v2"
11 "charm.land/lipgloss/v2"
11 "charm.land/lipgloss/v2"
12− hyperp "github.com/charmbracelet/crush/internal/agent/hyper"
13 "github.com/charmbracelet/crush/internal/oauth"
12 "github.com/charmbracelet/crush/internal/oauth"
14 "github.com/charmbracelet/crush/internal/oauth/hyper"
13 "github.com/charmbracelet/crush/internal/oauth/hyper"
15 "github.com/charmbracelet/crush/internal/tui/styles"
14 "github.com/charmbracelet/crush/internal/tui/styles"
@@ -47,7 +46,6 @@ type DeviceFlowErrorMsg struct {
47type DeviceFlow struct {
46type DeviceFlow struct {
48 State DeviceFlowState
47 State DeviceFlowState
49 width int
48 width int
50− baseURL string
51 deviceCode string
49 deviceCode string
52 userCode string
50 userCode string
53 verificationURL string
51 verificationURL string
@@ -64,7 +62,6 @@ func NewDeviceFlow() *DeviceFlow {
64 s.Style = lipgloss.NewStyle().Foreground(styles.CurrentTheme().GreenLight)
62 s.Style = lipgloss.NewStyle().Foreground(styles.CurrentTheme().GreenLight)
65 return &DeviceFlow{
63 return &DeviceFlow{
66 State: DeviceFlowStateDisplay,
64 State: DeviceFlowStateDisplay,
67− baseURL: hyperp.BaseURL(),
68 spinner: s,
65 spinner: s,
69 }
66 }
70}
67}
@@ -103,6 +100,7 @@ func (d *DeviceFlow) View() string {
103 whiteStyle := lipgloss.NewStyle().Foreground(t.White)
100 whiteStyle := lipgloss.NewStyle().Foreground(t.White)
104 primaryStyle := lipgloss.NewStyle().Foreground(t.Primary)
101 primaryStyle := lipgloss.NewStyle().Foreground(t.Primary)
105 greenStyle := lipgloss.NewStyle().Foreground(t.GreenLight)
102 greenStyle := lipgloss.NewStyle().Foreground(t.GreenLight)
103+ linkStyle := lipgloss.NewStyle().Foreground(t.GreenDark).Underline(true)
106 errorStyle := lipgloss.NewStyle().Foreground(t.Error)
104 errorStyle := lipgloss.NewStyle().Foreground(t.Error)
107 mutedStyle := lipgloss.NewStyle().Foreground(t.FgMuted)
105 mutedStyle := lipgloss.NewStyle().Foreground(t.FgMuted)
108
106
@@ -121,7 +119,6 @@ func (d *DeviceFlow) View() string {
121 Margin(1, 1, 0, 1).
119 Margin(1, 1, 0, 1).
122 Width(d.width - 2).
120 Width(d.width - 2).
123 Render(
121 Render(
124−
125 whiteStyle.Render("Press ") +
122 whiteStyle.Render("Press ") +
126 primaryStyle.Render("enter") +
123 primaryStyle.Render("enter") +
127 whiteStyle.Render(" to copy the code below and open the browser."),
124 whiteStyle.Render(" to copy the code below and open the browser."),
@@ -140,7 +137,7 @@ func (d *DeviceFlow) View() string {
140 Render(d.userCode),
137 Render(d.userCode),
141 )
138 )
142
139
143− link := lipgloss.NewStyle().Hyperlink(d.verificationURL, "id=hyper-verify").Render(d.verificationURL)
140+ link := linkStyle.Hyperlink(d.verificationURL, "id=hyper-verify").Render(d.verificationURL)
144 url := mutedStyle.
141 url := mutedStyle.
145 Margin(0, 1).
142 Margin(0, 1).
146 Width(d.width - 2).
143 Width(d.width - 2).
@@ -165,7 +162,7 @@ func (d *DeviceFlow) View() string {
165 case DeviceFlowStateError:
162 case DeviceFlowStateError:
166 return lipgloss.NewStyle().
163 return lipgloss.NewStyle().
167 Margin(0, 1).
164 Margin(0, 1).
168− Width(d.width).
165+ Width(d.width - 2).
169 Render(errorStyle.Render("Authentication failed."))
166 Render(errorStyle.Render("Authentication failed."))
170
167
171 default:
168 default:
@@ -183,6 +180,9 @@ func (d *DeviceFlow) Cursor() *tea.Cursor { return nil }
183
180
184// CopyCodeAndOpenURL copies the user code to the clipboard and opens the URL.
181// CopyCodeAndOpenURL copies the user code to the clipboard and opens the URL.
185func (d *DeviceFlow) CopyCodeAndOpenURL() tea.Cmd {
182func (d *DeviceFlow) CopyCodeAndOpenURL() tea.Cmd {
183+ if d.State != DeviceFlowStateDisplay {
184+ return nil
185+ }
186 return tea.Sequence(
186 return tea.Sequence(
187 tea.SetClipboard(d.userCode),
187 tea.SetClipboard(d.userCode),
188 func() tea.Msg {
188 func() tea.Msg {
@@ -197,6 +197,9 @@ func (d *DeviceFlow) CopyCodeAndOpenURL() tea.Cmd {
197
197
198// CopyCode copies just the user code to the clipboard.
198// CopyCode copies just the user code to the clipboard.
199func (d *DeviceFlow) CopyCode() tea.Cmd {
199func (d *DeviceFlow) CopyCode() tea.Cmd {
200+ if d.State != DeviceFlowStateDisplay {
201+ return nil
202+ }
200 return tea.Sequence(
203 return tea.Sequence(
201 tea.SetClipboard(d.userCode),
204 tea.SetClipboard(d.userCode),
202 util.ReportInfo("Code copied to clipboard"),
205 util.ReportInfo("Code copied to clipboard"),