Пример #1
0
func (f *Formatter) formatLinePrefix(line *gc.DiffLine) string {
	switch line.Type {
	case gc.DiffAdd, gc.DiffAddNewline:
		return gx.Colorize(gx.Green, "+", f.useColor)
	case gc.DiffRemove, gc.DiffRemoveNewline:
		return gx.Colorize(gx.Red, "-", f.useColor)
	default:
		return " "
	}
}
Пример #2
0
func (f *Formatter) formatLineContent(line *gc.DiffLine) string {
	switch line.Type {
	case gc.DiffAddNewline, gc.DiffRemoveNewline:
		return "↵"
	case gc.DiffAdd:
		return gx.Colorize(gx.Green, line.Content, f.useColor)
	case gc.DiffRemove:
		return gx.Colorize(gx.Red, line.Content, f.useColor)
	default:
		return line.Content
	}
}
Пример #3
0
func (f *Formatter) formatLineNumbers(oldNum, newNum int) string {
	if !f.useLineNumbers {
		return ""
	}
	var newLine string
	oldLine := f.formatLineNumber(oldNum)
	if oldNum == newNum || newNum == -1 {
		newLine = f.formatLineNumber(-1)
	} else {
		newLine = gx.Colorize(gx.Green, f.formatLineNumber(newNum), f.useColor)
	}
	if oldNum != -1 {
		oldLine = gx.Colorize(gx.Red, oldLine, f.useColor)
	}
	return fmt.Sprintf("%v%v", oldLine, newLine)
}
Пример #4
0
func (f *Formatter) formatTitle(c *gc.Comment, highlight string) string {
	lines := strings.Split(c.Content, "\n")
	title := lines[0]
	if len(lines) > 1 {
		title = fmt.Sprintf("%v...", title)
	}
	if f.useColor {
		title = strings.Replace(title, highlight, gx.Colorize(gx.Red, highlight, true), -1)
	}
	return title
}
Пример #5
0
func (f *Formatter) FormatComment(c *gc.Comment, highlight string) string {
	return fmt.Sprintf("%v  %v\n",
		gx.Colorize(gx.Cyan, f.formatHeader(c), f.useColor),
		f.formatTitle(c, highlight))
}