Skip to content

Add Windows 10 support

kankri requested to merge kankri/termion:windows-support into master

I tried the merge request !151 but found it wasn't really working. This MR adds commits to that.

Running e.g. the keys example seemed to be somewhat working when started with cargo run --example keys, but wasn't working if started directly as target\debug\examples\keys.exe: escape sequences were just printed on the screen instead of controlling the output. It seems cargo leaves the console in the Virtual Terminal mode, thus hiding the fact that termion didn't properly set up the console. Even when started from cargo, keyboard input was not handled properly.

I fixed the problems I noticed in the original MR:

  • Fix unused imports.
  • Fix "termion::sys::tty::is_tty()".
  • Add support for using escape sequences and reading special keys on Windows 10.

Then I changed some of the examples to make it easier to test the various features:

  • Print keys using Debug trait in examples/keys.rs.
  • Show more color and style features in examples/color.rs.
  • Print mouse events in examples/mouse.rs.

Finally I added some tests for parse_csi() and fixed the panics those tests discovered:

  • Fix a comment.
  • Normalize indentation in "event::parse_csi()".
  • Simplify pattern matching in "event::parse_csi()".
  • Simplify pattern matching in "event::parse_csi()" with "ok()?".
  • Add tests for "CSI <" and fix "event::parse_csi()" not to panic.
  • Add tests for "CSI M" and fix "event::parse_csi()" not to panic.
  • Fix invalid tests.
  • Simplify matching "CSI M" in "event::parse_csi()".
  • Add tests for "CSI ... M" and fix "event::parse_csi()" not to panic.
  • Add tests for "CSI ... ~" and fix "event::parse_csi()" not to panic.

There are still some shortcomings in Windows support:

  • Control-j, control-m and Enter are all reported as Char('\n')
  • Control-z ends the input iterator (because of CTRL_Z_MASK in std::sys::windows::stdio::read_u16s())
  • Control-arrow keys are not supported (termion doesn't parse multiple arguments)
  • Window resize events are not received
  • Only Windows 10.0.10586 and later is supported (some features starting from 10.0.14393)

All of these problems could be avoided by using the Windows Console API to get key and windows size events directly.

Merge request reports