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) }