Skip to content

Commit 88b9586

Browse files
build strings more efficiently
1 parent 677e47c commit 88b9586

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

render/view.go

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,12 @@ func (m rootModel) View() string {
151151
}
152152

153153
if m.result == api.VerificationResultSlugSuccess && m.isSubmit {
154-
str.WriteString("\n\n" + green.Render("All tests passed! 🎉") + "\n")
154+
str.WriteByte('\n')
155+
str.WriteByte('\n')
156+
str.WriteString(green.Render("All tests passed! 🎉"))
157+
str.WriteByte('\n')
155158
if m.xpReward >= 0 {
156-
str.WriteString("\n")
159+
str.WriteByte('\n')
157160
str.WriteString(green.Bold(true).Render(fmt.Sprintf("Gained +%d XP", m.xpReward)))
158161
str.WriteByte('\n')
159162
for _, item := range m.xpBreakdown {
@@ -174,26 +177,36 @@ func (m rootModel) View() string {
174177
str.WriteByte('\n')
175178
}
176179
}
177-
str.WriteString("\n" + green.Render("Return to your browser to continue with the next lesson.") + "\n\n")
180+
str.WriteByte('\n')
181+
str.WriteString(green.Render("Return to your browser to continue with the next lesson."))
182+
str.WriteByte('\n')
183+
str.WriteByte('\n')
178184
} else if m.result == api.VerificationResultSlugNoop {
179185
str.WriteString("\n\nTests failed! ❌")
180186
fmt.Fprintf(&str, "\n\nFailed Step: %v", m.failure.FailedStepIndex+1)
181-
str.WriteString("\nError: " + m.failure.ErrorMessage + "\n")
182-
str.WriteString("\n" + white.Render(safeStepIcon) + " This was a safe step.\n")
187+
str.WriteString("\nError: ")
188+
str.WriteString(m.failure.ErrorMessage)
189+
str.WriteByte('\n')
190+
str.WriteByte('\n')
191+
str.WriteString(white.Render(safeStepIcon))
192+
str.WriteString(" This was a safe step.\n")
183193
str.WriteString("You haven't passed, but you also haven't lost armor or Sharpshooter progress.\n\n")
184194
} else if m.result == api.VerificationResultSlugFailure {
185-
str.WriteString("\n\n" + red.Render("Tests failed! ❌"))
195+
str.WriteByte('\n')
196+
str.WriteByte('\n')
197+
str.WriteString(red.Render("Tests failed! ❌"))
186198
if m.failure != nil {
187199
if m.failure.FailedStepIndex >= 0 && m.failure.FailedStepIndex < len(m.steps) {
188-
fmt.Fprintf(&str, "%s", red.Render(fmt.Sprintf("\n\nFailed Command: %s", m.steps[m.failure.FailedStepIndex].step)))
200+
str.WriteString(red.Render(fmt.Sprintf("\n\nFailed Command: %s", m.steps[m.failure.FailedStepIndex].step)))
189201
}
190-
fmt.Fprintf(&str, "%s", red.Render(fmt.Sprintf("\n\nFailed Step: %v", m.failure.FailedStepIndex+1)))
191-
fmt.Fprintf(&str, "%s", red.Render("\nError: "+m.failure.ErrorMessage))
202+
str.WriteString(red.Render(fmt.Sprintf("\n\nFailed Step: %v", m.failure.FailedStepIndex+1)))
203+
str.WriteString(red.Render(fmt.Sprintf("\nError: %s", m.failure.ErrorMessage)))
192204
} else {
193-
fmt.Fprintf(&str, "%s", red.Render("\n\nFailed Step: unknown"))
194-
fmt.Fprintf(&str, "%s", red.Render("\nError: unknown"))
205+
str.WriteString(red.Render("\n\nFailed Step: unknown"))
206+
str.WriteString(red.Render("\nError: unknown"))
195207
}
196-
str.WriteString("\n\n")
208+
str.WriteByte('\n')
209+
str.WriteByte('\n')
197210
currentDate := time.Now().Format("2006-01-02")
198211
if strings.HasSuffix(currentDate, "04-01") {
199212
str.WriteString(magenta.Render(fmt.Sprintf("This incident has been reported to your system administrator. [%s]\n", currentDate)))

0 commit comments

Comments
 (0)