add text and message support
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 16 May 2025 02:26:59 +0000 (19:26 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 16 May 2025 02:26:59 +0000 (19:26 -0700)
rust/pspp/src/output/mod.rs
rust/pspp/src/output/pivot/test.rs
rust/pspp/src/output/spv.rs

index 6eadd671e7022eb9a11dc46aaea8db8b05e41a8e..4ff8d3bea40dc1fe00e7f172f8a224b3f1591421 100644 (file)
@@ -117,6 +117,15 @@ pub struct Text {
     content: Value,
 }
 
+impl From<&Diagnostic> for Text {
+    fn from(value: &Diagnostic) -> Self {
+        Text {
+            type_: TextType::Log,
+            content: Value::new_user_text(value.to_string()),
+        }
+    }
+}
+
 pub enum TextType {
     /// `TITLE` and `SUBTITLE` commands.
     PageTitle,
@@ -140,6 +149,14 @@ impl TextType {
             TextType::Log => "Log",
         }
     }
+
+    pub fn as_xml_str(&self) -> &'static str {
+        match self {
+            TextType::PageTitle => "page-title",
+            TextType::Title => "title",
+            TextType::Syntax | TextType::Log => "log",
+        }
+    }
 }
 
 pub struct ItemCursor {
index 1354a66d6bba531a4fb45c2f2f6bba0a8ec9ff2c..5788d03288980b4f9039e3765d439b7a2b3a9b51 100644 (file)
@@ -763,7 +763,7 @@ fn footnote_alphabetic_superscript() {
         "\
 Pivot Table with Alphabetic Superscript Footnotes[*]
 ╭────────────┬──────────────────╮
-│            │       A[*]       │
+│            │       A[*]      1 │
 │            ├───────┬──────────┤
 │Corner[*][b]│  B[b] │  C[*][b] │
 ├────────────┼───────┼──────────┤
index bdec94703e937a9b991a6a92264d848502b7cf5f..6b4aa39c902515c33fee15aaaeeeda6b735aae38 100644 (file)
@@ -28,7 +28,7 @@ use crate::{
             Footnotes, Group, HeadingRegion, HorzAlign, LabelPosition, Leaf, PivotTable,
             RowColBorder, Stroke, Value, ValueInner, ValueStyle, VertAlign,
         },
-        Item,
+        Item, Text,
     },
     settings::Show,
 };
@@ -99,7 +99,6 @@ where
         let mut content = Vec::new();
         let mut cursor = Cursor::new(&mut content);
         pivot_table.write_le(&mut cursor).unwrap();
-        println!("{}", content.len());
 
         let table_name = light_table_name(table_id);
         self.writer
@@ -127,6 +126,17 @@ where
         });
     }
 
+    fn write_text<X>(&mut self, item: &Item, text: &Text, structure: &mut XmlWriter<X>)
+    where
+        X: Write,
+    {
+        self.container(structure, item, "vtx:text", |w| {
+            w.with_attribute(("type", text.type_.as_xml_str()))
+                .write_text_content(BytesText::new(&text.content.display(()).to_string()))
+                .unwrap();
+        });
+    }
+
     fn write_item<X>(&mut self, item: &Item, structure: &mut XmlWriter<X>)
     where
         X: Write,
@@ -155,12 +165,14 @@ where
                     })
                     .unwrap();
             }
-            super::Details::Message(_diagnostic) => todo!(),
+            super::Details::Message(diagnostic) => {
+                self.write_text(item, &diagnostic.into(), structure)
+            }
             super::Details::PageBreak => {
                 self.needs_page_break = true;
             }
             super::Details::Table(pivot_table) => self.write_table(&*item, pivot_table, structure),
-            super::Details::Text(_text) => todo!(),
+            super::Details::Text(text) => self.write_text(item, text, structure),
         }
     }