chiark / gitweb /
Examine User: compact way of displaying fields.
authorSimon Tatham <anakin@pobox.com>
Thu, 4 Jan 2024 20:33:58 +0000 (20:33 +0000)
committerSimon Tatham <anakin@pobox.com>
Thu, 4 Jan 2024 20:33:58 +0000 (20:33 +0000)
This is much simpler than my previous idea of trying to modify the
HTML DOM to insert the heading at the start of the first paragraph!

src/coloured_string.rs
src/text.rs

index 185a16a17fdec14f6fc4a61a35e4c6218fab1d32..574d055a7ec0aed4bc2547d07072c0fdd5208710 100644 (file)
@@ -47,6 +47,7 @@ impl ColouredString {
     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)
     }
index e268752af60bbb09f03bc60124993e1dba7e0f21..cbcfa10302f40390ea541c400d8459a3dcad600d 100644 (file)
@@ -2309,8 +2309,24 @@ impl TextFragment for ExamineUserDisplay {
         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));
         }