Function keys F1-F5 not detected on Linux console
Created by: ziotom78
The following snippet (modified version of https://github.com/ticki/termion/blob/master/examples/keys.rs) fails to detect function keys F1-F5 when run on a Linux text console (tty, enabled using Ctrl+Alt+F1):
extern crate termion;
use termion::event::Key;
use termion::input::TermRead;
use termion::raw::IntoRawMode;
use std::io::{Write, stdout, stdin};
fn main() {
let stdin = stdin();
let mut stdout = stdout().into_raw_mode().unwrap();
write!(stdout,
"{}{}q to exit. Type stuff, use alt, and so on.{}",
termion::clear::All,
termion::cursor::Goto(1, 1),
termion::cursor::Hide)
.unwrap();
stdout.flush().unwrap();
for c in stdin.keys() {
write!(stdout,
"{}{}",
termion::cursor::Goto(1, 1),
termion::clear::CurrentLine)
.unwrap();
match c.unwrap() {
Key::Char('q') => break,
Key::F(n) => println!("F{}", n),
_ => {}
}
stdout.flush().unwrap();
}
write!(stdout, "{}", termion::cursor::Show).unwrap();
}
Specifically:
- F1 is reported as key
A
- F2 is reported as key
B
- F3 is reported as key
C
- F4 is reported as key
D
- F5 is reported as key
E
Function keys F6-F12 work fine. I think this is caused by a different definition of the control sequences for $TERM==xterm
and $TERM==linux
(this case):
$ infocmp xterm linux | grep "kf[1-9]:"
kf1: '\EOP', '\E[[A'.
kf2: '\EOQ', '\E[[B'.
kf3: '\EOR', '\E[[C'.
kf4: '\EOS', '\E[[D'.
kf5: '\E[15~', '\E[[E'.
As you can see, only F1-F5 differ, and the last letter is indeed what termion reports.
My system is a Linux Mint 18 Sarah KDE edition (64bit).