diff options
author | Gokul Soumya | 2021-06-24 15:54:34 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-06-25 00:28:24 +0000 |
commit | 18beda38ac9dfec843dcbb51adf596e294fc13b2 (patch) | |
tree | bd288a4201b8bda30e7869004f676dec2aebe36c /helix-tui/src | |
parent | 10548bf0e32209e02460021cc8ca4865c4c75bf7 (diff) |
Add … when chars are truncated in picker
Diffstat (limited to 'helix-tui/src')
-rw-r--r-- | helix-tui/src/buffer.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/helix-tui/src/buffer.rs b/helix-tui/src/buffer.rs index 0d1edc46..8b03cb0d 100644 --- a/helix-tui/src/buffer.rs +++ b/helix-tui/src/buffer.rs @@ -269,8 +269,27 @@ impl Buffer { where S: AsRef<str>, { + self.set_string_truncated(x, y, string, width, style, false) + } + + /// Print at most the first `width` characters of a string if enough space is available + /// until the end of the line. If `markend` is true appends a `…` at the end of + /// truncated lines. + pub fn set_string_truncated<S>( + &mut self, + x: u16, + y: u16, + string: S, + width: usize, + style: Style, + ellipsis: bool, + ) -> (u16, u16) + where + S: AsRef<str>, + { let mut index = self.index_of(x, y); let mut x_offset = x as usize; + let width = if ellipsis { width - 1 } else { width }; let graphemes = UnicodeSegmentation::graphemes(string.as_ref(), true); let max_offset = min(self.area.right() as usize, width.saturating_add(x as usize)); for s in graphemes { @@ -293,6 +312,9 @@ impl Buffer { index += width; x_offset += width; } + if ellipsis && x_offset - (x as usize) < string.as_ref().chars().count() { + self.content[index].set_symbol("…"); + } (x_offset as u16, y) } |