Repository: pterm/pterm (go)

Issue:
Print lines above spinner
While a spinner is running, every printed line should be put above the spinner.

Pull request description:
feat: print lines above active spinners
### Description
print lines above active spinners

### Scope
> What is affected by this pull request?

- [ ] Bug Fix
- [x] New Feature
- [ ] Documentation
- [ ] Other

### Related Issue
Fixes #211 


### To-Do Checklist
- [x] I tested my changes
- [ ] I have commented every method that I created/changed
- [ ] I updated the examples to fit with my changes
- [ ] I have added tests for my newly created methods


Patch:
diff --git a/print.go b/print.go
index 92a078a3..8eebfaa4 100644
--- a/print.go
+++ b/print.go
@@ -60,6 +60,14 @@ func Print(a ...interface{}) {
 		}
 	}
 
+	for _, spinner := range activeSpinnerPrinters {
+		if spinner.IsActive {
+			ret += sClearLine()
+			ret += Sprinto(a...)
+			printed = true
+		}
+	}
+
 	if !printed {
 		ret = color.Sprint(Sprint(a...))
 	}
diff --git a/spinner_printer.go b/spinner_printer.go
index 771b10f2..88b01cca 100644
--- a/spinner_printer.go
+++ b/spinner_printer.go
@@ -6,6 +6,8 @@ import (
 	"github.com/pterm/pterm/internal"
 )
 
+var activeSpinnerPrinters []*SpinnerPrinter
+
 // DefaultSpinner is the default SpinnerPrinter.
 var DefaultSpinner = SpinnerPrinter{
 	Sequence:       []string{"▀ ", " ▀", " ▄", "▄ "},
@@ -85,6 +87,7 @@ func (s *SpinnerPrinter) UpdateText(text string) {
 // Start the SpinnerPrinter.
 func (s SpinnerPrinter) Start(text ...interface{}) (*SpinnerPrinter, error) {
 	s.IsActive = true
+	activeSpinnerPrinters = append(activeSpinnerPrinters, &s)
 
 	if len(text) != 0 {
 		s.Text = Sprint(text...)


Test patch:
diff --git a/spinner_printer_test.go b/spinner_printer_test.go
index a5159649..8370202b 100644
--- a/spinner_printer_test.go
+++ b/spinner_printer_test.go
@@ -25,12 +25,14 @@ func TestSpinnerPrinter_Fail(t *testing.T) {
 func TestSpinnerPrinter_GenericStart(t *testing.T) {
 	p := DefaultSpinner
 	p.GenericStart()
+	p.GenericStop()
 }
 
 func TestSpinnerPrinter_GenericStartRawOutput(t *testing.T) {
 	DisableStyling()
 	p := DefaultSpinner
 	p.GenericStart()
+	p.GenericStop()
 	EnableStyling()
 }
 
@@ -52,7 +54,6 @@ func TestSpinnerPrinter_UpdateText(t *testing.T) {
 	p.UpdateText("test")
 
 	assert.Equal(t, "test", p.Text)
-	p.Stop()
 }
 
 func TestSpinnerPrinter_UpdateTextRawOutput(t *testing.T) {
@@ -161,3 +162,7 @@ func TestSpinnerPrinter_DifferentVariations(t *testing.T) {
 		})
 	}
 }
+
+func TestClearActiveSpinners(t *testing.T) {
+	activeSpinnerPrinters = []*SpinnerPrinter{}
+}