diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-12 01:01:35 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-12 01:01:43 +0900 |
| commit | 1e44f5723e4c0e0903d00a61f254901e612fe5e1 (patch) | |
| tree | 9c2e1eec364bbf6418a4072ee7767b04c3df0297 /crates/shirabe/src/console/html_output_formatter.rs | |
| parent | ddf0a624145b618c05c2ee47414545b99b685f37 (diff) | |
| download | php-shirabe-1e44f5723e4c0e0903d00a61f254901e612fe5e1.tar.gz php-shirabe-1e44f5723e4c0e0903d00a61f254901e612fe5e1.tar.zst php-shirabe-1e44f5723e4c0e0903d00a61f254901e612fe5e1.zip | |
feat(symfony-console): port Symfony Console and make the workspace compile
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/console/html_output_formatter.rs')
| -rw-r--r-- | crates/shirabe/src/console/html_output_formatter.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/crates/shirabe/src/console/html_output_formatter.rs b/crates/shirabe/src/console/html_output_formatter.rs index a2158fa..b516c83 100644 --- a/crates/shirabe/src/console/html_output_formatter.rs +++ b/crates/shirabe/src/console/html_output_formatter.rs @@ -3,7 +3,8 @@ use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_external_packages::symfony::console::formatter::OutputFormatter; -use shirabe_external_packages::symfony::console::formatter::OutputFormatterStyle; +use shirabe_external_packages::symfony::console::formatter::OutputFormatterInterface; +use shirabe_external_packages::symfony::console::formatter::OutputFormatterStyleInterface; #[derive(Debug)] pub struct HtmlOutputFormatter { @@ -41,14 +42,19 @@ impl HtmlOutputFormatter { //8 => "conceal" ]; - pub fn new(styles: IndexMap<String, OutputFormatterStyle>) -> Self { + pub fn new(styles: IndexMap<String, Box<dyn OutputFormatterStyleInterface>>) -> Self { Self { inner: OutputFormatter::new(true, styles), } } - pub fn format(&self, message: Option<&str>) -> Option<String> { - let formatted = self.inner.format(message.unwrap_or("")); + pub fn format(&mut self, message: Option<&str>) -> anyhow::Result<Option<String>> { + let formatted = self.inner.format(message)?; + + let formatted = match formatted { + Some(formatted) => formatted, + None => return Ok(None), + }; let clear_escape_codes = "(?:39|49|0|22|24|25|27|28)"; let pattern = format!( @@ -56,7 +62,11 @@ impl HtmlOutputFormatter { clear_escape_codes, clear_escape_codes ); - Preg::replace_callback(&pattern, |matches| self.format_html(matches), &formatted).ok() + Ok(Some(Preg::replace_callback( + &pattern, + |matches| self.format_html(matches), + &formatted, + )?)) } fn format_html(&self, matches: &IndexMap<CaptureKey, String>) -> String { |
