Beispiel #1
0
func lineNumber(c *ansi.Colorer, buf *bytes.Buffer, n int, hasMatch bool) string {
	defer buf.Reset()

	s := fmt.Sprintf("%d", n)
	buf.WriteString(c.Fg(s, ansi.Yellow, ansi.Bold))
	if hasMatch {
		buf.WriteByte(':')
	} else {
		buf.WriteByte('-')
	}
	for i := len(s); i < 6; i++ {
		buf.WriteByte(' ')
	}
	return buf.String()
}
Beispiel #2
0
func hiliteMatches(c *ansi.Colorer, p *regexp.Regexp, line string) string {
	// find the indexes for all matches
	idxs := p.FindAllStringIndex(line, -1)

	var buf bytes.Buffer
	beg := 0

	for _, idx := range idxs {
		// for each match add the contents before the match ...
		buf.WriteString(line[beg:idx[0]])
		// and the highlighted version of the match
		buf.WriteString(c.FgBg(line[idx[0]:idx[1]],
			ansi.Black,
			ansi.Bold,
			ansi.Yellow,
			ansi.Intense))
		beg = idx[1]
	}

	buf.WriteString(line[beg:])

	return buf.String()
}