Skip to content

Commit

Permalink
terminfo: Pretend to be xterm if Windows console supports ansi
Browse files Browse the repository at this point in the history
 Windows people seem to be fine with this:
 microsoft/WSL#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 <[email protected]>
  • Loading branch information
MoSal committed Aug 22, 2018
1 parent 45da4f4 commit 57fcfaf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Binary file added assets/xterm-256color
Binary file not shown.
22 changes: 22 additions & 0 deletions src/terminfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,6 +71,18 @@ impl TermInfo {
}
})
});

#[cfg(windows)]
{
if term_name.is_none() && win::conout_supports_ansi() {
// Microsoft people don't seem to be okay 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 {
Expand Down Expand Up @@ -123,6 +139,12 @@ impl TermInfo {
parse(&mut reader, false)
}

// Get TermInfo from a byte slice directly
fn from_bytes(bytes: &[u8]) -> Result<TermInfo> {
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) {
Expand Down

0 comments on commit 57fcfaf

Please sign in to comment.