@@ -6,6 +6,7 @@ use crate::api::news::get_list::NewsEntry;
6
6
use crate :: api:: post:: get_one:: PostEntry ;
7
7
use crate :: api:: user:: info:: UserInfo ;
8
8
use crate :: infra:: iter:: IteratorExt ;
9
+ use crate :: infra:: str:: StrExt ;
9
10
use crate :: infra:: time:: patch_rfc3339;
10
11
use anyhow:: Result ;
11
12
use chrono:: DateTime ;
@@ -14,7 +15,6 @@ use std::fmt::Display;
14
15
use std:: ops:: Not ;
15
16
use std:: path:: PathBuf ;
16
17
use unicode_width:: UnicodeWidthStr ;
17
- use crate :: infra:: str:: StrExt ;
18
18
19
19
pub fn login ( cfg_path : & Result < PathBuf > ) {
20
20
match cfg_path {
@@ -85,18 +85,26 @@ pub fn list_ing(ing_list: &Result<Vec<(IngEntry, Vec<IngCommentEntry>)>>, rev: b
85
85
println ! ( " {} {}" , "#" . dimmed( ) , ing. id. to_string( ) . dimmed( ) ) ;
86
86
let content = if align {
87
87
let user_name_width = ing. user_name . width_cjk ( ) ;
88
- let ( term_width, _) = term_size:: dimensions ( )
89
- . expect ( "Can not get terminal size" ) ;
90
- let left_width = term_width. checked_sub ( user_name_width + 3 ) . unwrap_or ( 0 ) ;
91
- if let Some ( lines) = fmt_content ( & ing. content ) . width_split ( left_width) {
92
- if comment_list. len ( ) > 0 {
93
- lines. join ( "\n " ) . replace ( "\n " , & format ! ( "\n │{}" , " " . repeat( user_name_width - 2 ) ) )
94
- } else {
95
- lines. join ( "\n " ) . replace ( "\n " , & format ! ( "\n {}" , " " . repeat( user_name_width + 3 ) ) )
96
- }
97
- } else {
98
- ing. content . clone ( )
99
- }
88
+ let ( term_width, _) = term_size:: dimensions ( ) . expect ( "Can not get terminal size" ) ;
89
+ let left_width = term_width. saturating_sub ( user_name_width + 3 ) ;
90
+ fmt_content ( & ing. content )
91
+ . width_split ( left_width)
92
+ . map_or_else (
93
+ || ing. content . clone ( ) ,
94
+ |lines| {
95
+ if comment_list. is_empty ( ) . not ( ) {
96
+ lines. join ( "\n " ) . replace (
97
+ '\n' ,
98
+ & format ! ( "\n │{}" , " " . repeat( user_name_width - 2 ) ) ,
99
+ )
100
+ } else {
101
+ lines. join ( "\n " ) . replace (
102
+ '\n' ,
103
+ & format ! ( "\n {}" , " " . repeat( user_name_width + 3 ) ) ,
104
+ )
105
+ }
106
+ } ,
107
+ )
100
108
} else {
101
109
fmt_content ( & ing. content )
102
110
} ;
@@ -248,7 +256,7 @@ pub fn list_news(news_list: &Result<Vec<NewsEntry>>, rev: bool) {
248
256
} ;
249
257
250
258
let url = format ! ( "https://news.cnblogs.com/n/{}" , news. id) ;
251
- println ! ( "{} {}" , create_time. dimmed( ) , url. dimmed( ) , ) ;
259
+ println ! ( "{} {}" , create_time. dimmed( ) , url. dimmed( ) , ) ;
252
260
println ! ( " {}" , news. title) ;
253
261
println ! ( " {}{}" , news. summary. dimmed( ) , "..." . dimmed( ) ) ;
254
262
println ! ( ) ;
0 commit comments