fix(preset): add output-flag to avoid encoding issues (#4926)

This commit is contained in:
David Knaack
2023-03-03 11:46:16 +01:00
committed by GitHub
parent 4c12a7878b
commit 5e78226a3f
12 changed files with 45 additions and 29 deletions
+3 -15
View File
@@ -34,24 +34,12 @@ fn gen_presets_hook(mut file: &File) -> SdResult<()> {
.and_then(|v| v.strip_suffix(".toml"))
.expect("Failed to process filename");
presets.push_str(format!("print::Preset(\"{name}\"),\n").as_str());
match_arms.push_str(
format!(
r#"
"{name}" => {{
let stdout = io::stdout();
let mut stdout = stdout.lock();
let _ = stdout.write_all(include_bytes!(r"{full_path}"));
}}
"#
)
.as_str(),
);
match_arms.push_str(format!(r#""{name}" => include_bytes!(r"{full_path}"),"#).as_str());
}
writeln!(
file,
r#"
use std::io::{{self, Write}};
use crate::print;
pub fn get_preset_list<'a>() -> &'a [print::Preset] {{
@@ -60,10 +48,10 @@ pub fn get_preset_list<'a>() -> &'a [print::Preset] {{
]
}}
pub fn print_preset_content(name: &str) {{
pub fn get_preset_content(name: &str) -> &[u8] {{
match name {{
{match_arms}
_ => {{}}
_ => unreachable!(),
}}
}}
"#