Documentation ¶
Overview ¶
Package fmtutil provides methods for output formatting
Index ¶
- Variables
- func Align(text string, alignment Alignment, size int) string
- func ColorizePassword(password, letterTag, numTag, specialTag string) string
- func CountDigits(i int) int
- func Float(f float64) float64
- func ParseSize(size string) uint64
- func PrettyBool(b bool, vals ...string) string
- func PrettyDiff(i int, separator ...string) string
- func PrettyNum(i any, separator ...string) string
- func PrettyPerc(i float64) string
- func PrettySize(i any, separator ...string) string
- func Separator(tiny bool, args ...string)
- func Wrap(text, indent string, maxLineLength int) string
- type Alignment
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var OrderSeparator = ","
OrderSeparator is a default order separator
var SeparatorColorTag = "{s}"
SeparatorColorTag is fmtc color tag used for separator (light gray by default)
var SeparatorFullscreen = false
SeparatorFullscreen allow enabling full-screen separator
var SeparatorSize = 88
SeparatorSize contains size of separator
var SeparatorSymbol = "-"
SeparatorSymbol used for separator generation
var SeparatorTitleColorTag = "{s}"
SeparatorTitleColorTag is fmtc color tag used for separator title (light gray by default)
var SizeSeparator = ""
SizeSeparator is a default size separator
Functions ¶
func Align ¶ added in v12.65.0
Align can align text with ANSI control sequences (for example colors)
func ColorizePassword ¶
ColorizePassword adds different fmtc color tags for numbers and letters
Example ¶
password := ">+XY!b3Rog" fmt.Println(ColorizePassword(password, "{r}", "{y}", "{c}"))
Output: {c}>+{r}XY{c}!{r}b{y}3{r}Rog{!}
func Float ¶
Float formats float numbers more nicely
Example ¶
f1 := 0.3145 f2 := 3.452 f3 := 135.5215 fmt.Printf("%f → %g\n", f1, Float(f1)) fmt.Printf("%f → %g\n", f2, Float(f2)) fmt.Printf("%f → %g\n", f3, Float(f3))
Output: 0.314500 → 0.31 3.452000 → 3.45 135.521500 → 135.5
func ParseSize ¶
ParseSize parses size and return it in bytes (e.g 1.34 Mb -> 1478182)
Example ¶
s1 := "160" s2 := "34Mb" s3 := "2.2 GB" fmt.Printf("%s → %d\n", s1, ParseSize(s1)) fmt.Printf("%s → %d\n", s2, ParseSize(s2)) fmt.Printf("%s → %d\n", s3, ParseSize(s3))
Output: 160 → 160 34Mb → 35651584 2.2 GB → 2362232012
func PrettyBool ¶
PrettyBool formats boolean to "pretty" form (e.g true/false -> Y/N)
Example ¶
fmt.Printf("%t → %s\n", true, PrettyBool(true)) fmt.Printf("%t → %s\n", false, PrettyBool(false)) fmt.Printf("%t → %s\n", true, PrettyBool(true, "Yep", "Nope")) fmt.Printf("%t → %s\n", false, PrettyBool(false, "Yep", "Nope"))
Output: true → Y false → N true → Yep false → Nope
func PrettyDiff ¶
PrettyDiff formats number to "pretty" form with + or - symbol at the beginning
func PrettyNum ¶
PrettyNum formats number to "pretty" form (e.g 1234567 -> 1,234,567)
Example ¶
var ( n1 int = 10 n2 uint = 5000 n3 float64 = 6128750.26 ) fmt.Printf("%d → %s\n", n1, PrettyNum(n1)) fmt.Printf("%d → %s\n", n2, PrettyNum(n2)) fmt.Printf("%.2f → %s\n", n3, PrettyNum(n3)) // Set default order separator OrderSeparator = " " fmt.Printf("%.2f → %s\n", n3, PrettyNum(n3)) // Use custom order separator fmt.Printf("%.2f → %s\n", n3, PrettyNum(n3, "|"))
Output: 10 → 10 5000 → 5,000 6128750.26 → 6,128,750.26 6128750.26 → 6 128 750.26 6128750.26 → 6|128|750.26
func PrettyPerc ¶
PrettyNum formats float value to "pretty" percent form (e.g 12.3423 -> 12.3%)
Example ¶
var ( n1 float64 = 0.123 n2 float64 = 10.24 n3 float64 = 1294.193 ) OrderSeparator = "," fmt.Printf("%f → %s\n", n1, PrettyPerc(n1)) fmt.Printf("%f → %s\n", n2, PrettyPerc(n2)) fmt.Printf("%f → %s\n", n3, PrettyPerc(n3))
Output: 0.123000 → 0.12% 10.240000 → 10.2% 1294.193000 → 1,294.2%
func PrettySize ¶
PrettySize formats value to "pretty" size (e.g 1478182 -> 1.34 Mb)
Example ¶
s1 := 193 s2 := 184713 s3 := int64(46361936461) fmt.Printf("%d → %s\n", s1, PrettySize(s1)) fmt.Printf("%d → %s\n", s2, PrettySize(s2)) fmt.Printf("%d → %s\n", s3, PrettySize(s3)) // Set size separator SizeSeparator = " " fmt.Printf("%d → %s\n", s3, PrettySize(s3)) // Use custom order separator fmt.Printf("%d → %s\n", s3, PrettySize(s3, "|"))
Output: 193 → 193B 184713 → 180.4KB 46361936461 → 43.2GB 46361936461 → 43.2 GB 46361936461 → 43.2|GB
func Separator ¶
Separator renders separator to console
Example ¶
// You can change color of separator symbols and title using fmtc color tags SeparatorColorTag = "{r}" // Set color to red SeparatorTitleColorTag = "{r*}" // Set color to red with bold weight // Or you can remove colors SeparatorColorTag = "" SeparatorTitleColorTag = "" // This is tiny separator (just 1 line) Separator(true) // This is wide separator with newlines before and after separator Separator(false) // You can set title of separator Separator(true, "MY SEPARATOR")
Output:
Types ¶
Directories ¶
Path | Synopsis |
---|---|
Package panel provides methods for rendering panels with text
|
Package panel provides methods for rendering panels with text |
Package table contains methods and structs for rendering data in tabular format
|
Package table contains methods and structs for rendering data in tabular format |