refactor: Remove obsolete documentation files and unused test for mouse functionality

This commit is contained in:
asepharyana
2026-07-15 04:36:00 +07:00
parent 4428e8bc01
commit 9bf5236680
7 changed files with 106 additions and 314 deletions
+106 -20
View File
@@ -37,7 +37,6 @@ pub fn render_markdown(text: &str, width: u16) -> Vec<Span<'static>> {
let mut in_heading = false;
let mut heading_level = 0;
let mut in_table = false;
let mut in_table_cell = false;
let mut table_rows: Vec<Vec<Vec<Span<'static>>>> = Vec::new();
let mut current_row: Vec<Vec<Span<'static>>> = Vec::new();
@@ -99,7 +98,6 @@ pub fn render_markdown(text: &str, width: u16) -> Vec<Span<'static>> {
));
}
pulldown_cmark::Tag::Table(_) => {
in_table = true;
table_rows.clear();
}
pulldown_cmark::Tag::TableHead | pulldown_cmark::Tag::TableRow => {
@@ -141,38 +139,68 @@ pub fn render_markdown(text: &str, width: u16) -> Vec<Span<'static>> {
table_rows.push(std::mem::take(&mut current_row));
}
pulldown_cmark::TagEnd::Table => {
in_table = false;
let mut col_widths = Vec::new();
let cols_count = table_rows.first().map(|r| r.len()).unwrap_or(0);
if cols_count == 0 {
continue;
}
let mut col_widths = vec![0; cols_count];
for row in &table_rows {
for (i, cell) in row.iter().enumerate() {
let width: usize = cell.iter().map(|s| s.content.chars().count()).sum();
if i >= col_widths.len() {
col_widths.push(width);
} else if width > col_widths[i] {
col_widths[i] = width;
if i < cols_count {
let cell_width: usize = cell.iter().map(|s| s.content.chars().count()).sum();
if cell_width > col_widths[i] {
col_widths[i] = cell_width;
}
}
}
}
let effective_width = if width > 0 { (width as usize).saturating_sub(2) } else { 0 };
let border_overhead = cols_count * 3 + 4;
let available_width = effective_width.saturating_sub(border_overhead);
let mut total_width: usize = col_widths.iter().sum();
if width > 0 && total_width > available_width && available_width > 0 {
while total_width > available_width {
let max_idx = col_widths.iter().enumerate().max_by_key(|&(_, &w)| w).map(|(i, _)| i).unwrap();
if col_widths[max_idx] <= 3 { break; }
col_widths[max_idx] -= 1;
total_width -= 1;
}
}
spans.push(Span::raw("\n"));
for (r, row) in table_rows.iter().enumerate() {
spans.push(Span::styled(" | ", Style::default().fg(Theme::BORDER)));
let mut cell_lines = Vec::new();
for (i, cell) in row.iter().enumerate() {
let width: usize = cell.iter().map(|s| s.content.chars().count()).sum();
let pad = col_widths.get(i).copied().unwrap_or(0).saturating_sub(width);
for span in cell {
spans.push(span.clone());
if i < cols_count {
cell_lines.push(wrap_spans_to_lines(cell, col_widths[i]));
}
spans.push(Span::raw(" ".repeat(pad)));
spans.push(Span::styled(" | ", Style::default().fg(Theme::BORDER)));
}
spans.push(Span::raw("\n"));
let max_height = cell_lines.iter().map(|cl| cl.len()).max().unwrap_or(1);
for y in 0..max_height {
spans.push(Span::styled(" | ", Style::default().fg(Theme::BORDER)));
for (i, cl) in cell_lines.iter().enumerate() {
let line_spans = if y < cl.len() { &cl[y] } else { [].as_slice() };
let mut line_width = 0;
for span in line_spans {
line_width += span.content.chars().count();
spans.push(span.clone());
}
let pad = col_widths[i].saturating_sub(line_width);
spans.push(Span::raw(" ".repeat(pad)));
spans.push(Span::styled(" | ", Style::default().fg(Theme::BORDER)));
}
spans.push(Span::raw("\n"));
}
if r == 0 {
spans.push(Span::styled(" |", Style::default().fg(Theme::BORDER)));
for width in &col_widths {
spans.push(Span::styled(format!("{}-|", "-".repeat(*width + 2)), Style::default().fg(Theme::BORDER)));
for w in &col_widths {
spans.push(Span::styled(format!("{}-|", "-".repeat(*w + 2)), Style::default().fg(Theme::BORDER)));
}
spans.push(Span::raw("\n"));
}
@@ -291,3 +319,61 @@ pub fn render_markdown(text: &str, width: u16) -> Vec<Span<'static>> {
spans
}
fn wrap_spans_to_lines(spans: &[Span<'static>], target_width: usize) -> Vec<Vec<Span<'static>>> {
let mut lines = Vec::new();
let mut current_line = Vec::new();
let mut line_len = 0;
for span in spans {
let style = span.style;
let text = span.content.as_ref();
let mut current_word = String::new();
let mut tokens = Vec::new();
for c in text.chars() {
if c == ' ' {
if !current_word.is_empty() { tokens.push(current_word.clone()); current_word.clear(); }
tokens.push(" ".to_string());
} else {
current_word.push(c);
}
}
if !current_word.is_empty() { tokens.push(current_word); }
for token in tokens {
if token == " " {
if line_len > 0 && line_len < target_width {
current_line.push(Span::styled(" ", style));
line_len += 1;
}
} else {
let token_len = token.chars().count();
if line_len + token_len > target_width && line_len > 0 {
lines.push(std::mem::take(&mut current_line));
line_len = 0;
}
if token_len > target_width {
for c in token.chars() {
if target_width > 0 && line_len >= target_width {
lines.push(std::mem::take(&mut current_line));
line_len = 0;
}
current_line.push(Span::styled(c.to_string(), style));
line_len += 1;
}
} else {
current_line.push(Span::styled(token, style));
line_len += token_len;
}
}
}
}
if !current_line.is_empty() {
lines.push(current_line);
}
if lines.is_empty() {
lines.push(vec![]);
}
lines
}