<commit_before>use nix::sys::ioctl::*;
use nix::sys::termios;
use std::fs::File;
use std::fs::OpenOptions;
use std::os::unix::io::*;

pub use nix::Result;

pub struct Terminal {
    tty: File,
    ttyfd: RawFd,
    size: Winsize,
    orig_attr: termios::Termios,
}

impl Terminal {
    pub fn new() -> Result<Terminal> {
        let mut tmptty = OpenOptions::new()
            .read(true)
            .write(true)
            .open("/dev/tty").unwrap();
        let tmpttyfd = tmptty.as_raw_fd();
        let mut tmpterm = Terminal {
            tty: tmptty,
            ttyfd: tmpttyfd,
            size: Winsize::new(),
            orig_attr: termios::tcgetattr(tmpttyfd).unwrap(),
        };
        match tmpterm.update_size() {
            Ok(()) => Ok(tmpterm),
            Err(error) => Err(error),
        }
    }

    pub fn destroy(self) -> Result<()> {
        match termios::tcsetattr(self.ttyfd, termios::SetArg::TCSANOW, &self.orig_attr) {
            Ok(()) => Ok(()),
            Err(error) => Err(error),
        }
    }

    pub fn update_size(&mut self) -> Result<()> {
        ioctl(self.tty.as_raw_fd(), TIOCGWINSZ(&mut self.size))
    }

    pub fn rows(&self) -> u16 {
        self.size.ws_row as u16
    }

    pub fn cols(&self) -> u16 {
        self.size.ws_col as u16
    }
}

trait Constructor<T> {
    fn new() -> T;
}

impl Constructor<Winsize> for Winsize {
    fn new() -> Winsize {
        Winsize {
            ws_row: 0,
            ws_col: 0,
            ws_xpixel: 0,
            ws_ypixel: 0,
        }
    }
}
<commit_msg>typing touchups. Preparing for major refactor for extensibility<commit_after>use nix;
use nix::sys::ioctl;
use nix::sys::termios;
use std::fs::File;
use std::fs::OpenOptions;
use std::os::unix::io::*;
use std::result;

const TTYPATH: &'static str = "/dev/tty";

pub struct Terminal {
    tty: File,
    ttyfd: RawFd,
    size: ioctl::Winsize,
    orig_attr: termios::Termios,
}

pub type Result<T> = result::Result<T, Error>;

pub enum Error {
    Unknown,
}

impl Terminal {
    pub fn new() -> nix::Result<Terminal> {
        let mut tmptty = OpenOptions::new()
            .read(true)
            .write(true)
            .open(TTYPATH).unwrap();
        let tmpttyfd = tmptty.as_raw_fd();
        let mut tmpterm = Terminal {
            tty: tmptty,
            ttyfd: tmpttyfd,
            size: ioctl::Winsize::new(),
            orig_attr: termios::tcgetattr(tmpttyfd).unwrap(),
        };
        match tmpterm.update_size() {
            Ok(()) => Ok(tmpterm),
            Err(error) => Err(error),
        }
    }

    pub fn destroy(self) -> nix::Result<()> {
        match termios::tcsetattr(self.ttyfd, termios::SetArg::TCSANOW, &self.orig_attr) {
            Ok(()) => Ok(()),
            Err(error) => Err(error),
        }
    }

    pub fn update_size(&mut self) -> nix::Result<()> {
        ioctl::ioctl(self.tty.as_raw_fd(), ioctl::TIOCGWINSZ(&mut self.size))
    }

    pub fn rows(&self) -> u16 {
        self.size.ws_row as u16
    }

    pub fn cols(&self) -> u16 {
        self.size.ws_col as u16
    }
}

trait Constructor<T> {
    fn new() -> T;
}

impl Constructor<ioctl::Winsize> for ioctl::Winsize {
    fn new() -> ioctl::Winsize {
        ioctl::Winsize {
            ws_row: 0,
            ws_col: 0,
            ws_xpixel: 0,
            ws_ypixel: 0,
        }
    }
}

{'fraction_non_alphanumeric': 0.1563150074294205, 'fraction_numerical': 0.00713224368499257, 'mean_word_length': 2.0161290322580645, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '604965', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1199, 'n_words': 248}