| 138 | // ============================================================================= |
| 139 | |
| 140 | const toAnsiDocInternal = (self: HelpDoc.HelpDoc): Doc.AnsiDoc => { |
| 141 | switch (self._tag) { |
| 142 | case "Empty": { |
| 143 | return Doc.empty |
| 144 | } |
| 145 | case "Header": { |
| 146 | return pipe( |
| 147 | Doc.annotate(InternalSpan.toAnsiDoc(self.value), Ansi.bold), |
| 148 | Doc.cat(Doc.hardLine) |
| 149 | ) |
| 150 | } |
| 151 | case "Paragraph": { |
| 152 | return pipe( |
| 153 | InternalSpan.toAnsiDoc(self.value), |
| 154 | Doc.cat(Doc.hardLine) |
| 155 | ) |
| 156 | } |
| 157 | case "DescriptionList": { |
| 158 | const definitions = self.definitions.map(([span, doc]) => |
| 159 | Doc.cats([ |
| 160 | Doc.annotate(InternalSpan.toAnsiDoc(span), Ansi.bold), |
| 161 | Doc.empty, |
| 162 | Doc.indent(toAnsiDocInternal(doc), 2) |
| 163 | ]) |
| 164 | ) |
| 165 | return Doc.vsep(definitions) |
| 166 | } |
| 167 | case "Enumeration": { |
| 168 | const elements = self.elements.map((doc) => Doc.cat(Doc.text("- "), toAnsiDocInternal(doc))) |
| 169 | return Doc.indent(Doc.vsep(elements), 2) |
| 170 | } |
| 171 | case "Sequence": { |
| 172 | return Doc.vsep([ |
| 173 | toAnsiDocInternal(self.left), |
| 174 | toAnsiDocInternal(self.right) |
| 175 | ]) |
| 176 | } |
| 177 | } |
| 178 | } |