77 "os"
88 "time"
99
10+ "github.com/charmbracelet/bubbles/help"
11+ "github.com/charmbracelet/bubbles/key"
1012 "github.com/charmbracelet/bubbles/spinner"
1113 tea "github.com/charmbracelet/bubbletea"
1214 "github.com/charmbracelet/lipgloss"
@@ -49,26 +51,17 @@ var lintCommand = cli.Command{
4951 },
5052}
5153
52- var helpStyle = lipgloss .NewStyle ().
53- Foreground (lipgloss .Color ("241" )).
54- Margin (1 , 0 , 0 , 0 )
55-
5654type lintModel struct {
57- spinner spinner.Model
58- diagnostics []stainless.BuildDiagnostic
59- error error
60- watching bool
61- stopWhenPassing bool
62- ctx context.Context
63- cmd * cli.Command
64- cc * apiCommandContext
65- stopPolling chan struct {}
66- help helpModel
67- }
68-
69- type helpModel struct {
70- width int
71- height int
55+ spinner spinner.Model
56+ diagnostics []stainless.BuildDiagnostic
57+ error error
58+ watching bool
59+ canSkip bool
60+ ctx context.Context
61+ cmd * cli.Command
62+ cc * apiCommandContext
63+ stopPolling chan struct {}
64+ help help.Model
7265}
7366
7467func (m lintModel ) Init () tea.Cmd {
@@ -94,7 +87,7 @@ func (m lintModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
9487 m .cmd = msg .cmd
9588 m .cc = msg .cc
9689
97- if m .stopWhenPassing && ! hasBlockingDiagnostic (m .diagnostics ) {
90+ if m .canSkip && ! hasBlockingDiagnostic (m .diagnostics ) {
9891 m .watching = false
9992 return m , tea .Quit
10093 }
@@ -119,8 +112,7 @@ func (m lintModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
119112 return m , cmd
120113
121114 case tea.WindowSizeMsg :
122- m .help .width = msg .Width
123- m .help .height = msg .Height
115+ m .help .Width = msg .Width
124116 return m , nil
125117 }
126118
@@ -142,12 +134,7 @@ func (m lintModel) View() string {
142134 }
143135 }
144136
145- if m .stopWhenPassing {
146- content += helpStyle .Render ("Press Enter to skip diagnostics, Ctrl+C to exit" )
147- } else {
148- content += helpStyle .Render ("Press Ctrl+C to exit" )
149- }
150-
137+ content += "\n " + m .help .View (m )
151138 return content
152139}
153140
@@ -172,22 +159,44 @@ func getDiagnosticsCmd(ctx context.Context, cmd *cli.Command, cc *apiCommandCont
172159 }
173160}
174161
175- func runLinter (ctx context.Context , cmd * cli.Command , stopWhenPassing bool ) error {
162+ func (m lintModel ) ShortHelp () []key.Binding {
163+ if m .canSkip {
164+ return []key.Binding {
165+ key .NewBinding (key .WithKeys ("ctrl+c" ), key .WithHelp ("ctrl-c" , "quit" )),
166+ key .NewBinding (key .WithKeys ("enter" ), key .WithHelp ("enter" , "skip diagnostics" )),
167+ }
168+ } else {
169+ return []key.Binding {key .NewBinding (key .WithKeys ("ctrl+c" ), key .WithHelp ("ctrl-c" , "quit" ))}
170+ }
171+ }
172+
173+ func (m lintModel ) FullHelp () [][]key.Binding {
174+ if m .canSkip {
175+ return [][]key.Binding {{
176+ key .NewBinding (key .WithKeys ("ctrl+c" ), key .WithHelp ("ctrl-c" , "quit" )),
177+ key .NewBinding (key .WithKeys ("enter" ), key .WithHelp ("enter" , "skip diagnostics" )),
178+ }}
179+ } else {
180+ return [][]key.Binding {{key .NewBinding (key .WithKeys ("ctrl+c" ), key .WithHelp ("ctrl-c" , "quit" ))}}
181+ }
182+ }
183+
184+ func runLinter (ctx context.Context , cmd * cli.Command , canSkip bool ) error {
176185 cc := getAPICommandContext (cmd )
177186
178187 s := spinner .New ()
179188 s .Spinner = spinner .MiniDot
180189 s .Style = lipgloss .NewStyle ().Foreground (lipgloss .Color ("208" ))
181190
182191 m := lintModel {
183- spinner : s ,
184- watching : cmd .Bool ("watch" ),
185- stopWhenPassing : stopWhenPassing ,
186- ctx : ctx ,
187- cmd : cmd ,
188- cc : cc ,
189- stopPolling : make (chan struct {}),
190- help : helpModel {} ,
192+ spinner : s ,
193+ watching : cmd .Bool ("watch" ),
194+ canSkip : canSkip ,
195+ ctx : ctx ,
196+ cmd : cmd ,
197+ cc : cc ,
198+ stopPolling : make (chan struct {}),
199+ help : help . New () ,
191200 }
192201
193202 p := tea .NewProgram (m , tea .WithContext (ctx ))
0 commit comments