pkg.re/essentialkaos/ek.10@v12.41.0+incompatible/ansi/examples_test.go (about) 1 package ansi 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 ) 13 14 // ////////////////////////////////////////////////////////////////////////////////// // 15 16 func Example_HasCodes() { 17 input := "Hello" 18 fmt.Println(HasCodes(input)) 19 20 input = "\033[40;38;5;82mHello\x1B[0m" 21 fmt.Println(HasCodes(input)) 22 23 // Output: 24 // false 25 // true 26 } 27 28 func Example_HasCodesBytes() { 29 input := []byte("Hello") 30 fmt.Println(HasCodesBytes(input)) 31 32 input = []byte("\033[40;38;5;82mHello\x1B[0m") 33 fmt.Println(HasCodesBytes(input)) 34 35 // Output: 36 // false 37 // true 38 } 39 40 func Example_RemoveCodes() { 41 input := "\033[40;38;5;82mHello\x1B[0m" 42 fmt.Println(RemoveCodes(input)) 43 // Output: 44 // Hello 45 } 46 47 func Example_RemoveCodesBytes() { 48 input := []byte("\033[40;38;5;82mHello\x1B[0m") 49 fmt.Println(string(RemoveCodesBytes(input))) 50 // Output: 51 // Hello 52 }