<commit_before>

use ::backend;
use ::event::{Event, Key};
use std::io::Write;
use termion;
use termion::input::TermRead;
use termion::raw::IntoRawMode;
use ::theme::{BaseColor, Color, ColorStyle, Effect};

pub struct TermionBackend {
    terminal: termion::raw::RawTerminal<::std::io::Stdout>,
}

impl backend::Backend for TermionBackend {
    fn init() -> Self {
        print!("{}", termion::cursor::Hide);
        Self::clear();


        TermionBackend {
            terminal: ::std::io::stdout().into_raw_mode().unwrap(),
        }
    }

    fn finish(&mut self) {
        // Maybe we should clear everything?
        print!("{}{}", termion::cursor::Show, termion::cursor::Goto(1, 1));
        Self::clear();
    }

    fn init_color_style(&mut self, style: ColorStyle, foreground: &Color,
                        background: &Color) {
        // Do we _need_ to save the color?
    }

    fn with_color<F: FnOnce()>(&self, color: ColorStyle, f: F) {
        // TODO: actually use colors
        // TODO: careful! need to remember the previous state
        //                and apply it back
        f();
    }

    fn with_effect<F: FnOnce()>(&self, effect: Effect, f: F) {
        // TODO: actually use effects
        // TODO: careful! need to remember the previous state
        //                and apply it back
        f();
    }

    fn has_colors(&self) -> bool {
        // TODO: color support detection?
        true
    }

    fn screen_size(&self) -> (usize, usize) {
        let (x, y) = termion::terminal_size().unwrap_or((1, 1));
        (x as usize, y as usize)
    }

    fn clear() {<commit_msg>Take `&self` in TermionBackend::clear()<commit_after>use ::backend;
use ::event::{Event, Key};
use std::io::Write;
use termion;
use termion::input::TermRead;
use termion::raw::IntoRawMode;
use ::theme::{BaseColor, Color, ColorStyle, Effect};

pub struct TermionBackend {
    terminal: termion::raw::RawTerminal<::std::io::Stdout>,
}

impl backend::Backend for TermionBackend {
    fn init() -> Self {
        print!("{}", termion::cursor::Hide);

        let backend = TermionBackend {
            terminal: ::std::io::stdout().into_raw_mode().unwrap(),
        };

        backend.clear();
        backend
    }

    fn finish(&mut self) {
        // Maybe we should clear everything?
        print!("{}{}", termion::cursor::Show, termion::cursor::Goto(1, 1));
        self.clear();
    }

    fn init_color_style(&mut self, style: ColorStyle, foreground: &Color,
                        background: &Color) {
        // Do we _need_ to save the color?
    }

    fn with_color<F: FnOnce()>(&self, color: ColorStyle, f: F) {
        // TODO: actually use colors
        // TODO: careful! need to remember the previous state
        //                and apply it back
        f();
    }

    fn with_effect<F: FnOnce()>(&self, effect: Effect, f: F) {
        // TODO: actually use effects
        // TODO: careful! need to remember the previous state
        //                and apply it back
        f();
    }

    fn has_colors(&self) -> bool {
        // TODO: color support detection?
        true
    }

    fn screen_size(&self) -> (usize, usize) {
        let (x, y) = termion::terminal_size().unwrap_or((1, 1));
        (x as usize, y as usize)
    }

    fn clear(&self) {
{'fraction_non_alphanumeric': 0.1517074644907827, 'fraction_numerical': 0.0024176488365064974, 'mean_word_length': 2.277227722772277, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '318436', 'n_tokens_mistral': 1016, 'n_tokens_neox': 1010, 'n_words': 283}