forked from pterm/pterm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpterm.go
70 lines (58 loc) · 2.14 KB
/
pterm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Package pterm is a modern go module to beautify console output.
// It can be used without configuration, but if desired, everything can be customized down to the smallest detail.
//
// Official docs are available at: https://docs.pterm.sh
//
// View the animated examples here: https://github.com/forvitinn/pterm#-examples
package pterm
import "github.com/gookit/color"
var (
// Output completely disables output from pterm if set to false. Can be used in CLI application quiet mode.
Output = true
// PrintDebugMessages sets if messages printed by the DebugPrinter should be printed.
PrintDebugMessages = false
// RawOutput is set to true if pterm.DisableStyling() was called.
// The variable indicates that PTerm will not add additional styling to text.
// Use pterm.DisableStyling() or pterm.EnableStyling() to change this variable.
// Changing this variable directly, will disable or enable the output of colored text.
RawOutput = false
)
func init() {
color.ForceColor()
}
// EnableOutput enables the output of PTerm.
func EnableOutput() {
Output = true
}
// DisableOutput disables the output of PTerm.
func DisableOutput() {
Output = false
}
// EnableDebugMessages enables the output of debug printers.
func EnableDebugMessages() {
PrintDebugMessages = true
}
// DisableDebugMessages disables the output of debug printers.
func DisableDebugMessages() {
PrintDebugMessages = false
}
// EnableStyling enables the default PTerm styling.
// This also calls EnableColor.
func EnableStyling() {
RawOutput = false
EnableColor()
}
// DisableStyling sets PTerm to RawOutput mode and disables all of PTerms styling.
// You can use this to print to text files etc.
// This also calls DisableColor.
func DisableStyling() {
RawOutput = true
DisableColor()
}
// RecalculateTerminalSize updates already initialized terminal dimensions. Has to be called after a termina resize to guarantee proper rendering. Applies only to new instances.
func RecalculateTerminalSize() {
// keep in sync with DefaultBarChart
DefaultBarChart.Width = GetTerminalWidth() * 2 / 3
DefaultBarChart.Height = GetTerminalHeight() * 2 / 3
DefaultParagraph.MaxWidth = GetTerminalWidth()
}