pkg.re/essentialkaos/ek@v12.36.0+incompatible/fmtc/examples_test.go (about)

     1  package fmtc
     2  
     3  // ////////////////////////////////////////////////////////////////////////////////// //
     4  //                                                                                    //
     5  //                         Copyright (c) 2021 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  
    81  func ExamplePrintf() {
    82  	var (
    83  		user         = "Bob"
    84  		isUserOnline = true
    85  	)
    86  
    87  	if isUserOnline {
    88  		Printf("User {c}%s{!} is {g}online{!}\n", user)
    89  	} else {
    90  		Printf("User {c}%s{!} is {r}offline{!}\n", user)
    91  	}
    92  }
    93  
    94  func ExampleBell() {
    95  	// terminal bell
    96  	Bell()
    97  }
    98  
    99  func ExampleNewLine() {
   100  	// just print a new line
   101  	NewLine()
   102  }
   103  
   104  func ExampleClean() {
   105  	// Remove color tags from text
   106  	fmt.Println(Clean("{r}Text{!}"))
   107  
   108  	// Output: Text
   109  }
   110  
   111  func ExampleTPrintf() {
   112  	TPrintf("This is temporary text")
   113  	time.Sleep(time.Second)
   114  	TPrintf("This message replace previous message after 1 sec")
   115  }
   116  
   117  func ExampleTLPrintf() {
   118  	// Power of TPrintf and LPrintf in one method
   119  	TLPrintf(22, "This is temporary text")
   120  	time.Sleep(time.Second)
   121  	TLPrintf(22, "This message replace previous message after 1 sec")
   122  }
   123  
   124  func ExampleLPrintf() {
   125  	// Only "This is text" will be shown
   126  	LPrintf(12, "{r}This is %s {g} with colors{!}", "text")
   127  }