Repository: pterm/pterm (go)

Issue:
Option to disable all output
Option to disable all output.

```go
pterm.DisableOutput = true
```

🔝 this should disable all Print functions, so that PTerm does not print anything.
Can be used to run CLI tools in `quiet` or `silent` mode.

Pull request description:
feat: add ability to disable output
### Description
Now we can disable output using `pterm.DisableOutput = false` for using with quiet mode

### Scope
> What is affected by this pull request?

- [ ] Bug Fix
- [x] New Feature
- [ ] Documentation
- [ ] Other

### Related Issue
Fixes #31 


Patch:
diff --git a/print.go b/print.go
index f5cc73d6..f8bb59cf 100644
--- a/print.go
+++ b/print.go
@@ -37,6 +37,10 @@ func Sprinto(a ...interface{}) string {
 // Spaces are added between operands when neither is a string.
 // It returns the number of bytes written and any write error encountered.
 func Print(a ...interface{}) {
+	if DisableOutput {
+		return
+	}
+
 	var ret string
 	var printed bool
 
@@ -72,6 +76,10 @@ func Printf(format string, a ...interface{}) {
 // Spaces are added between operands when neither is a string.
 // It returns the number of bytes written and any write error encountered.
 func Fprint(writer io.Writer, a ...interface{}) {
+	if DisableOutput {
+		return
+	}
+
 	color.Fprint(writer, Sprint(a...))
 }
 
@@ -90,6 +98,10 @@ func Fprintln(writer io.Writer, a ...interface{}) {
 // time.Sleep(time.Second)
 // pterm.Oprint("Hello, Earth!")
 func Printo(a ...interface{}) {
+	if DisableOutput {
+		return
+	}
+
 	color.Print("\r" + Sprint(a...))
 }
 
diff --git a/pterm.go b/pterm.go
index c5512f48..f2ac5c11 100644
--- a/pterm.go
+++ b/pterm.go
@@ -1,1 +1,6 @@
 package pterm
+
+var (
+	// DisableOutput completely disables output from pterm. Can be used in CLI application quiet mode.
+	DisableOutput = false
+)
\ No newline at end of file


Test patch:
diff --git a/pterm_test.go b/pterm_test.go
index 75c2af7d..f2cdfd30 100644
--- a/pterm_test.go
+++ b/pterm_test.go
@@ -41,70 +41,165 @@ func TestSprinto(t *testing.T) {
 // Print functions
 
 func TestPrint(t *testing.T) {
-	for _, randomString := range internal.RandomStrings {
-		out := captureStdout(func(w io.Writer) {
-			Print(randomString)
-		})
-		assert.Equal(t, randomString, out)
-	}
+	t.Run("enabled output", func(t *testing.T) {
+		for _, randomString := range internal.RandomStrings {
+			out := captureStdout(func(w io.Writer) {
+				Print(randomString)
+			})
+			assert.Equal(t, randomString, out)
+		}
+	})
+
+	t.Run("disabled output", func(t *testing.T) {
+		DisableOutput = true
+		for _, randomString := range internal.RandomStrings {
+			out := captureStdout(func(w io.Writer) {
+				Print(randomString)
+			})
+			assert.Equal(t, "", out)
+		}
+		DisableOutput = false
+	})
 }
 
 func TestPrintln(t *testing.T) {
-	for _, randomString := range internal.RandomStrings {
-		out := captureStdout(func(w io.Writer) {
-			Println(randomString)
-		})
-		assert.Equal(t, randomString+"\n", out)
-	}
+	t.Run("enabled output", func(t *testing.T) {
+		for _, randomString := range internal.RandomStrings {
+			out := captureStdout(func(w io.Writer) {
+				Println(randomString)
+			})
+			assert.Equal(t, randomString+"\n", out)
+		}
+	})
+
+	t.Run("disabled output", func(t *testing.T) {
+		DisableOutput = true
+		for _, randomString := range internal.RandomStrings {
+			out := captureStdout(func(w io.Writer) {
+				Println(randomString)
+			})
+			assert.Equal(t, "", out)
+		}
+		DisableOutput = false
+	})
 }
 
 func TestPrintf(t *testing.T) {
-	for _, randomString := range internal.RandomStrings {
+	t.Run("enabled output", func(t *testing.T) {
+		for _, randomString := range internal.RandomStrings {
+			out := captureStdout(func(w io.Writer) {
+				Printf(randomString)
+			})
+			assert.Equal(t, randomString, out)
+		}
 		out := captureStdout(func(w io.Writer) {
-			Printf(randomString)
+			Printf("Hello, %s!", "World")
 		})
-		assert.Equal(t, randomString, out)
-	}
-	out := captureStdout(func(w io.Writer) {
-		Printf("Hello, %s!", "World")
+		assert.Equal(t, "Hello, World!", out)
 	})
-	assert.Equal(t, "Hello, World!", out)
-}
 
-func TestFprint(t *testing.T) {
-	for _, randomString := range internal.RandomStrings {
+	t.Run("disabled output", func(t *testing.T) {
+		DisableOutput = true
+		for _, randomString := range internal.RandomStrings {
+			out := captureStdout(func(w io.Writer) {
+				Printf(randomString)
+			})
+			assert.Equal(t, "", out)
+		}
 		out := captureStdout(func(w io.Writer) {
-			Fprint(w, randomString)
+			Printf("Hello, %s!", "World")
 		})
-		assert.Equal(t, randomString, out)
-	}
+		assert.Equal(t, "", out)
+		DisableOutput = false
+	})
+}
+
+func TestFprint(t *testing.T) {
+	t.Run("enabled output", func(t *testing.T) {
+		for _, randomString := range internal.RandomStrings {
+			out := captureStdout(func(w io.Writer) {
+				Fprint(w, randomString)
+			})
+			assert.Equal(t, randomString, out)
+		}
+	})
+
+	t.Run("disabled output", func(t *testing.T) {
+		DisableOutput = true
+		for _, randomString := range internal.RandomStrings {
+			out := captureStdout(func(w io.Writer) {
+				Fprint(w, randomString)
+			})
+			assert.Equal(t, "", out)
+		}
+		DisableOutput = false
+	})
 }
 
 func TestFprintln(t *testing.T) {
-	for _, randomString := range internal.RandomStrings {
-		out := captureStdout(func(w io.Writer) {
-			Fprintln(w, randomString)
-		})
-		assert.Equal(t, randomString+"\n", out)
-	}
+	t.Run("enabled output", func(t *testing.T) {
+		for _, randomString := range internal.RandomStrings {
+			out := captureStdout(func(w io.Writer) {
+				Fprintln(w, randomString)
+			})
+			assert.Equal(t, randomString+"\n", out)
+		}
+	})
+
+	t.Run("disabled output", func(t *testing.T) {
+		DisableOutput = true
+		for _, randomString := range internal.RandomStrings {
+			out := captureStdout(func(w io.Writer) {
+				Fprintln(w, randomString)
+			})
+			assert.Equal(t, "", out)
+		}
+		DisableOutput = false
+	})
 }
 
 func TestPrinto(t *testing.T) {
-	for _, randomString := range internal.RandomStrings {
-		out := captureStdout(func(w io.Writer) {
-			Printo(randomString)
-		})
-		assert.Equal(t, "\r"+randomString, out)
-	}
+	t.Run("enabled output", func(t *testing.T) {
+		for _, randomString := range internal.RandomStrings {
+			out := captureStdout(func(w io.Writer) {
+				Printo(randomString)
+			})
+			assert.Equal(t, "\r"+randomString, out)
+		}
+	})
+
+	t.Run("disabled output", func(t *testing.T) {
+		DisableOutput = true
+		for _, randomString := range internal.RandomStrings {
+			out := captureStdout(func(w io.Writer) {
+				Printo(randomString)
+			})
+			assert.Equal(t, "", out)
+		}
+		DisableOutput = false
+	})
 }
 
 func TestFprinto(t *testing.T) {
-	for _, randomString := range internal.RandomStrings {
-		out := captureStdout(func(w io.Writer) {
-			Fprinto(w, randomString)
-		})
-		assert.Equal(t, "\r"+randomString, out)
-	}
+	t.Run("enabled output", func(t *testing.T) {
+		for _, randomString := range internal.RandomStrings {
+			out := captureStdout(func(w io.Writer) {
+				Fprinto(w, randomString)
+			})
+			assert.Equal(t, "\r"+randomString, out)
+		}
+	})
+
+	t.Run("disabled output", func(t *testing.T) {
+		DisableOutput = true
+		for _, randomString := range internal.RandomStrings {
+			out := captureStdout(func(w io.Writer) {
+				Fprinto(w, randomString)
+			})
+			assert.Equal(t, "", out)
+		}
+		DisableOutput = false
+	})
 }
 
 func TestRemoveColors(t *testing.T) {