@@ -84,9 +84,11 @@ type seriesTable struct {
84
84
err error
85
85
infoTitle string
86
86
flashMsg internal.TextFlash
87
+ program * tea.Program
88
+ logger log.Logger
87
89
}
88
90
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 {
90
92
tbl := table .New (
91
93
table .WithColumns ([]table.Column {
92
94
{Title : "Name" , Width : 60 },
@@ -126,6 +128,7 @@ func newModel(sm map[string]scrape.SeriesSet, height int) *seriesTable {
126
128
loading : true ,
127
129
searchingMetrics : false ,
128
130
flashMsg : internal.TextFlash {},
131
+ logger : logger ,
129
132
}
130
133
131
134
return m
@@ -279,8 +282,21 @@ func (m *seriesTable) updateWhileBrowsingTable(msg tea.Msg) (tea.Model, tea.Cmd)
279
282
cmd .Stdout = os .Stdout
280
283
cmd .Stderr = os .Stderr
281
284
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
+
284
300
// Ideally the temp file would be removed here but that causes issues with editors like vscode
285
301
if err != nil {
286
302
return m , m .flashMsg .Flash ("Failed to run editor: " + err .Error (), internal .Error , flashDuration )
@@ -379,8 +395,9 @@ func registerCardinalityCommand(app *extkingpin.App) {
379
395
scrapeURL := opts .ScrapeURL
380
396
timeoutDuration := opts .Timeout
381
397
382
- metricTable := newModel (nil , opts .OutputHeight )
398
+ metricTable := newModel (nil , opts .OutputHeight , logger )
383
399
p := tea .NewProgram (metricTable )
400
+ metricTable .program = p
384
401
385
402
// Create a channel to signal when scraping is complete
386
403
scrapeDone := make (chan struct {})
0 commit comments