Skip to content

Commit 76bc0a7

Browse files
committed
Add a Style to ReadWritePair.
1 parent f2c4756 commit 76bc0a7

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/term.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ impl<T: io::Read + std::fmt::Debug + AsRawFd + Send> TermRead for T {}
2525
pub struct ReadWritePair {
2626
read: Arc<Mutex<dyn TermRead>>,
2727
write: Arc<Mutex<dyn TermWrite>>,
28+
style: Style,
2829
}
2930

3031
/// Where the term is writing.
@@ -176,9 +177,19 @@ impl Term {
176177
})
177178
}
178179

179-
/// Return a terminal for the given Read/Write pair.
180+
/// Return a terminal for the given Read/Write pair styled-like Stderr.
180181
#[cfg(unix)]
181182
pub fn read_write_pair<R, W>(read: R, write: W) -> Term
183+
where
184+
R: io::Read + std::fmt::Debug + AsRawFd + Send + 'static,
185+
W: Write + std::fmt::Debug + AsRawFd + Send + 'static,
186+
{
187+
Self::read_write_pair_with_style(read, write, Style::new().for_stderr())
188+
}
189+
190+
/// Return a terminal for the given Read/Write pair.
191+
#[cfg(unix)]
192+
pub fn read_write_pair_with_style<R, W>(read: R, write: W, style: Style) -> Term
182193
where
183194
R: io::Read + std::fmt::Debug + AsRawFd + Send + 'static,
184195
W: Write + std::fmt::Debug + AsRawFd + Send + 'static,
@@ -187,6 +198,7 @@ impl Term {
187198
target: TermTarget::ReadWritePair(ReadWritePair {
188199
read: Arc::new(Mutex::new(read)),
189200
write: Arc::new(Mutex::new(write)),
201+
style,
190202
}),
191203
buffer: None,
192204
})
@@ -198,9 +210,8 @@ impl Term {
198210
match self.inner.target {
199211
TermTarget::Stderr => Style::new().for_stderr(),
200212
TermTarget::Stdout => Style::new().for_stdout(),
201-
// TODO: Needs an implementation. But also: is not Copy.
202213
#[cfg(unix)]
203-
TermTarget::ReadWritePair(_) => Style::new().for_stderr(),
214+
TermTarget::ReadWritePair(ReadWritePair { ref style, .. }) => style.clone(),
204215
}
205216
}
206217

0 commit comments

Comments
 (0)