Skip to content
Snippets Groups Projects
Commit e487552b authored by Main's avatar Main
Browse files

Removed the KEYPRESS enum because Rust doesn't support the FromPrimitive trait anymore

parent a2eac621
No related branches found
No related tags found
No related merge requests found
......@@ -11,27 +11,25 @@ use nix::sys::termios::{BRKINT, ICRNL, INPCK, ISTRIP, IXON, OPOST, CS8, ECHO, IC
static MAX_LINE: i32 = 4096;
static UNSUPPORTED_TERM: [&'static str; 3] = ["dumb","cons25","emacs"];
enum KEYPRESS{
NULL = 0, // NULL
CTRLA = 1, // C-a
CTRLB = 2, // C-b
CTRLC = 3, // C-c
CTRLD = 4, // C-d
CTRLE = 5, // C-e
CTRLF = 6, // C-f
CTRLH = 8, // C-h
TAB = 9, // Tab
CTRLK = 11, // C-k
CTRLL = 12, // C-l
ENTER = 13, // Enter
CTRLN = 14, // C-n
CTRLP = 16, // C-p
CTRLT = 20, // C-t
CTRLU = 21, // C-u
CTRLW = 23, // C-w
ESC = 27, // Esc
BACKSPACE = 127 // Backspace
}
const NULL : u8 = 0; // NULL
const CTRLA : u8 = 1; // C-a
const CTRLB : u8 = 2; // C-b
const CTRLC : u8 = 3; // C-c
const CTRLD : u8 = 4; // C-d
const CTRLE : u8 = 5; // C-e
const CTRLF : u8 = 6; // C-f
const CTRLH : u8 = 8; // C-h
const TAB : u8 = 9; // Tab
const CTRLK : u8 = 11; // C-k
const CTRLL : u8 = 12; // C-l
const ENTER : u8 = 13; // Enter
const CTRLN : u8 = 14; // C-n
const CTRLP : u8 = 16; // C-p
const CTRLT : u8 = 20; // C-t
const CTRLU : u8 = 21; // C-u
const CTRLW : u8 = 23; // C-w
const ESC : u8 = 27; // Esc
const BACKSPACE: u8 = 127; // Backspace
fn is_a_tty() -> bool {
let isatty = unsafe { libc::isatty(libc::STDIN_FILENO as i32) } != 0;
......@@ -72,9 +70,14 @@ fn disable_raw_mode(original_termios: termios::Termios) -> Result<(), nix::Error
fn readline_edit() -> Result<String, io::Error> {
let mut buffer = Vec::new();
let mut input: [u8; 1] = [0];
let numread = io::stdin().read(&mut input).unwrap();
buffer.push(input[0]);
println!("{}",input[0]);
loop {
let numread = io::stdin().read(&mut input).unwrap();
match input[0] {
ENTER => break,
_ => { print!("{}", input[0]); io::stdout().flush(); }
}
buffer.push(input[0]);
}
Ok(String::from_utf8(buffer).unwrap())
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment