mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-24 23:46:41 +02:00
Fix more width issues
This commit is contained in:
parent
a74d101b39
commit
e20ec465c6
3 changed files with 14 additions and 15 deletions
|
@ -17,6 +17,7 @@ use rustyline_derive::Helper;
|
||||||
|
|
||||||
use unicode_segmentation::Graphemes;
|
use unicode_segmentation::Graphemes;
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
pub fn get_start_word_under_cursor(line: &str, cursor_pos: usize) -> usize {
|
pub fn get_start_word_under_cursor(line: &str, cursor_pos: usize) -> usize {
|
||||||
let mut chars = line[..cursor_pos].chars();
|
let mut chars = line[..cursor_pos].chars();
|
||||||
|
@ -143,10 +144,7 @@ impl CompletionList {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn max_width(&self) -> Option<usize> {
|
pub fn max_width(&self) -> Option<usize> {
|
||||||
self.candidates()
|
self.candidates().iter().map(|p| p.display.width() + 4).max()
|
||||||
.iter()
|
|
||||||
.map(|p| p.display.graphemes(true).count() + 4)
|
|
||||||
.max()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, i: usize) -> Option<String> {
|
pub fn get(&self, i: usize) -> Option<String> {
|
||||||
|
|
|
@ -498,14 +498,14 @@ where
|
||||||
"{symbol}{elt:>width$}",
|
"{symbol}{elt:>width$}",
|
||||||
symbol = symbol,
|
symbol = symbol,
|
||||||
elt = elt,
|
elt = elt,
|
||||||
width = *w as usize - symbol.to_string().graphemes(true).count()
|
width = (*w as usize).saturating_sub(symbol.to_string().width())
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
format!(
|
format!(
|
||||||
"{symbol}{elt:<width$}",
|
"{symbol}{elt:<width$}",
|
||||||
symbol = symbol,
|
symbol = symbol,
|
||||||
elt = elt,
|
elt = elt,
|
||||||
width = *w as usize - symbol.to_string().graphemes(true).count()
|
width = (*w as usize).saturating_sub(symbol.to_string().width())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::error::Error;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use task_hookrs::task::Task;
|
use task_hookrs::task::Task;
|
||||||
use task_hookrs::uda::UDAValue;
|
use task_hookrs::uda::UDAValue;
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
pub fn vague_format_date_time(from_dt: NaiveDateTime, to_dt: NaiveDateTime) -> String {
|
pub fn vague_format_date_time(from_dt: NaiveDateTime, to_dt: NaiveDateTime) -> String {
|
||||||
let mut seconds = (to_dt - from_dt).num_seconds();
|
let mut seconds = (to_dt - from_dt).num_seconds();
|
||||||
|
@ -277,14 +278,14 @@ impl TaskReportTable {
|
||||||
None => format!(""),
|
None => format!(""),
|
||||||
};
|
};
|
||||||
let mut d = task.description().to_string();
|
let mut d = task.description().to_string();
|
||||||
let mut end = self.description_width;
|
let mut available_width = self.description_width;
|
||||||
if self.description_width >= c.len() {
|
if self.description_width >= c.len() {
|
||||||
end = self.description_width - c.len();
|
available_width = self.description_width - c.len();
|
||||||
}
|
}
|
||||||
while end < d.len() && !d.is_char_boundary(end) {
|
while available_width < d.width() && !d.is_char_boundary(available_width) {
|
||||||
end += 1;
|
available_width += 1;
|
||||||
}
|
}
|
||||||
d.truncate(end);
|
d.truncate(available_width);
|
||||||
if d != *task.description() {
|
if d != *task.description() {
|
||||||
d = format!("{}…", d);
|
d = format!("{}…", d);
|
||||||
}
|
}
|
||||||
|
@ -292,11 +293,11 @@ impl TaskReportTable {
|
||||||
}
|
}
|
||||||
"description.truncated" => {
|
"description.truncated" => {
|
||||||
let mut d = task.description().to_string();
|
let mut d = task.description().to_string();
|
||||||
let mut end = self.description_width;
|
let mut available_width = self.description_width;
|
||||||
while end < d.len() && !d.is_char_boundary(end) {
|
while available_width < d.len() && !d.is_char_boundary(available_width) {
|
||||||
end += 1;
|
available_width += 1;
|
||||||
}
|
}
|
||||||
d.truncate(end);
|
d.truncate(available_width);
|
||||||
if d != *task.description() {
|
if d != *task.description() {
|
||||||
d = format!("{}…", d);
|
d = format!("{}…", d);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue