diff --git a/internal/view/live_view.go b/internal/view/live_view.go index ae5ad4ab..bdd7c423 100644 --- a/internal/view/live_view.go +++ b/internal/view/live_view.go @@ -33,6 +33,7 @@ type LiveView struct { fullScreen bool managedField bool cancel context.CancelFunc + paused bool } // NewLiveView returns a live viewer. @@ -47,6 +48,7 @@ func NewLiveView(app *App, title string, m model.ResourceViewer) *LiveView { maxRegions: 0, cmdBuff: model.NewFishBuff('/', model.FilterBuffer), model: m, + paused: true, // Default is to NOT automatically refresh for a better user experience } v.AddItem(v.text, 0, 1, true) @@ -132,6 +134,7 @@ func (v *LiveView) bindKeys() { tcell.KeyCtrlS: ui.NewKeyAction("Save", v.saveCmd, false), ui.KeyC: ui.NewKeyAction("Copy", v.cpCmd, true), ui.KeyF: ui.NewKeyAction("Toggle FullScreen", v.toggleFullScreenCmd, true), + ui.KeyR: ui.NewKeyAction("Toggle Auto-Refresh", v.pauseCmd, true), ui.KeyN: ui.NewKeyAction("Next Match", v.nextCmd, true), ui.KeyShiftN: ui.NewKeyAction("Prev Match", v.prevCmd, true), ui.KeySlash: ui.NewSharedKeyAction("Filter Mode", v.activateCmd, false), @@ -145,6 +148,22 @@ func (v *LiveView) bindKeys() { } } +// pauseCmd is used for pausing the refreshing of data on config map and secrets +func (v *LiveView) pauseCmd(evt *tcell.EventKey) *tcell.EventKey { + // We save the old variable because we need to toggle it for the correct behavior in the Start function + p := v.paused + v.paused = !v.paused + if p { + v.Start() + v.app.Flash().Info("Auto-refresh is enabled") + } else { + v.Stop() + v.app.Flash().Info("Auto-refresh is disabled") + } + + return evt +} + func (v *LiveView) keyboard(evt *tcell.EventKey) *tcell.EventKey { if a, ok := v.actions[ui.AsKey(evt)]; ok { return a.Action(evt) @@ -177,6 +196,11 @@ func (v *LiveView) Start() { if err := v.model.Watch(ctx); err != nil { log.Error().Err(err).Msgf("LiveView watcher failed") } + + // Determine if we want to auto-refresh or not + if v.paused { + v.Stop() + } } func (v *LiveView) defaultCtx() context.Context {