diff --git a/src/display/colorful.rs b/src/display/colorful.rs index f75bb79..040380a 100644 --- a/src/display/colorful.rs +++ b/src/display/colorful.rs @@ -306,7 +306,6 @@ pub fn search_post(result: &Result<(Vec, usize)>, rev: bool) -> Result>, @@ -328,7 +327,20 @@ pub fn list_news( let url = format!("https://news.cnblogs.com/n/{}", news.id); writeln!(buf, "{} {}", create_time.dimmed(), url.dimmed())?; writeln!(buf, " {}", news.title)?; - writeln!(buf, " {}{}", news.summary.dimmed(), "...".dimmed())?; + + let summary = { + let summary = format!("{}...", news.summary); + summary.width_split(get_term_width() - 4).map_or_else( + || summary.clone(), + |vec| { + vec.into_iter() + .map(|line| format!(" {}", line)) + .collect::>() + .join("\n") + }, + ) + }; + writeln!(buf, "{}", summary.dimmed())?; } buf }) diff --git a/src/display/normal.rs b/src/display/normal.rs index f443b46..6b63626 100644 --- a/src/display/normal.rs +++ b/src/display/normal.rs @@ -298,7 +298,6 @@ pub fn search_post(result: &Result<(Vec, usize)>, rev: bool) -> Result>, @@ -320,7 +319,20 @@ pub fn list_news( let url = format!("https://news.cnblogs.com/n/{}", news.id); writeln!(buf, "{} {}", create_time, url)?; writeln!(buf, " {}", news.title)?; - writeln!(buf, " {}...", news.summary)?; + + let summary = { + let summary = format!("{}...", news.summary); + summary.width_split(get_term_width() - 4).map_or_else( + || summary.clone(), + |vec| { + vec.into_iter() + .map(|line| format!(" {}", line)) + .collect::>() + .join("\n") + }, + ) + }; + writeln!(buf, "{}", summary)?; } buf })