summaryrefslogtreecommitdiffstats
path: root/adenosine-cli/src/pretty.rs
diff options
context:
space:
mode:
Diffstat (limited to 'adenosine-cli/src/pretty.rs')
-rw-r--r--adenosine-cli/src/pretty.rs98
1 files changed, 98 insertions, 0 deletions
diff --git a/adenosine-cli/src/pretty.rs b/adenosine-cli/src/pretty.rs
new file mode 100644
index 0000000..306c056
--- /dev/null
+++ b/adenosine-cli/src/pretty.rs
@@ -0,0 +1,98 @@
+use adenosine::app_bsky::PostView;
+use anyhow::Result;
+use std::io::Write;
+use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
+
+pub fn pp_post_view(pv: &PostView) -> Result<()> {
+ let mut stdout = StandardStream::stdout(ColorChoice::Always);
+ stdout.set_color(ColorSpec::new().set_fg(Some(Color::Yellow)).set_bold(true))?;
+
+ write!(&mut stdout, "@{:<54.54}", pv.author.handle)?;
+ stdout.reset()?;
+ stdout.set_color(ColorSpec::new().set_dimmed(true))?;
+ writeln!(&mut stdout, "{}", pv.indexedAt)?;
+ stdout.reset()?;
+
+ write!(&mut stdout, " ")?;
+ if let Some(entities) = &pv.record.entities {
+ let mut cur: usize = 0;
+ for ent in entities {
+ write!(
+ &mut stdout,
+ "{}",
+ &pv.record.text[cur..ent.index.start as usize]
+ )?;
+ match ent.r#type.as_str() {
+ "mention" => stdout
+ .set_color(ColorSpec::new().set_fg(Some(Color::Magenta)).set_bold(true))?,
+ "hashtag" => {
+ stdout.set_color(ColorSpec::new().set_fg(Some(Color::Cyan)).set_bold(true))?
+ }
+ "link" => stdout.set_color(
+ ColorSpec::new()
+ .set_fg(Some(Color::Blue))
+ .set_underline(true),
+ )?,
+ _ => {}
+ }
+ write!(
+ &mut stdout,
+ "{}",
+ &pv.record.text[ent.index.start as usize..ent.index.end as usize]
+ )?;
+ stdout.reset()?;
+ cur = ent.index.end as usize;
+ }
+ writeln!(&mut stdout, "{}", &pv.record.text[cur..])?;
+ } else if !pv.record.text.is_empty() {
+ writeln!(&mut stdout, "{}", &pv.record.text)?;
+ }
+
+ if let Some(embed) = &pv.embed {
+ if let Some(ext) = &embed.external {
+ let desc = format!("{}: {}", ext.title, ext.description);
+ stdout.set_color(
+ ColorSpec::new()
+ .set_fg(Some(Color::Green))
+ .set_dimmed(true)
+ .set_underline(false),
+ )?;
+ writeln!(&mut stdout, " {:<70.70}", desc)?;
+ write!(&mut stdout, " ")?;
+ stdout.set_color(
+ ColorSpec::new()
+ .set_fg(Some(Color::Green))
+ .set_dimmed(true)
+ .set_underline(true),
+ )?;
+ writeln!(&mut stdout, "{}", &ext.uri)?;
+ stdout.reset()?;
+ }
+ if let Some(images) = &embed.images {
+ for img in images.iter() {
+ if !img.alt.is_empty() {
+ stdout.set_color(
+ ColorSpec::new()
+ .set_fg(Some(Color::Green))
+ .set_dimmed(true)
+ .set_underline(false),
+ )?;
+ writeln!(&mut stdout, " {:<70.70}", img.alt)?;
+ }
+ write!(&mut stdout, " ")?;
+ stdout.set_color(
+ ColorSpec::new()
+ .set_fg(Some(Color::Green))
+ .set_dimmed(true)
+ .set_underline(true),
+ )?;
+ writeln!(&mut stdout, "{}", &img.fullsize)?;
+ stdout.reset()?;
+ }
+ }
+ }
+
+ writeln!(&mut stdout, "\n")?;
+ stdout.reset()?;
+ Ok(())
+}