Files
dev/code-rs/tui/src/text_processing.rs
T
James PeterandClaude 72437dddb6 chore: complete legacy test retirement and upstream crate adoption
This commit completes Phase 1 of the codebase cleanup plan documented in
ROADMAP.md and related migration documents.

Major changes:
- Removed legacy test suites from code-rs/ crates (~35,000 lines)
- Adopted upstream codex-mcp-client and codex-responses-api-proxy
- Deleted TUI compat layer, agent task planning docs, and orphaned modules
- Updated documentation to reflect current state and future phases

Test Coverage:
- Deleted tests from: app-server, apply-patch, chatgpt, cli, core, exec,
  login, mcp-server
- Documented 9 remaining coverage gaps requiring new tests (see
  docs/migration/legacy-tests-retirement.md)
- Preserved smoke test infrastructure in tui/tests/ui_smoke.rs

Crate Adoptions:
- mcp-client: Now re-exports codex-mcp-client with fork-specific buffer config
- responses-api-proxy: Now re-exports codex-responses-api-proxy with minimal
  wrapper
- mcp-types: Updated to use upstream types where possible

TUI Cleanup:
- Removed compat.rs ratatui adapter layer
- Deleted obsolete modules: app_backtrack, custom_terminal, scroll_view,
  text_block, transcript_app
- Archived agent_tasks/ planning docs to docs/archive/

Documentation Updates:
- ROADMAP.md: Marked Phases 1-2 complete, updated next actions
- TEST_SUITE_RESET.md: Documented Phase 1 completion
- DEAD_CODE_INVENTORY.md: Updated with deletion outcomes
- Added docs/migration/legacy-tests-retirement.md with 6-week plan
- Added docs/maintenance/prompt-architecture.md

Next Steps (Phase 2-3):
- Port critical test coverage (9 test files identified)
- Expand smoke test scenarios
- Continue upstream tracking per monthly cadence

See docs/migration/ for detailed migration status and roadmap.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
2025-10-06 05:15:48 +10:00

131 lines
4.0 KiB
Rust

use ratatui::prelude::*;
use ratatui::style::Modifier;
use ratatui::style::Style;
/// Process text with basic markdown support
#[allow(dead_code)]
pub(crate) fn process_markdown_text(text: &str, _width: u16) -> Vec<Line<'static>> {
let mut lines = Vec::new();
// Split by newlines but preserve empty lines (text.lines() skips empty lines!)
for line in text.split('\n') {
lines.push(parse_markdown_line(line));
}
lines
}
/// Process text with markdown support and apply dimming to all text
#[allow(dead_code)]
pub(crate) fn process_dimmed_markdown_text(text: &str, width: u16) -> Vec<Line<'static>> {
let lines = process_markdown_text(text, width);
// Remove empty lines that immediately follow bold titles (common in thinking content)
let mut filtered_lines = Vec::new();
let mut last_was_bold_title = false;
for line in &lines {
let is_empty =
line.spans.is_empty() || (line.spans.len() == 1 && line.spans[0].content.is_empty());
// Check if this line has bold content (likely a title)
let has_bold = line.spans.iter().any(|span| {
span.style
.add_modifier
.contains(ratatui::style::Modifier::BOLD)
});
// Skip empty lines that come right after bold titles
if is_empty && last_was_bold_title {
last_was_bold_title = false; // Reset flag
continue; // Skip this empty line
}
filtered_lines.push(line.clone());
last_was_bold_title = has_bold;
}
// Apply dimming to all spans in all remaining lines
filtered_lines
.into_iter()
.map(|line| {
let dimmed_spans: Vec<_> = line
.spans
.into_iter()
.map(|span| {
// Apply dim color while preserving other styling (bold, etc.)
ratatui::text::Span::styled(
span.content,
span.style.fg(crate::colors::text_dim()),
)
})
.collect();
ratatui::text::Line::from(dimmed_spans)
})
.collect()
}
/// Parse a single line with markdown formatting
#[allow(dead_code)]
fn parse_markdown_line(text: &str) -> Line<'static> {
let mut spans = Vec::new();
let mut current_text = String::new();
let mut chars = text.chars().peekable();
while let Some(ch) = chars.next() {
if ch == '*' && chars.peek() == Some(&'*') {
// Found **bold** marker
chars.next(); // consume second *
// Save any accumulated text
if !current_text.is_empty() {
spans.push(Span::styled(
current_text.clone(),
Style::default().fg(crate::colors::text()),
));
current_text.clear();
}
// Find the closing **
let mut bold_text = String::new();
let mut found_closing = false;
while let Some(ch) = chars.next() {
if ch == '*' && chars.peek() == Some(&'*') {
chars.next(); // consume second *
found_closing = true;
break;
}
bold_text.push(ch);
}
if found_closing && !bold_text.is_empty() {
spans.push(Span::styled(
bold_text,
Style::default()
.fg(crate::colors::text_bright())
.add_modifier(Modifier::BOLD),
));
} else {
// No closing **, treat as regular text
current_text.push_str("**");
current_text.push_str(&bold_text);
}
} else {
current_text.push(ch);
}
}
// Handle remaining text
if !current_text.is_empty() {
spans.push(Span::styled(
current_text,
Style::default().fg(crate::colors::text()),
));
}
Line::from(spans)
}