`IntoRawMode` only works with stdout
Although the IntoRawMode
trait looks like it supports any writer: impl Writer
, in fact it only works with stdout. The issue comes down to using sys::unix::{get_terminal_attr, ..}
that have libc::STDOUT_FILENO
hardcoded into them.
A solution would be update RawTerminal
and IntoRawMode
so it would be implemented for all impl Writer + AsRawFd
. The raw fd needs to be retrieved from the writer and given to subsequent functions. I.e. something like that:
pub trait IntoRawMode: Write + AsRawFd + Sized {
/// Switch to raw mode.
///
/// Raw mode means that stdin won't be printed (it will instead have to be written manually by
/// the program). Furthermore, the input isn't canonicalised or buffered (that is, you can
/// read from stdin one byte of a time). The output is neither modified in any way.
fn into_raw_mode(self) -> io::Result<RawTerminal<Self>>;
}
impl<W: Write + AsRawFd> IntoRawMode for W {
fn into_raw_mode(self) -> io::Result<RawTerminal<W>> {
let fd = self.as_raw_fd();
let mut ios = get_terminal_attr(fd)?;
let prev_ios = ios;
raw_terminal_attr(&mut ios);
set_terminal_attr(fd, &ios)?;
Ok(RawTerminal {
prev_ios: prev_ios,
output: self,
})
}
}
Unfortunately, that would require a major bump in library version as it changes API. As a workaround until v3
it's possible to provide a second module raw2
that would properly handle writers that are not stdout, for example.
Let me know if you're interested in contribution!