extern crate crossterm;

use crossterm::style::{
    Colorize,
    Styler
};

use crate::{
    bitransform::{
        BitransformDesc,
        BitransformRegister
    },
    evolearn::Population
};

use super::Evolver;

impl Evolver {
    /// Changes Bitransform to one present in `register` or show all that are there.
    pub fn bitran(&mut self, register: &BitransformRegister, id: &str, prefs: &[usize]) -> Result<(), String> {
        if id != "" {
            let bitran = register.new_from_desc(& BitransformDesc::new(id, prefs))?;
            self.bitran = bitran;
            self.population.unscore();
        } else {
            let list = register.list();
            for (id, info) in list {
                println!("{:16}{}", id.cyan().bold(), info.green());
            }
        }
        Ok(())
    }

}
