mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-24 23:46:41 +02:00
Fix unicode truncation issues
This commit is contained in:
parent
e20ec465c6
commit
671d1ece44
3 changed files with 19 additions and 11 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -1406,6 +1406,7 @@ dependencies = [
|
|||
"task-hookrs",
|
||||
"tui",
|
||||
"unicode-segmentation",
|
||||
"unicode-truncate",
|
||||
"unicode-width",
|
||||
"uuid",
|
||||
]
|
||||
|
@ -1457,6 +1458,15 @@ version = "1.7.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-truncate"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a04be5ca5f7a4a7270ffea82bc41c59b87c611ed04f20e77c338e8d3c2348e42"
|
||||
dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.8"
|
||||
|
|
|
@ -42,6 +42,7 @@ task-hookrs = { git = "https://github.com/matthiasbeyer/task-hookrs" }
|
|||
tui = { version = "0.12", optional = true, default-features = false }
|
||||
unicode-segmentation = "1.6"
|
||||
unicode-width = "0.1"
|
||||
unicode-truncate = "0.2"
|
||||
uuid = { version = "0.8.1", features = ["serde", "v4"] }
|
||||
|
||||
[package.metadata.rpm]
|
||||
|
|
|
@ -5,6 +5,7 @@ use std::error::Error;
|
|||
use std::process::Command;
|
||||
use task_hookrs::task::Task;
|
||||
use task_hookrs::uda::UDAValue;
|
||||
use unicode_truncate::UnicodeTruncateStr;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
pub fn vague_format_date_time(from_dt: NaiveDateTime, to_dt: NaiveDateTime) -> String {
|
||||
|
@ -277,27 +278,23 @@ impl TaskReportTable {
|
|||
Some(a) => format!(" [{}]", a.len()),
|
||||
None => format!(""),
|
||||
};
|
||||
let mut d = task.description().to_string();
|
||||
let d = task.description().to_string();
|
||||
let mut available_width = self.description_width;
|
||||
if self.description_width >= c.len() {
|
||||
available_width = self.description_width - c.len();
|
||||
}
|
||||
while available_width < d.width() && !d.is_char_boundary(available_width) {
|
||||
available_width += 1;
|
||||
}
|
||||
d.truncate(available_width);
|
||||
let (d, _) = d.unicode_truncate(available_width);
|
||||
let mut d = d.to_string();
|
||||
if d != *task.description() {
|
||||
d = format!("{}…", d);
|
||||
}
|
||||
format!("{}{}", d, c)
|
||||
}
|
||||
"description.truncated" => {
|
||||
let mut d = task.description().to_string();
|
||||
let mut available_width = self.description_width;
|
||||
while available_width < d.len() && !d.is_char_boundary(available_width) {
|
||||
available_width += 1;
|
||||
}
|
||||
d.truncate(available_width);
|
||||
let d = task.description().to_string();
|
||||
let available_width = self.description_width;
|
||||
let (d, _) = d.unicode_truncate(available_width);
|
||||
let mut d = d.to_string();
|
||||
if d != *task.description() {
|
||||
d = format!("{}…", d);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue