aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages/src/symfony/console/style/output_style.rs
blob: 6286e011b61e526fe91495af7eb3d3bff62de4ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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!()
    }
}