From 74ad1480b1a5d06495b46d58d2a5cf1be03fc48b Mon Sep 17 00:00:00 2001 From: Mohammad AlSaleh Date: Wed, 22 Aug 2018 21:15:52 +0300 Subject: [PATCH] Pretend to be xterm if Windows console supports ansi Windows people seem to be fine with this: https://github.com/Microsoft/WSL/issues/1446 I still think a precise terminfo file with the list of supported sequences documented in the below link would be ideal: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences But I didn't find such a file. And I don't know how to generate one easily. A copy of xterm-256color terminfo file is included at compile-time. I copied it from ncurses 6.1. With this commit, term should be on par with ansi_term for Windows 10 users. Signed-off-by: Mohammad AlSaleh --- assets/xterm-256color | Bin 0 -> 3713 bytes src/terminfo/mod.rs | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 assets/xterm-256color diff --git a/assets/xterm-256color b/assets/xterm-256color new file mode 100644 index 0000000000000000000000000000000000000000..470fbd467cbb8b6b9b23e7fef2528021db8d8a3b GIT binary patch literal 3713 zcmb_eZH!!18Gg^)yR7R65J;oVXx+wMOR8<}J@;c~dY2AmyRcKbJ7c$7*AAPs`_cWJ z-R;cKZrR;RqJ|&|enkxtBY_wUBoYloFbF0j#i)d!Cc-abf*Lf27&QH1$@skIJu_uv zjs4+f&-1+Jectn)Gw17`Z5fX~N!QVLRpy%2=5)QbTgS=d^5SxR-Bf$e&NXLy;p;Wd z29YxVOfU?x!T+5a>ni_jPPB088noU@+c36Wvt|tqj!psR zX^B>8-DJOqzDW1c1F#>a@6+SpC+R7AmY%1V=vVX`)Ze7H=xzF^iEg#Jl?-Vs_+!@o zICzJ(TdkYar`gv6t^opuV&F%GS#+vXKlPjNXm&^3BF|Q?0})$h%wtG%E0=7QeI^IG z)?qtGveWw!wYRp+pSv9I-mdLE2jjHoV>5 z)C6TGv*TEqZbbaYMCIYM+hU5cIo=3EAGw7? z%aL%9hLSs!+@a(SZEiDr$Ss_=To6WXnO!8Yb0QqsxHOX7k>rj{ZoaOtCvlriaXncA z6uoNd2Re-6B$qFYPr}6|ETmBZd&=(b@hCONBdyO&>@#OT$MJ@@3unRi{S9xgr}yZw zy}V1;{)-Y_S;^kXy`d-U7sfsmJ_mufmf!IDyk=-R_NI+1NQ|%0)^QBI=@5%5!!yTV zbMxp5%>#c^`)G4}?EM-!ctn-xThwsy9y6~U!WW^{x)Cq2R%;jezVH?pnp+D^{DIBht)Ra;e8b1b#y=t zsxsb2<7!GRsJc3*?os!u2h=y!L+VlWxcZTLM!nE^9bHhrR@tUjS zHMg#?Z32yJaXipwVH$izhWJvB$JPP2_KaKip5`UzudK0fulq^L+sbYO+_pD+%~@}H z(Mvgv>~MUPc;nmiYL8Z!$|tA&6$#~I5(&jZiBL``luIoViiHxPoKVOYUXVsYu}~tE zW775z%8<0ZLhNa84=Ln}5?O>|p+qRhlt`9DvLuovkt~U1i6tbKkXS-u35h!$@#Tw- zgkqsYC?~{USA>K@kx(p@2<4bGUjbDEeP)HsvhiyuF_%smGP=iK%8kwe%1|7vV9HN=}#Bz;h8jK4E`$L9^A!bMza)4njEDp0c z%;GSM!w?6C4?+P#0zv~q1d5ucg~9R=Vt|MNA_j;UAYy=sDRJ*5?!Cmlm$>&5_kQ@c zqfmg5fY5*tfl!CXSOr1_LIpwvLaiJ*1{DYu2o(qw2=z#b+XA5ip#q@-p^jF#AYilt geY663v;uXs0`a7#g^2(K`lP0MZFQ9z468NzH_aX8pa1{> literal 0 HcmV?d00001 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) {