Files
codex/codex-rs/tui/src/markdown_render/task_lists.rs
T
Ahmed Ibrahim e0ef5a1a0f Reduce generic code duplication in RPC and Markdown rendering (#47751)
## Why

RPC sending and waiting do not depend on request or response types, and Markdown layout does not depend on the parser iterator. Share these implementations across typed calls and parser variants.

## What changed

- Extract `RpcClient::send_request_and_wait` into a non-generic async method, preserving registration before serialization and disconnected-client error precedence.
- Remove the iterator type parameter from `Writer` and pass iterators to event traversal methods, retaining static dispatch and dropping the parser before rendering state, including on unwind.
- Update streaming rendering and existing rendering tests to use the separate parser.

GitOrigin-RevId: 4cc07223111b7c08211028948d13fe04598f8fc7
2026-09-24 04:48:03 +00:00

32 lines
1.2 KiB
Rust

//! Task-list checkboxes replace unordered bullets and retain ordered numbering.
//! Keep the hanging indent aligned with the task text, including in loose lists.
use super::Writer;
use ratatui::text::Span;
impl Writer<'_, '_> {
pub(super) fn task_list_marker(&mut self, checked: bool) {
let Some(context) = self
.indent_stack
.iter_mut()
.rev()
.find(|context| context.is_list)
else {
return;
};
if let Some(marker) = context.marker.as_mut()
&& let Some(span) = marker.last_mut()
{
let prefix = span.content.strip_suffix("• ").unwrap_or(&span.content);
let checkbox = if checked { "☑" } else { "☐" };
span.content = format!("{prefix}{checkbox} ").into();
context.prefix = vec![Span::from(" ".repeat(Self::spans_display_width(marker)))];
}
if self.current_line_content.is_some() {
// Loose lists start their paragraph before the task marker arrives.
self.current_initial_indent = self.prefix_spans(/*pending_marker_line*/ true);
self.current_subsequent_indent = self.prefix_spans(/*pending_marker_line*/ false);
}
}
}