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() }