Something went wrong. Try again.
Browser extension: detect and subscribe to standard.site publications on ATProto substandard.blog
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586use anyhow::Result;
use crate::model::ThreadRow;
pub fn print_rows(rows: &[ThreadRow], include_author: bool, json: bool) -> Result<()> { if json { println!("{}", serde_json::to_string_pretty(rows)?); return Ok(()); } if rows.is_empty() { return Ok(()); }
let mut headers = Vec::new(); if include_author { headers.push("AUTHOR"); } headers.extend([ "ROOT DATE", "POSTS", "GRAPHEMES", "LIKES", "REPOSTS", "QUOTES", "REPLIES", "DROPPED", "CRAFT", "SCORE", "PUBLISHED", "URL", ]);
let mut table: Vec<Vec<String>> = Vec::with_capacity(rows.len()); for row in rows { let mut cells = Vec::new(); if include_author { cells.push(row.author.handle.clone()); } cells.extend([ row.root_date.clone(), row.post_count.to_string(), row.graphemes.to_string(), row.likes.to_string(), row.reposts.to_string(), row.quotes.to_string(), row.replies.to_string(), row.dropped_branches.to_string(), format!("{:.0}", row.craft.score * 100.0), format!("{:.1}", row.score), if row.published { "yes" } else { "-" }.to_string(), row.url.clone(), ]); table.push(cells); }
let mut widths: Vec<usize> = headers.iter().map(|header| header.len()).collect(); for row in &table { for (index, cell) in row.iter().enumerate() { widths[index] = widths[index].max(cell.chars().count()); } }
print_row(&headers, &widths); let rules: Vec<String> = widths.iter().map(|width| "-".repeat(*width)).collect(); print_row(&rules, &widths); for row in &table { print_row(row, &widths); } Ok(())}
fn print_row(cells: &[impl AsRef<str>], widths: &[usize]) { let mut line = String::new(); for (index, cell) in cells.iter().enumerate() { if index > 0 { line.push_str(" "); } line.push_str(cell.as_ref()); if index + 1 < cells.len() { let padding = widths[index].saturating_sub(cell.as_ref().chars().count()); line.push_str(&" ".repeat(padding)); } } println!("{line}");}