//! Editor functionality use crate::helpers::*; use nix::sys::termios::Termios; use nix::unistd::read; use std::io; use std::io::{BufReader, Error, Stdin}; use std::io::prelude::*; use term_parser::{Action, ActionIter}; /// Main structure for the editor pub struct Editor { /// Reference to terminal settings before setting up raw mode original_termios: Termios, } impl Editor { pub fn new() -> Self { Editor { original_termios: get_termios(STDIN_FILENO) } } fn read_key(&mut self) -> char { let stdin = io::stdin(); let mut in_str = String::new(); let mut input = BufReader::new(stdin.take(1)); input.read_to_string(&mut in_str).unwrap(); let mut chars = in_str.chars(); chars.next().unwrap() } fn read_term_code(&mut self) -> ActionIter> { let stdin = io::stdin(); let buffer = BufReader::new(stdin); let term_code_iter = ActionIter::new(buffer); term_code_iter } pub fn process_keypress(&mut self) -> Option<()> { for term_code in self.read_term_code() { let term_code = match term_code { Ok(code) => code, Err(e) => panic!("{:?}\r\n", e), }; print!("{:?}\r\n", term_code); } /* let char = self.read_key(); if char == 'q' { disable_raw_mode(&self.original_termios)?; // Break out of the input loop return None; } // Echo characters if is_cntrl(char) { print!("{}\r\n", char as u8); } else { print!("{} ('{}')\r\n", char as u8, char); } */ Some(()) } }