Skip to content

Commit 4b01a71

Browse files
author
Bruce Hill
committed
Clear the screen before entering into the looping modes
1 parent 69df4c8 commit 4b01a71

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

pkg/cmd/dev.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ var devCommand = cli.Command{
275275
}
276276

277277
func runPreview(ctx context.Context, cmd *cli.Command) error {
278+
// Clear the screen and move the cursor to the top
279+
fmt.Print("\033[2J\033[H")
280+
os.Stdout.Sync()
281+
278282
cc := getAPICommandContext(cmd)
279283

280284
gitUser, err := getGitUsername()

pkg/cmd/dev_view.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package cmd
22

33
import (
44
"fmt"
5+
"os"
56
"strings"
67
"time"
78

89
tea "github.com/charmbracelet/bubbletea"
910
"github.com/charmbracelet/glamour"
1011
"github.com/charmbracelet/lipgloss"
12+
"github.com/charmbracelet/x/term"
1113
"github.com/stainless-api/stainless-api-go"
1214
)
1315

@@ -293,10 +295,15 @@ func ViewHelpMenu() string {
293295

294296
// renderMarkdown renders markdown content using glamour
295297
func renderMarkdown(content string) string {
298+
width, _, err := term.GetSize(uintptr(os.Stdout.Fd()))
299+
if err != nil || width <= 0 || width > 120 {
300+
width = 120
301+
}
296302
r, err := glamour.NewTermRenderer(
297303
glamour.WithAutoStyle(),
298-
glamour.WithWordWrap(120),
304+
glamour.WithWordWrap(width),
299305
)
306+
300307
if err != nil {
301308
return content
302309
}

pkg/cmd/lint.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ var lintCommand = cli.Command{
4141
Action: runLinter,
4242
}
4343

44+
var helpStyle = lipgloss.NewStyle().
45+
Foreground(lipgloss.Color("241")).
46+
Margin(1, 0, 0, 0)
47+
4448
type lintModel struct {
4549
spinner spinner.Model
4650
diagnostics []stainless.BuildDiagnostic
@@ -88,13 +92,19 @@ func waitForFileChanges(m lintModel) tea.Cmd {
8892
}
8993

9094
func (m lintModel) Init() tea.Cmd {
95+
if m.watching {
96+
// Clear the screen and move the cursor to the top
97+
fmt.Print("\033[2J\033[H")
98+
os.Stdout.Sync()
99+
}
91100
return m.spinner.Tick
92101
}
93102

94103
func (m lintModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
95104
switch msg := msg.(type) {
96105
case tea.KeyMsg:
97106
if msg.String() == "ctrl+c" {
107+
m.watching = false
98108
return m, tea.Quit
99109
}
100110

@@ -143,13 +153,7 @@ func (m lintModel) View() string {
143153
}
144154
}
145155

146-
// Add help menu
147-
helpStyle := lipgloss.NewStyle().
148-
Foreground(lipgloss.Color("241")).
149-
Margin(1, 0, 0, 0)
150-
151156
helpText := helpStyle.Render("Press Ctrl+C to exit")
152-
153157
return content + helpText
154158
}
155159

@@ -221,7 +225,7 @@ func runLinter(ctx context.Context, cmd *cli.Command) error {
221225
}
222226

223227
// If not in watch mode and we have blocking diagnostics, exit with error code
224-
if !finalModel.watching && hasBlockingDiagnostic(finalModel.diagnostics) {
228+
if !cmd.Bool("watch") && hasBlockingDiagnostic(finalModel.diagnostics) {
225229
os.Exit(1)
226230
}
227231

0 commit comments

Comments
 (0)