Files
rustype/+
T

123 lines
3.1 KiB
Plaintext

mod keymaps;
mod cml_functions;
use colored::*;
use std::io::Write;
use rust_translate::translate;
use random_word::gen_len;
use keymaps::get_keymap_rus;
use cml_functions::*;
// TODO:
// [ ] Line wrapping / character cap
// [x] Working cursor navigation
// [ ] Proper has_max_len (see below)
// [x] Allow full caps translation (_YU / _Yu)
// [x] Allow typing within text
// [ ] Clean up result (whitespaces)
//
// BUG:
// [x] Space -> Arrow left -> backspace -> panic
// [x] 4x space -> backspace -> -> sp -> bs -> panic
// [x] 2x space -> 2x backspace -> panic
// [x] Cursor inserts, doesnt overwrite
// [x] special letter -> left -> space -> cursor pos wrong
fn main() {
let result = diff_string_copy("hellollo".to_string(), "hello".to_string());
println!("\n{:?}", result);
loop {
let learned_word = learn_new_word();
if learned_word.is_none() {
break;
};
}
//println!("Congrats!! You learned a new Word: {}", learned_word);
}
#[tokio::main]
async fn learn_new_word() -> Option<String> {
//print!("Welcome! Which word do you want to learn?\n> ");
std::io::stdout().flush().unwrap();
//let mut vocab = String::new();
//io::stdin().read_line(&mut vocab).expect("Failed to read line");
//vocab = vocab.trim().to_string();
let vocab = gen_len(4, random_word::Lang::En).expect("no word found").to_string();
let vocab_tr = translate(&vocab, "en", "ru").await.unwrap();
println!("\n{}: {}", vocab.red(), vocab_tr.green());
println!("Please repeat in russian 🇷🇺 (2x ESC to quit)");
let input_opt = cml_input_line(get_keymap_rus());
input_opt.as_ref()?;
let input = input_opt.unwrap().to_string();
//println!("] '{}'", input);
if input == vocab_tr {
println!("Well done!");
}
else {
println!("sorry, thats wrong!");
if input.to_lowercase() == vocab_tr.to_lowercase() {
println!("upper/lowecase counts!!");
};
}
Some(vocab.to_string())
}
fn diff_string_copy(original: String, copy: String) -> Vec<u16> {
let mut diff_indicies: Vec<u16> = Vec::new();
let mut cp = copy.chars();
for letter in original.chars() {
//print!("{}", letter);
#[allow(unused_assignments)]
let mut cp_letter: Option<char> = None;
let mut found = false;
loop {
cp_letter = cp.next();
if let Some(cp_lt_unpacked) = cp_letter {
// print!("{}", letter);
if cp_lt_unpacked == letter {
print!("{}", letter);
found = true;
break;
}
else {
// different letter
print!("#");
}
}
else {
// cp iter has run out
diff_indicies.push(1);
println!("");
return diff_indicies;
}
}
if !found {
diff_indicies.push(1);
}
}
println!("\nended");
diff_indicies
}