Skip to content

Unwanted newline with spinnerΒ #731

@sqsp-rwatkins

Description

@sqsp-rwatkins

How can I get the spinner to not print a new line before the text?

output during spinner:

πŸš€ Creating Devspace Instance
   β€’ Instance name: rwatkins-3
   β€’ Size: M
   β€’ Location: US_EAST1
   β€’ Image: devspace-base
                                                                                                                                                                                                                                          
 β–€ Waiting for instance to start (3s)

output after spinner complete. RemoveWhenDone is set:

πŸš€ Creating Devspace Instance
   β€’ Instance name: rwatkins-3
   β€’ Size: M
   β€’ Location: US_EAST1
   β€’ Image: devspace-base
                                                                                                                                                                                                                                          
   β€’ Instance status: βœ… Running

Spinner functions:

// StartSpinner starts a spinning animation with a message
func (ui *PtermUI) StartSpinner(message string) {
	ui.mu.Lock()
	defer ui.mu.Unlock()

	// Use a regular PTerm spinner for single operations
	if _, exists := ui.spinners[message]; !exists {
		// indentedMessage := ui.getIndent() + message
		spinner, _ := pterm.DefaultSpinner.Start()
		spinner.UpdateText(message)
		ui.spinners[message] = spinner
	}
}

// StopSpinner stops the spinning animation
func (ui *PtermUI) StopSpinner() {
	ui.mu.Lock()
	defer ui.mu.Unlock()

	// Stop all regular spinners
	for _, spinner := range ui.spinners {
		spinner.Stop()
	}
	ui.spinners = make(map[string]*pterm.SpinnerPrinter)
}

// SpinnerSuccess resolves a spinner with success
func (ui *PtermUI) SpinnerSuccess(message string) {
	ui.mu.Lock()
	defer ui.mu.Unlock()

	if spinner, exists := ui.spinners[message]; exists {
		// Use the original message for the success output (without indentation)
		spinner.Success(message)
		delete(ui.spinners, message)
	}
}

// SpinnerWarning resolves a spinner with warning
func (ui *PtermUI) SpinnerWarning(message string) {
	ui.mu.Lock()
	defer ui.mu.Unlock()

	if spinner, exists := ui.spinners[message]; exists {
		// Use the original message for the warning output (without indentation)
		spinner.Warning(message)
		delete(ui.spinners, message)
	}
}

// SpinnerFail resolves a spinner with failure
func (ui *PtermUI) SpinnerFail(message string) {
	ui.mu.Lock()
	defer ui.mu.Unlock()

	if spinner, exists := ui.spinners[message]; exists {
		// Use the original message for the fail output (without indentation)
		spinner.Fail(message)
		delete(ui.spinners, message)
	}
}

Calling code:

u.StartSpinner("Waiting for instance to start")
...
u.SpinnerSuccess("Waiting for instance to start")
u.PrintItem("Instance status", "βœ… Running")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions