From: Ben Pfaff Date: Fri, 16 May 2025 02:26:59 +0000 (-0700) Subject: add text and message support X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79d4b5879753c287c9ee16ca03ee4862d4c4c261;p=pspp add text and message support --- diff --git a/rust/pspp/src/output/mod.rs b/rust/pspp/src/output/mod.rs index 6eadd671e7..4ff8d3bea4 100644 --- a/rust/pspp/src/output/mod.rs +++ b/rust/pspp/src/output/mod.rs @@ -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 { diff --git a/rust/pspp/src/output/pivot/test.rs b/rust/pspp/src/output/pivot/test.rs index 1354a66d6b..5788d03288 100644 --- a/rust/pspp/src/output/pivot/test.rs +++ b/rust/pspp/src/output/pivot/test.rs @@ -763,7 +763,7 @@ fn footnote_alphabetic_superscript() { "\ Pivot Table with Alphabetic Superscript Footnotes[*] ╭────────────┬──────────────────╮ -│ │ A[*] │ +│ │ A[*] 1 │ │ ├───────┬──────────┤ │Corner[*][b]│ B[b] │ C[*][b] │ ├────────────┼───────┼──────────┤ diff --git a/rust/pspp/src/output/spv.rs b/rust/pspp/src/output/spv.rs index bdec94703e..6b4aa39c90 100644 --- a/rust/pspp/src/output/spv.rs +++ b/rust/pspp/src/output/spv.rs @@ -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(&mut self, item: &Item, text: &Text, structure: &mut XmlWriter) + 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(&mut self, item: &Item, structure: &mut XmlWriter) 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), } }