diff --git a/assets/xterm-256color b/assets/xterm-256color new file mode 100644 index 00000000..470fbd46 Binary files /dev/null and b/assets/xterm-256color differ diff --git a/src/terminfo/mod.rs b/src/terminfo/mod.rs index d9d17bc4..fc587df1 100644 --- a/src/terminfo/mod.rs +++ b/src/terminfo/mod.rs @@ -18,6 +18,10 @@ use std::io; use std::io::BufReader; use std::path::Path; + +#[cfg(windows)] +use win; + use Attr; use color; use Terminal; @@ -67,6 +71,18 @@ impl TermInfo { } }) }); + + #[cfg(windows)] + { + if term_name.is_none() && win::conout_supports_ansi() { + // Microsoft people seem to be fine with pretending to be xterm: + // https://github.com/Microsoft/WSL/issues/1446 + // We have to ship xterm's terminfo file since the database + // is not shipped with Windows + return TermInfo::from_bytes(include_bytes!("../../assets/xterm-256color")); + } + } + if let Some(term_name) = term_name { return TermInfo::from_name(term_name); } else { @@ -123,6 +139,13 @@ impl TermInfo { parse(&mut reader, false) } + #[cfg(windows)] + // Get TermInfo from a byte slice directly + fn from_bytes(bytes: &[u8]) -> Result { + let mut reader = BufReader::new(bytes); + parse(&mut reader, false) + } + /// Retrieve a capability `cmd` and expand it with `params`, writing result to `out`. pub fn apply_cap(&self, cmd: &str, params: &[Param], out: &mut io::Write) -> Result<()> { match self.strings.get(cmd) {