pkg.re/essentialkaos/ek.10@v12.41.0+incompatible/fmtc/examples_test.go (about) 1 package fmtc 2 3 // ////////////////////////////////////////////////////////////////////////////////// // 4 // // 5 // Copyright (c) 2022 ESSENTIAL KAOS // 6 // Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> // 7 // // 8 // ////////////////////////////////////////////////////////////////////////////////// // 9 10 import ( 11 "fmt" 12 "time" 13 ) 14 15 // ////////////////////////////////////////////////////////////////////////////////// // 16 17 func ExamplePrintln() { 18 19 // print colored text 20 // {!} is tag for style reset 21 Println("{d}black{!}") 22 Println("{r}red{!}") 23 Println("{y}yellow{!}") 24 Println("{b}blue{!}") 25 Println("{c}cyan{!}") 26 Println("{m}magenta{!}") 27 Println("{g}green{!}") 28 Println("{s}light grey{!}") 29 30 // use text modificators 31 32 // light colors 33 Println("{r-}light red{!}") 34 Println("{r-}dark grey{!}") 35 36 // bold + color 37 Println("{r*}red{!}") 38 Println("{g*}green{!}") 39 40 // dim 41 Println("{r^}red{!}") 42 Println("{g^}green{!}") 43 44 // underline 45 Println("{r_}red{!}") 46 Println("{g_}green{!}") 47 48 // blink 49 Println("{r~}red{!}") 50 Println("{g~}green{!}") 51 52 // reverse 53 Println("{r@}red{!}") 54 Println("{g@}green{!}") 55 56 // background color 57 Println("{D}black{!}") 58 Println("{R}red{!}") 59 Println("{Y}yellow{!}") 60 Println("{B}blue{!}") 61 Println("{C}cyan{!}") 62 Println("{M}magenta{!}") 63 Println("{G}green{!}") 64 Println("{S}light grey{!}") 65 66 // many tags at once 67 // underline, cyan text with the red background 68 Println("{cR_}text{!}") 69 70 // many tags in once 71 Println("{r}{*}red and bold{!}") 72 73 // modificator reset 74 Println("{r}{*}red and bold {!*}just red{!}") 75 76 // 256 colors (# for foreground, % for background) 77 Println("{#201}pink text{!}") 78 Println("{%201}pink background{!}") 79 80 // 24-bit colors (# for foreground, % for background) 81 Println("{#7cfc00}lawngreen text{!}") 82 Println("{%6a5acd}slateblue background{!}") 83 } 84 85 func ExamplePrintf() { 86 var ( 87 user = "Bob" 88 isUserOnline = true 89 ) 90 91 if isUserOnline { 92 Printf("User {c}%s{!} is {g}online{!}\n", user) 93 } else { 94 Printf("User {c}%s{!} is {r}offline{!}\n", user) 95 } 96 } 97 98 func ExampleBell() { 99 // terminal bell 100 Bell() 101 } 102 103 func ExampleNewLine() { 104 // just print a new line 105 NewLine() 106 } 107 108 func ExampleClean() { 109 // Remove color tags from text 110 fmt.Println(Clean("{r}Text{!}")) 111 112 // Output: Text 113 } 114 115 func ExampleIs256ColorsSupported() { 116 fmt.Printf("256 Colors Supported: %t\n", Is256ColorsSupported()) 117 } 118 119 func ExampleIsTrueColorSupported() { 120 fmt.Printf("TrueColor Supported: %t\n", IsTrueColorSupported()) 121 } 122 123 func ExampleTPrintf() { 124 TPrintf("This is temporary text") 125 time.Sleep(time.Second) 126 TPrintf("This message replace previous message after 1 sec") 127 } 128 129 func ExampleTLPrintf() { 130 // Power of TPrintf and LPrintf in one method 131 TLPrintf(22, "This is temporary text") 132 time.Sleep(time.Second) 133 TLPrintf(22, "This message will replace previous message after 1 sec") 134 } 135 136 func ExampleLPrintf() { 137 // Only "This is text" will be shown 138 LPrintf(12, "{r}This is %s {g} with colors{!}", "text") 139 }