pub fn width(&self) -> usize { UnicodeWidthStr::width(&self.text as &str) }
pub fn text(&self) -> &str { &self.text }
+ pub fn colours(&self) -> &str { &self.colour }
pub fn recolour(&self, colour: char) -> Self {
Self::uniform(&self.text, colour)
}
if !self.info_fields.is_empty() {
push_fragment(&mut lines, self.info_header.render(width));
for (key, value) in &self.info_fields {
- push_fragment(&mut lines, key.render(width));
- push_fragment(&mut lines, value.render_indented(width, 4));
+ // Display a single line 'key: value' if it fits.
+ // Otherwise, let the value go to the next line,
+ // indented further.
+ let rkey = key.render(width);
+ let rval = value.render_indented(width, 4);
+ if rkey.len() == 1 && rval.len() == 1 &&
+ rkey[0].width() + rval[0].width() + 2 <= width
+ {
+ let rval = &rval[0];
+ assert!(rval.text().starts_with(" "));
+ // Trim 3 spaces off, leaving one after the colon
+ let rval = ColouredString::general(&rval.text()[3..],
+ &rval.colours()[3..]);
+ lines.push(rkey[0].to_owned() + &rval);
+ } else {
+ push_fragment(&mut lines, rkey);
+ push_fragment(&mut lines, rval);
+ }
}
push_fragment(&mut lines, self.blank.render(width));
}