(data api.CLIData, isSubmit bool, ch chan tea.Msg)
| 98 | } |
| 99 | |
| 100 | func StartRenderer(data api.CLIData, isSubmit bool, ch chan tea.Msg) func(api.LessonSubmissionEvent) { |
| 101 | var wg sync.WaitGroup |
| 102 | p := tea.NewProgram(initModel(isSubmit), tea.WithoutSignalHandler()) |
| 103 | |
| 104 | wg.Add(1) |
| 105 | go func() { |
| 106 | defer wg.Done() |
| 107 | if model, err := p.Run(); err != nil { |
| 108 | fmt.Fprintln(os.Stderr, err) |
| 109 | } else if r, ok := model.(rootModel); ok { |
| 110 | r.clear = false |
| 111 | r.finalized = true |
| 112 | output := termenv.NewOutput(os.Stdout) |
| 113 | output.WriteString(r.View()) |
| 114 | } |
| 115 | }() |
| 116 | |
| 117 | go func() { |
| 118 | for { |
| 119 | msg := <-ch |
| 120 | p.Send(msg) |
| 121 | } |
| 122 | }() |
| 123 | |
| 124 | return func(submissionEvent api.LessonSubmissionEvent) { |
| 125 | ch <- messages.DoneStepMsg{ |
| 126 | Result: submissionEvent.ResultSlug, |
| 127 | Failure: submissionEvent.StructuredErrCLI, |
| 128 | XPReward: submissionEvent.XPReward, |
| 129 | XPBreakdown: submissionEvent.XPBreakdown, |
| 130 | } |
| 131 | wg.Wait() |
| 132 | } |
| 133 | } |
no test coverage detected