Documentation
¶
Index ¶
- Constants
- func Highlight(original string, substring string, limit int, before string, after string, ...) string
- func HighlightColor(original string, substring string, limit int, color string, caseSensitive bool) string
- func HighlightSameReplacements(original string, substring string, limit int, replacement string, ...) string
Examples ¶
Constants ¶
const ( FgBlack string = "\x1b[30m" FgRed string = "\x1b[31m" FgGreen string = "\x1b[32m" FgYellow string = "\x1b[33m" FgBlue string = "\x1b[34m" FgMagenta string = "\x1b[35m" FgCyan string = "\x1b[36m" FgWhite string = "\x1b[37m" BgBlack string = "\x1b[40m" BgRed string = "\x1b[41m" BgGreen string = "\x1b[42m" BgYellow string = "\x1b[43m" BgBlue string = "\x1b[44m" BgMagenta string = "\x1b[45m" BgCyan string = "\x1b[46m" BgWhite string = "\x1b[47m" )
This is a small list of colors sourced from https://talyian.github.io/ansicolors/
As stated by the webpage, "Different consoles render these codes at different values"
You may pass your own strings as replacements to the functions if you want to have more color options.
Variables ¶
This section is empty.
Functions ¶
func Highlight ¶
func Highlight(original string, substring string, limit int, before string, after string, caseSensitive bool) string
Highlight prefixes up to `limit` occurrences of `substring` with `before` and suffixes up to `limit` occurrences of `substring` with `after`.
Highlight can optionally be case-sensitive.
Example ¶
fmt.Println(highlight.Highlight("Hello World!", "World", 1, "GitHub ", "", false))
Output: Hello GitHub World!
func HighlightColor ¶
func HighlightColor(original string, substring string, limit int, color string, caseSensitive bool) string
HighlightColor has the same functionality as Highlight, but prefixes and suffixes up to `limit` occurences of `substring` with the same text.
The `color` passed to HighlightColor does not have to strictly be a color. You may want to use `HighlightSameReplacements` to make usage of `go-highlight` more clear in your program if `color` is not a color.
Example ¶
// Colors can't be printed on the online Go documentation.
// You will have to run an example locally.
//
// You can copy this code example below for a quick test:
/*
package main
import (
"fmt"
"github.com/dieperdev/go-highlight"
)
func main() {
text := "Red, Yellow, and Blue."
highlighted := highlight.HighlightColor(text, "Yellow", 1, highlight.BgYellow, true)
fmt.Println(highlighted)
}
*/
fmt.Println(highlight.HighlightColor("Red, Yellow, and Blue.", "Yellow", 1, "Orange", true))
Output: Red, OrangeYellowOrange, and Blue.
func HighlightSameReplacements ¶
func HighlightSameReplacements(original string, substring string, limit int, replacement string, caseSensitive bool) string
HighlightSameReplacements has the same functionality as HighlightColor, but with different function name. It is intended to make usage of `go-highlight` more clear.
Example ¶
fmt.Println(highlight.HighlightSameReplacements("Go is a programming language.", "Go", 1, "*", true))
Output: *Go* is a programming language.
Types ¶
This section is empty.