@@ -266,11 +266,30 @@ impl Buffer {
266 width: usize,
266 width: usize,
267 style: Style,
267 style: Style,
268 ) -> (u16, u16)
268 ) -> (u16, u16)
272+ self.set_string_truncated(x, y, string, width, style, false)
275+ /// Print at most the first `width` characters of a string if enough space is available
276+ /// until the end of the line. If `markend` is true appends a `…` at the end of
277+ /// truncated lines.
278+ pub fn set_string_truncated<S>(
270 S: AsRef<str>,
288 S: AsRef<str>,
272 let mut index = self.index_of(x, y);
290 let mut index = self.index_of(x, y);
273 let mut x_offset = x as usize;
291 let mut x_offset = x as usize;
292+ let width = if ellipsis { width - 1 } else { width };
274 let graphemes = UnicodeSegmentation::graphemes(string.as_ref(), true);
293 let graphemes = UnicodeSegmentation::graphemes(string.as_ref(), true);
275 let max_offset = min(self.area.right() as usize, width.saturating_add(x as usize));
294 let max_offset = min(self.area.right() as usize, width.saturating_add(x as usize));
276 for s in graphemes {
295 for s in graphemes {
@@ -293,6 +312,9 @@ impl Buffer {
293 index += width;
312 index += width;
294 x_offset += width;
313 x_offset += width;
315+ if ellipsis && x_offset - (x as usize) < string.as_ref().chars().count() {
316+ self.content[index].set_symbol("…");
296 (x_offset as u16, y)
318 (x_offset as u16, y)