From e162c87b9d7e7a08ae0b79881d60d9f7603a0003 Mon Sep 17 00:00:00 2001 From: tzermias Date: Tue, 24 Feb 2026 22:55:40 +0200 Subject: [PATCH] Add inline height display during movement operations Shows real-time height feedback in the terminal during goto-height and goto-memory commands, updating every 200ms in place. Output example: Height: 78 cm (overwrites same line each tick) Height: 85 cm Height: 100 cm (final line, followed by newline) Changes: - GoToHeight: print \rHeight: X cm on each 200ms ticker tick; finalise with newline on completion and \n before cancellation message - GoToMemory: same pattern No new dependencies, no API changes, no new types. Co-Authored-By: Claude Sonnet 4.6 --- pkg/jiecang/height.go | 4 +++- pkg/jiecang/memory.go | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/jiecang/height.go b/pkg/jiecang/height.go index a506604..60ad3b5 100644 --- a/pkg/jiecang/height.go +++ b/pkg/jiecang/height.go @@ -69,6 +69,7 @@ func (j *Jiecang) GoToHeight(ctx context.Context, height uint8) error { j.mu.RUnlock() if currentHeight == height { + fmt.Printf("\rHeight: %d cm\n", currentHeight) break } @@ -78,9 +79,10 @@ func (j *Jiecang) GoToHeight(ctx context.Context, height uint8) error { if err := j.sendCommand(commands["stop"]); err != nil { return fmt.Errorf("failed to send stop command: %w", err) } - fmt.Printf("Operation cancelled at height %d cm\n", currentHeight) + fmt.Printf("\nOperation cancelled at height %d cm\n", currentHeight) return nil case <-ticker.C: + fmt.Printf("\rHeight: %d cm", currentHeight) if err := j.sendCommand(command); err != nil { return fmt.Errorf("failed to send goto command: %w", err) } diff --git a/pkg/jiecang/memory.go b/pkg/jiecang/memory.go index ee2dd97..5ed23a5 100644 --- a/pkg/jiecang/memory.go +++ b/pkg/jiecang/memory.go @@ -51,15 +51,16 @@ func (j *Jiecang) GoToMemory(ctx context.Context, memoryNum int) error { j.mu.RUnlock() if currentHeight == targetHeight { + fmt.Printf("\rHeight: %d cm\n", currentHeight) break } select { case <-ctx.Done(): - // Context cancelled, return - fmt.Printf("Operation cancelled at height %d cm\n", currentHeight) + fmt.Printf("\nOperation cancelled at height %d cm\n", currentHeight) return nil case <-ticker.C: + fmt.Printf("\rHeight: %d cm", currentHeight) if err := j.sendCommand(commands[commandKey]); err != nil { return fmt.Errorf("failed to send goto memory%d command: %w", memoryNum, err) }