Process any actions in this printer's queue until the queue is empty.
(&mut self)
| 310 | |
| 311 | /// Process any actions in this printer's queue until the queue is empty. |
| 312 | fn run_action_queue(&mut self) -> FormatResult<()> { |
| 313 | while let Some(action) = self.action_queue.pop_front() { |
| 314 | match action { |
| 315 | CodeExampleAddAction::Print { original } => { |
| 316 | self.print_one(&original.as_output())?; |
| 317 | } |
| 318 | CodeExampleAddAction::Kept => {} |
| 319 | CodeExampleAddAction::Reset { code } => { |
| 320 | for codeline in code { |
| 321 | self.print_one(&codeline.original.as_output())?; |
| 322 | } |
| 323 | } |
| 324 | CodeExampleAddAction::Format { mut kind } => { |
| 325 | let Some(formatted_lines) = self.format(&mut kind)? else { |
| 326 | // Since we've failed to emit these lines, we need to |
| 327 | // put them back in the queue but have them jump to the |
| 328 | // front of the queue to get processed before any other |
| 329 | // action. |
| 330 | self.action_queue.push_front(CodeExampleAddAction::Reset { |
| 331 | code: kind.into_code(), |
| 332 | }); |
| 333 | continue; |
| 334 | }; |
| 335 | |
| 336 | self.already_normalized = false; |
| 337 | match kind { |
| 338 | CodeExampleKind::Doctest(CodeExampleDoctest { ps1_indent, .. }) => { |
| 339 | let mut lines = formatted_lines.into_iter(); |
| 340 | let Some(first) = lines.next() else { continue }; |
| 341 | self.print_one( |
| 342 | &first.map(|line| std::format!("{ps1_indent}>>> {line}")), |
| 343 | )?; |
| 344 | for docline in lines { |
| 345 | self.print_one( |
| 346 | &docline.map(|line| std::format!("{ps1_indent}... {line}")), |
| 347 | )?; |
| 348 | } |
| 349 | } |
| 350 | CodeExampleKind::Rst(litblock) => { |
| 351 | let Some(min_indent) = litblock.min_indent else { |
| 352 | continue; |
| 353 | }; |
| 354 | // This looks suspicious, but it's consistent with the whitespace |
| 355 | // normalization that will occur anyway. |
| 356 | let indent = " ".repeat(min_indent.columns()); |
| 357 | for docline in formatted_lines { |
| 358 | self.print_one( |
| 359 | &docline.map(|line| std::format!("{indent}{line}")), |
| 360 | )?; |
| 361 | } |
| 362 | } |
| 363 | CodeExampleKind::Markdown(fenced) => { |
| 364 | // This looks suspicious, but it's consistent with the whitespace |
| 365 | // normalization that will occur anyway. |
| 366 | let indent = " ".repeat(fenced.opening_fence_indent.columns()); |
| 367 | for docline in formatted_lines { |
| 368 | self.print_one( |
| 369 | &docline.map(|line| std::format!("{indent}{line}")), |