@@ -266,11 +266,30 @@ impl Buffer {
266266 width: usize,
267267 style: Style,
268268 ) -> (u16, u16)
269+ where
270+ S: AsRef<str>,
271+ {
272+ self.set_string_truncated(x, y, string, width, style, false)
273+ }
274+
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>(
279+ &mut self,
280+ x: u16,
281+ y: u16,
282+ string: S,
283+ width: usize,
284+ style: Style,
285+ ellipsis: bool,
286+ ) -> (u16, u16)
269287 where
270288 S: AsRef<str>,
271289 {
272290 let mut index = self.index_of(x, y);
273291 let mut x_offset = x as usize;
292+ let width = if ellipsis { width - 1 } else { width };
274293 let graphemes = UnicodeSegmentation::graphemes(string.as_ref(), true);
275294 let max_offset = min(self.area.right() as usize, width.saturating_add(x as usize));
276295 for s in graphemes {
@@ -293,6 +312,9 @@ impl Buffer {
293312 index += width;
294313 x_offset += width;
295314 }
315+ if ellipsis && x_offset - (x as usize) < string.as_ref().chars().count() {
316+ self.content[index].set_symbol("…");
317+ }
296318 (x_offset as u16, y)
297319 }
298320