├── LICENSE
├── doc.go
├── fmtc.go
├── README.md
├── decorator.go
└── fmtc_test.go
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Pronin S.V.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017 Pronin S.V.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | /*
6 | The fmtc overrides the print functions of the fmt package, but with the ability to color output in bash using HTML tags
7 |
8 | Available text decoration tags:
9 | - make font Bold
10 | - make font Bold
11 | - make text Underlined
12 | - make font Dim
13 | - Reverse background anf font color
14 | - make text Blink (not working on Mint/Ubuntu)
15 | - set font color Black (Dark)
16 | - set font color Red
17 | - set font color Green
18 | - set font color Yellow
19 | - set font color Blue
20 | - set font color Magenta
21 | - set font color Cyan
22 | - set font color Grey (Smokey)
23 | - set font color White
24 |
25 | Available background colors tags:
26 | - black background color
27 | - red background color
28 | - green background color
29 | - yellow background color
30 | - blue background color
31 | - magenta background color
32 | - cyan background color
33 | - grey background color
34 | - white background color
35 |
36 | - black background color
37 | - red background color
38 | - green background color
39 | - yellow background color
40 | - blue background color
41 | - magenta background color
42 | - cyan background color
43 | - grey background color
44 | - white background color
45 |
46 | Examples:
47 |
48 | fmtc.Print("HELLO WORLD")
49 | fmtc.Println("HELLO WORLD")
50 | fmtc.Printf("%v: %v", name, result)
51 | */
52 |
53 | package fmtc
54 |
--------------------------------------------------------------------------------
/fmtc.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017 Pronin S.V.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package fmtc
6 |
7 | import (
8 | "fmt"
9 | "io"
10 | )
11 |
12 | // Fprint formats using the default formats for its operands and writes to w.
13 | // Spaces are added between operands when neither is a string.
14 | // It returns the number of bytes written and any write error encountered.
15 | func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
16 | decorateIface(&a)
17 | return fmt.Fprint(w, a...)
18 | }
19 |
20 | // Fprintln formats using the default formats for its operands and writes to w.
21 | // Spaces are always added between operands and a newline is appended.
22 | // It returns the number of bytes written and any write error encountered.
23 | func Fprintln(w io.Writer, a ...interface{}) (n int, err error) {
24 | decorateIface(&a)
25 | return fmt.Fprintln(w, a...)
26 | }
27 |
28 | // Fprintf formats according to a format specifier and writes to w.
29 | // It returns the number of bytes written and any write error encountered.
30 | func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) {
31 | return fmt.Fprintf(w, decorate(format), a...)
32 | }
33 |
34 | // Print formats using the default formats for its operands and writes to standard output.
35 | // Spaces are added between operands when neither is a string.
36 | // It returns the number of bytes written and any write error encountered.
37 | func Print(a ...interface{}) (n int, err error) {
38 | decorateIface(&a)
39 | return fmt.Print(a...)
40 | }
41 |
42 | // Printf formats according to a format specifier and writes to standard output.
43 | // It returns the number of bytes written and any write error encountered.
44 | func Printf(format string, a ...interface{}) (n int, err error) {
45 | return fmt.Printf(decorate(format), a...)
46 | }
47 |
48 | // Println formats using the default formats for its operands and writes to standard output.
49 | // Spaces are always added between operands and a newline is appended.
50 | // It returns the number of bytes written and any write error encountered.
51 | func Println(a ...interface{}) (n int, err error) {
52 | decorateIface(&a)
53 | return fmt.Println(a...)
54 | }
55 |
56 | // Sprint formats using the default formats for its operands and returns the resulting string.
57 | // Spaces are added between operands when neither is a string.
58 | func Sprint(a ...interface{}) string {
59 | decorateIface(&a)
60 | return fmt.Sprint(a...)
61 | }
62 |
63 | // Sprintf formats according to a format specifier and returns the resulting string.
64 | func Sprintf(format string, a ...interface{}) string {
65 | return fmt.Sprintf(decorate(format), a...)
66 | }
67 |
68 | // Sprintln formats using the default formats for its operands and returns the resulting string.
69 | // Spaces are always added between operands and a newline is appended.
70 | func Sprintln(a ...interface{}) string {
71 | decorateIface(&a)
72 | return fmt.Sprintln(a...)
73 | }
74 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # fmtc
2 | The fmtc overrides the print functions of the fmt package, but with the ability to color output in bash using HTML tags
3 |
4 | ### Available text decoration tags
5 |
6 | ```
7 | - make font Bold
8 | - make font Bold
9 | - make text Underlined
10 | - make font Dim
11 | - Reverse background and font color
12 | - make text Blink (not working on Mint/Ubuntu)
13 | - set font color Black (Dark)
14 | - set font color Red
15 | - set font color Green
16 | - set font color Yellow
17 | - set font color Blue
18 | - set font color Magenta
19 | - set font color Cyan
20 | - set font color Grey (Smokey)
21 | - set font color White
22 | ```
23 | ### Available background colors tags:
24 | ```
25 | - black background color
26 | - red background color
27 | - green background color
28 | - yellow background color
29 | - blue background color
30 | - magenta background color
31 | - cyan background color
32 | - grey background color
33 | - white background color
34 |
35 | - black background color
36 | - red background color
37 | - green background color
38 | - yellow background color
39 | - blue background color
40 | - magenta background color
41 | - cyan background color
42 | - grey background color
43 | - white background color
44 | ```
45 |
46 | ### Install:
47 | ```bash
48 | go get github.com/Pronin1986/fmtc
49 | ```
50 |
51 | ### Usage:
52 | ```golang
53 | fmtc.Print(`HELLO BLUE TEXT`)
54 | fmtc.Println(`HELLO BLUE TEXT`)
55 | fmtc.Printf(`%v %v %v`, "HELLO", "BLUE", "TEXT")
56 | ```
57 |
58 | ```golang
59 | got: = fmtc.Sprint(`HELLO BLUE TEXT`)
60 | got = fmtc.Sprintln(`HELLO BLUE TEXT`)
61 | got = fmtc.Sprintf(`%v %v %v`, "HELLO", "BLUE", "TEXT")
62 | ```
63 |
64 | ```golang
65 | buf := new(bytes.Buffer)
66 | fmtc.Fprint(buf, `HELLO BLUE TEXT`)
67 | fmtc.Fprintln(buf, `HELLO BLUE TEXT`)
68 | fmtc.Fprintf(buf, `%v %v %v`, "HELLO", "BLUE", "TEXT")
69 | ```
70 |
71 | You have already decorated text for console output like a picture above:
72 |
73 | 
74 |
75 | ### Example:
76 |
77 | ```golang
78 | package main
79 |
80 | import (
81 | "fmt"
82 |
83 | "github.com/Pronin1986/fmtc"
84 | )
85 |
86 | func main() {
87 | fmt.Println("HELLO WORLD")
88 | fmtc.Println("HELLO WORLD")
89 | }
90 | ```
91 |
92 | 
93 |
94 |
--------------------------------------------------------------------------------
/decorator.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017 Pronin S.V.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package fmtc
6 |
7 | import (
8 | "regexp"
9 | "strings"
10 | "unicode/utf8"
11 |
12 | "golang.org/x/net/html"
13 | )
14 |
15 | const (
16 | //CODERESET reset style after this code
17 | CODERESET = "\033[0m"
18 | )
19 |
20 | // An array of tag and ASCI code matches for text
21 | var fontStyle = map[string]string{
22 | "b": "1", // - Bold
23 | "strong": "1", // - Bold
24 | "u": "4", // - Underline
25 | "dim": "2", // - Dim
26 | "reverse": "7", // - Reverse
27 | "blink": "5", //