Skip to content

Commit 426487d

Browse files
committed
feat: align ing wrap
1 parent 95b5f41 commit 426487d

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

Cargo.lock

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ getrandom = { version = "0.2.10", features = ["js"] }
2727
rand = { version = "0.8.5" }
2828
regex = "1.9.5"
2929
words-count = "0.1.6"
30+
unicode-width = "0.1.10"
3031

3132
serde = { version = "1.0.188", features = ["derive"] }
3233
serde_qs = "0.12.0"
@@ -43,5 +44,6 @@ futures = "0.3.28"
4344

4445
clap = { version = "4.4.2", features = ["derive", "wrap_help"] }
4546
colored = "2.0.4"
47+
term_size = "0.3.2"
4648

4749
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

src/display/colorful.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use colored::Colorize;
1313
use std::fmt::Display;
1414
use std::ops::Not;
1515
use std::path::PathBuf;
16+
use unicode_width::UnicodeWidthStr;
1617

1718
pub fn login(cfg_path: &Result<PathBuf>) {
1819
match cfg_path {
@@ -81,7 +82,9 @@ pub fn list_ing(ing_list: &Result<Vec<(IngEntry, Vec<IngCommentEntry>)>>, rev: b
8182
print!(" {}⭐", star_text.yellow());
8283
}
8384
println!(" {} {}", "#".dimmed(), ing.id.to_string().dimmed());
84-
let content = fmt_content(&ing.content);
85+
let user_name_width = ing.user_name.width_cjk();
86+
let content = fmt_content(&ing.content)
87+
.replace('\n', &format!("\n{}", " ".repeat(user_name_width + 3)));
8588
println!(" {} {}", ing.user_name.cyan(), content);
8689

8790
let len = comment_list.len();

src/display/normal.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use colored::Colorize;
1313
use std::fmt::Display;
1414
use std::ops::Not;
1515
use std::path::PathBuf;
16+
use unicode_width::UnicodeWidthStr;
1617

1718
pub fn login(cfg_path: &Result<PathBuf>) {
1819
match cfg_path {
@@ -81,8 +82,10 @@ pub fn list_ing(ing_list: &Result<Vec<(IngEntry, Vec<IngCommentEntry>)>>, rev: b
8182
print!(" {}⭐", star_text);
8283
}
8384
println!(" # {}", ing.id);
84-
let content = fmt_content(&ing.content);
85-
println!(" {}: {}", ing.user_name, content);
85+
let user_name_width = ing.user_name.width_cjk();
86+
let content = fmt_content(&ing.content)
87+
.replace('\n', &format!("\n{}", " ".repeat(user_name_width + 3)));
88+
println!(" {} {}", ing.user_name, content);
8689

8790
let len = comment_list.len();
8891
if len != 0 {

0 commit comments

Comments
 (0)