Skip to content

Commit c133741

Browse files
swar8080pedro-stanaka
authored andcommitted
Try pausing bubbletea's control of the terminal while running the editor to see if it avoids interference with editors that run in the same terminal
1 parent 192c48b commit c133741

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

cmd/cardinality.go

+21-4
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ type seriesTable struct {
8484
err error
8585
infoTitle string
8686
flashMsg internal.TextFlash
87+
program *tea.Program
88+
logger log.Logger
8789
}
8890

89-
func newModel(sm map[string]scrape.SeriesSet, height int) *seriesTable {
91+
func newModel(sm map[string]scrape.SeriesSet, height int, logger log.Logger) *seriesTable {
9092
tbl := table.New(
9193
table.WithColumns([]table.Column{
9294
{Title: "Name", Width: 60},
@@ -126,6 +128,7 @@ func newModel(sm map[string]scrape.SeriesSet, height int) *seriesTable {
126128
loading: true,
127129
searchingMetrics: false,
128130
flashMsg: internal.TextFlash{},
131+
logger: logger,
129132
}
130133

131134
return m
@@ -279,8 +282,21 @@ func (m *seriesTable) updateWhileBrowsingTable(msg tea.Msg) (tea.Model, tea.Cmd)
279282
cmd.Stdout = os.Stdout
280283
cmd.Stderr = os.Stderr
281284

282-
// Run the editor
283-
err := cmd.Run()
285+
// Pause the program to allow the editor to run without interference
286+
err := m.program.ReleaseTerminal()
287+
if err != nil {
288+
return m, m.flashMsg.Flash("Error preparing to view series: "+err.Error(), internal.Error, flashDuration)
289+
}
290+
defer func() {
291+
err := m.program.RestoreTerminal()
292+
if err != nil {
293+
_ = level.Warn(m.logger).Log("msg", "Failed to restore terminal", "err", err)
294+
}
295+
}()
296+
297+
// Display the editor
298+
err = cmd.Run()
299+
284300
// Ideally the temp file would be removed here but that causes issues with editors like vscode
285301
if err != nil {
286302
return m, m.flashMsg.Flash("Failed to run editor: "+err.Error(), internal.Error, flashDuration)
@@ -379,8 +395,9 @@ func registerCardinalityCommand(app *extkingpin.App) {
379395
scrapeURL := opts.ScrapeURL
380396
timeoutDuration := opts.Timeout
381397

382-
metricTable := newModel(nil, opts.OutputHeight)
398+
metricTable := newModel(nil, opts.OutputHeight, logger)
383399
p := tea.NewProgram(metricTable)
400+
metricTable.program = p
384401

385402
// Create a channel to signal when scraping is complete
386403
scrapeDone := make(chan struct{})

0 commit comments

Comments
 (0)