feat(debug): color enabled/disabled

This commit is contained in:
Jan De Dobbeleer 2023-01-17 17:01:51 +01:00 committed by Jan De Dobbeleer
parent 3ef7f1b481
commit 759a90f4e4

View file

@ -226,15 +226,15 @@ func (e *Engine) PrintDebug(startTime time.Time, version string) string {
// console title timing // console title timing
titleStartTime := time.Now() titleStartTime := time.Now()
title := e.getTitleTemplateText() title := e.getTitleTemplateText()
segmentTiming := &SegmentTiming{ consoleTitleTiming := &SegmentTiming{
name: "ConsoleTitle", name: "ConsoleTitle",
nameLength: 12, nameLength: 12,
active: len(e.Config.ConsoleTitleTemplate) > 0, active: len(e.Config.ConsoleTitleTemplate) > 0,
text: title, text: title,
duration: time.Since(titleStartTime), duration: time.Since(titleStartTime),
} }
largestSegmentNameLength := 12 largestSegmentNameLength := consoleTitleTiming.nameLength
segmentTimings = append(segmentTimings, segmentTiming) segmentTimings = append(segmentTimings, consoleTitleTiming)
// cache a pointer to the color cycle // cache a pointer to the color cycle
cycle = &e.Config.Cycle cycle = &e.Config.Cycle
// loop each segments of each blocks // loop each segments of each blocks
@ -247,11 +247,17 @@ func (e *Engine) PrintDebug(startTime time.Time, version string) string {
} }
} }
// pad the output so the tabs render correctly // 22 is the color for false/true and 7 is the reset color
largestSegmentNameLength += 7 largestSegmentNameLength += 22 + 7
for _, segment := range segmentTimings { for _, segment := range segmentTimings {
duration := segment.duration.Milliseconds() duration := segment.duration.Milliseconds()
segmentName := fmt.Sprintf("%s(%t)", segment.name, segment.active) var active string
if segment.active {
active = "\x1b[38;2;156;231;201mtrue\x1b[0m"
} else {
active = "\x1b[38;2;204;137;214mfalse\x1b[0m"
}
segmentName := fmt.Sprintf("%s(%s)", segment.name, active)
e.write(fmt.Sprintf("%-*s - %3d ms - %s\n", largestSegmentNameLength, segmentName, duration, segment.text)) e.write(fmt.Sprintf("%-*s - %3d ms - %s\n", largestSegmentNameLength, segmentName, duration, segment.text))
} }
e.write(fmt.Sprintf("\n\x1b[38;2;191;207;240m\x1b[1mRun duration:\x1b[0m %s\n", time.Since(startTime))) e.write(fmt.Sprintf("\n\x1b[38;2;191;207;240m\x1b[1mRun duration:\x1b[0m %s\n", time.Since(startTime)))