From a08e806eaac8737893f643107f771876c742d3ab Mon Sep 17 00:00:00 2001 From: "kalle (jag)" <2477952+applejag@users.noreply.github.com> Date: Sat, 11 Nov 2023 18:41:08 +0100 Subject: [PATCH] Show spinner on restart (#64) * Show spinner on restart * Updated CHANGELOG.md --- CHANGELOG.md | 3 +++ pkg/klock/klock.go | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b126d4d..996b23b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,9 @@ This project tries to follow [SemVer 2.0.0](https://semver.org/). The fix is just adding a small 150ms sleep, which is hopefully enough time for tools like `kubectx` to finish writing the kubeconfig file. (#63) +- Added spinner when the watch restarts (either from `--watch-kubeconfig` or + from an error), to indicate that it's loading. (#64) + - Changed to Go 1.21.4 to resolve vulnerability [GO-2023-2186](https://pkg.go.dev/vuln/GO-2023-2186), where `filepath.IsLocal` incorrectly treated reserved names as local. (#66) diff --git a/pkg/klock/klock.go b/pkg/klock/klock.go index 2dc1d26..43345ad 100644 --- a/pkg/klock/klock.go +++ b/pkg/klock/klock.go @@ -171,9 +171,17 @@ func (w *Watcher) WatchLoop(ctx context.Context, restartChan <-chan struct{}) er clearBeforePrinting = true select { case err := <-watchErrChan: + if cmd := w.Printer.Table.StartSpinner(); cmd != nil { + w.Program.Send(cmd()) + } w.errorChan <- fmt.Errorf("restart in 5s: %w", err) time.Sleep(5 * time.Second) + w.Printer.Table.StopSpinner() + w.Printer.Table.SetError(nil) case <-restartChan: + if cmd := w.Printer.Table.StartSpinner(); cmd != nil { + w.Program.Send(cmd()) + } // Prevent it from restarting too eagerly when we're told to restart // so the filesystem has time to flush, such as in case of // "kubectx" on bigger kubeconfigs.