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
|
//! ref: composer/vendor/symfony/console/Output/BufferedOutput.php
use crate::symfony::console::formatter::OutputFormatterInterface;
use crate::symfony::console::output::OutputInterface;
use crate::symfony::console::output::output::{DoWrite, Output};
#[derive(Debug)]
pub struct BufferedOutput {
inner: Output,
buffer: std::cell::RefCell<String>,
}
impl BufferedOutput {
pub fn new(
verbosity: Option<i64>,
decorated: bool,
formatter: Option<std::rc::Rc<std::cell::RefCell<dyn OutputFormatterInterface>>>,
) -> Self {
Self {
inner: Output::new(verbosity, decorated, formatter),
buffer: std::cell::RefCell::new(String::new()),
}
}
/// Empties buffer and returns its content.
pub fn fetch(&self) -> String {
let content = self.buffer.borrow().clone();
*self.buffer.borrow_mut() = String::new();
content
}
}
impl DoWrite for BufferedOutput {
fn do_write(&self, message: &str, newline: bool) {
self.buffer.borrow_mut().push_str(message);
if newline {
self.buffer.borrow_mut().push_str(shirabe_php_shim::PHP_EOL);
}
}
}
impl OutputInterface for BufferedOutput {
fn write(&self, messages: &[String], newline: bool, options: i64) {
self.inner.write(self, messages, newline, options);
}
fn writeln(&self, messages: &[String], options: i64) {
self.inner.writeln(self, messages, options);
}
fn set_verbosity(&self, level: i64) {
self.inner.set_verbosity(level);
}
fn get_verbosity(&self) -> i64 {
self.inner.get_verbosity()
}
fn is_quiet(&self) -> bool {
self.inner.is_quiet()
}
fn is_verbose(&self) -> bool {
self.inner.is_verbose()
}
fn is_very_verbose(&self) -> bool {
self.inner.is_very_verbose()
}
fn is_debug(&self) -> bool {
self.inner.is_debug()
}
fn set_decorated(&self, decorated: bool) {
self.inner.set_decorated(decorated);
}
fn is_decorated(&self) -> bool {
self.inner.is_decorated()
}
fn set_formatter(
&self,
formatter: std::rc::Rc<std::cell::RefCell<dyn OutputFormatterInterface>>,
) {
self.inner.set_formatter(formatter);
}
fn get_formatter(&self) -> std::rc::Rc<std::cell::RefCell<dyn OutputFormatterInterface>> {
self.inner.get_formatter()
}
}
|