Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions cmd/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func submissionHandler(cmd *cobra.Command, args []string) error {
isSubmit := cmd.Name() == "submit" || forceSubmit

var lessonUUID string
var confirmedTitle string
if len(args) > 0 {
lessonUUID = args[0]
} else {
Expand All @@ -53,11 +54,12 @@ func submissionHandler(cmd *cobra.Command, args []string) error {
if isSubmit {
if !promptToContinue(
"Submitting next lesson:",
lessonLabel,
render.RenderLessonTitle(lessonLabel),
"Continue?",
) {
return errors.New("submission canceled")
}
confirmedTitle = lessonLabel
}
lessonUUID = nextLesson.LessonUUID
}
Expand All @@ -70,7 +72,9 @@ func submissionHandler(cmd *cobra.Command, args []string) error {
lessonTitle := fmt.Sprintf("%d.%d - %s", lesson.ChapterNumber, lesson.LessonNumber, lesson.Lesson.Title)
lessonAction := lessonRunAction(isSubmit, len(args) == 0)
reportValidationError := func(err error) error {
fmt.Printf("%s\n%s\n", lessonAction, lessonTitle)
if lessonTitle != confirmedTitle {
fmt.Printf("%s\n%s\n", lessonAction, lessonTitle)
}
return err
}
if lesson.Lesson.Type != "type_cli" {
Expand All @@ -87,9 +91,11 @@ func submissionHandler(cmd *cobra.Command, args []string) error {

overrideBaseURL := viper.GetString("override_base_url")
runContext := render.RunContext{
Action: lessonAction,
LessonTitle: lessonTitle,
BaseURL: data.BaseURLDefault,
BaseURL: data.BaseURLDefault,
}
if lessonTitle != confirmedTitle {
runContext.Action = lessonAction
runContext.LessonTitle = lessonTitle
}
if overrideBaseURL != "" {
runContext.BaseURL = overrideBaseURL
Expand Down
19 changes: 10 additions & 9 deletions render/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ type RunContext struct {
BaseURLOverridden bool
}

func RenderLessonTitle(title string) string {
return lipgloss.NewStyle().Bold(true).Render(title)
}

func renderRunHeader(context RunContext) string {
if context.LessonTitle == "" {
return ""
}
var str strings.Builder
action := context.Action
if action == "" {
action = "Running lesson:"
if context.LessonTitle != "" {
fmt.Fprintln(&str, context.Action)
fmt.Fprintln(&str, RenderLessonTitle(context.LessonTitle))
}
fmt.Fprintln(&str, action)
fmt.Fprintln(&str, lipgloss.NewStyle().Bold(true).Render(context.LessonTitle))
if context.BaseURL != "" {
if context.BaseURLOverridden {
fmt.Fprintf(&str, "%s %s\n", warningStyle.Render("Using overridden base_url:"), context.BaseURL)
Expand All @@ -33,6 +32,8 @@ func renderRunHeader(context RunContext) string {
fmt.Fprintf(&str, "%s %s\n", secondaryStyle.Render("base_url:"), context.BaseURL)
}
}
str.WriteByte('\n')
if str.Len() > 0 {
str.WriteByte('\n')
}
return str.String()
}
2 changes: 1 addition & 1 deletion render/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type stepModel struct {
}

type rootModel struct {
runContext RunContext
runHeader string
terminalWidth int
steps []stepModel
spinner spinner.Model
Expand Down
2 changes: 1 addition & 1 deletion render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func StartRenderer(isSubmit bool, verbose bool, showOmitLessonIDTip bool, runCon
if terminalWidth, _, err := term.GetSize(int(os.Stdout.Fd())); err == nil {
m.terminalWidth = terminalWidth
}
m.runContext = runContext
m.runHeader = renderRunHeader(runContext)
m.showOmitLessonIDTip = showOmitLessonIDTip
interactive := term.IsTerminal(int(os.Stdin.Fd())) && term.IsTerminal(int(os.Stdout.Fd()))
options := []tea.ProgramOption{tea.WithoutSignalHandler(), tea.WithInput(nil)}
Expand Down
4 changes: 1 addition & 3 deletions render/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (m rootModel) View() string {
}
s := m.spinner.View()
var str strings.Builder
str.WriteString(renderRunHeader(m.runContext))
str.WriteString(m.runHeader)
failedStepIndex := -1
if m.isSubmit && m.failure != nil && m.failure.FailedStepIndex >= 0 && m.failure.FailedStepIndex < len(m.steps) {
failedStepIndex = m.failure.FailedStepIndex
Expand Down Expand Up @@ -125,8 +125,6 @@ func (m rootModel) View() string {
str.WriteByte('\n')
str.WriteByte('\n')
} else if m.isSubmit && m.result == api.VerificationResultSlugNoop {
str.WriteByte('\n')
str.WriteByte('\n')
str.WriteString(informationStyle.Render(safeStepIcon) + " " + informationStyle.Render("This was a safe step.") + "\n")
str.WriteString("You haven't passed, but you also haven't lost armor or Sharpshooter progress.\n\n")
}
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.33.0
v1.33.1
Loading