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-external-packages/src/symfony/console/style/output_style.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-external-packages/src/symfony/console/style/output_style.rs')
| -rw-r--r-- | crates/shirabe-external-packages/src/symfony/console/style/output_style.rs | 193 |
1 files changed, 193 insertions, 0 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/style/output_style.rs b/crates/shirabe-external-packages/src/symfony/console/style/output_style.rs new file mode 100644 index 0000000..6286e01 --- /dev/null +++ b/crates/shirabe-external-packages/src/symfony/console/style/output_style.rs @@ -0,0 +1,193 @@ +use crate::symfony::console::formatter::OutputFormatterInterface; +use crate::symfony::console::helper::ProgressBar; +use crate::symfony::console::output::ConsoleOutputInterface; +use crate::symfony::console::output::OutputInterface; +use crate::symfony::console::output::output_interface::OUTPUT_NORMAL; +use crate::symfony::console::style::style_interface::StyleInterface; +use shirabe_php_shim::PhpMixed; +use std::cell::RefCell; +use std::rc::Rc; + +/// Decorates output to add console style guide helpers. +#[derive(Debug)] +pub struct OutputStyle { + output: Rc<RefCell<dyn OutputInterface>>, +} + +impl OutputStyle { + pub fn new(output: Rc<RefCell<dyn OutputInterface>>) -> Self { + Self { output } + } + + pub fn create_progress_bar(&self, max: i64) -> ProgressBar { + ProgressBar::new(self.output.clone(), max, 1.0 / 25.0) + } + + pub(crate) fn get_error_output(&self) -> Rc<RefCell<dyn OutputInterface>> { + // PHP checks `$this->output instanceof ConsoleOutputInterface`; this requires + // runtime type information that the OutputInterface trait object lacks. + if !Self::is_console_output_interface(&self.output) { + return self.output.clone(); + } + + Self::as_console_output_interface(&self.output) + .unwrap() + .borrow() + .get_error_output() + } + + fn is_console_output_interface(_output: &Rc<RefCell<dyn OutputInterface>>) -> bool { + todo!() + } + + fn as_console_output_interface( + _output: &Rc<RefCell<dyn OutputInterface>>, + ) -> Option<Rc<RefCell<dyn ConsoleOutputInterface>>> { + todo!() + } +} + +impl OutputInterface for OutputStyle { + fn write(&self, messages: &[String], newline: bool, options: i64) { + self.output.borrow().write(messages, newline, options); + } + + fn writeln(&self, messages: &[String], options: i64) { + self.output.borrow().writeln(messages, options); + } + + fn set_verbosity(&self, level: i64) { + self.output.borrow().set_verbosity(level); + } + + fn get_verbosity(&self) -> i64 { + self.output.borrow().get_verbosity() + } + + fn is_quiet(&self) -> bool { + self.output.borrow().is_quiet() + } + + fn is_verbose(&self) -> bool { + self.output.borrow().is_verbose() + } + + fn is_very_verbose(&self) -> bool { + self.output.borrow().is_very_verbose() + } + + fn is_debug(&self) -> bool { + self.output.borrow().is_debug() + } + + fn set_decorated(&self, decorated: bool) { + self.output.borrow().set_decorated(decorated); + } + + fn is_decorated(&self) -> bool { + self.output.borrow().is_decorated() + } + + fn set_formatter(&self, formatter: Rc<RefCell<dyn OutputFormatterInterface>>) { + self.output.borrow().set_formatter(formatter); + } + + fn get_formatter(&self) -> Rc<RefCell<dyn OutputFormatterInterface>> { + self.output.borrow().get_formatter() + } +} + +impl StyleInterface for OutputStyle { + fn title(&mut self, _message: &str) { + todo!() + } + + fn section(&mut self, _message: &str) { + todo!() + } + + fn listing(&mut self, _elements: Vec<PhpMixed>) { + todo!() + } + + fn text(&mut self, _message: PhpMixed) { + todo!() + } + + fn success(&mut self, _message: PhpMixed) { + todo!() + } + + fn error(&mut self, _message: PhpMixed) { + todo!() + } + + fn warning(&mut self, _message: PhpMixed) { + todo!() + } + + fn note(&mut self, _message: PhpMixed) { + todo!() + } + + fn caution(&mut self, _message: PhpMixed) { + todo!() + } + + fn table(&mut self, _headers: Vec<PhpMixed>, _rows: Vec<PhpMixed>) { + todo!() + } + + fn ask( + &mut self, + _question: &str, + _default: Option<&str>, + _validator: Option<Box<dyn Fn(Option<PhpMixed>) -> anyhow::Result<PhpMixed>>>, + ) -> PhpMixed { + todo!() + } + + fn ask_hidden( + &mut self, + _question: &str, + _validator: Option<Box<dyn Fn(Option<PhpMixed>) -> anyhow::Result<PhpMixed>>>, + ) -> PhpMixed { + todo!() + } + + fn confirm(&mut self, _question: &str, _default: bool) -> bool { + todo!() + } + + fn choice( + &mut self, + _question: &str, + _choices: Vec<PhpMixed>, + _default: Option<PhpMixed>, + ) -> PhpMixed { + todo!() + } + + fn new_line(&mut self, count: i64) { + self.output.borrow().write( + &[shirabe_php_shim::str_repeat( + shirabe_php_shim::PHP_EOL, + count as usize, + )], + false, + OUTPUT_NORMAL, + ); + } + + fn progress_start(&mut self, _max: i64) { + todo!() + } + + fn progress_advance(&mut self, _step: i64) { + todo!() + } + + fn progress_finish(&mut self) { + todo!() + } +} |
