From 834e27b59e3c569718c05b7e9d3fef5e8503b7fb Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Sat, 10 Aug 2024 21:03:27 -0700 Subject: [PATCH] Update trane to version 0.22.0 (#98) --- Cargo.lock | 99 +++++++++++++++++++++++++++++--------------------- Cargo.toml | 5 ++- src/display.rs | 48 +++++++++++++++++++++++- 3 files changed, 106 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9a919b3..e3a5a4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -261,7 +261,7 @@ version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bac35c6dafb060fd4d275d9a4ffae97917c13a6327903a8be2153cd964f7085" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", "syn 2.0.72", @@ -697,12 +697,6 @@ dependencies = [ "hashbrown", ] -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - [[package]] name = "heck" version = "0.5.0" @@ -964,9 +958,9 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "lru" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3262e75e648fce39813cb56ac41f3c3e3f65217ebf3844d818d1f9398cfb0dc" +checksum = "37ee39891760e7d94734f6f63fedc29a2e4a152f836120753a72503f09fcf904" dependencies = [ "hashbrown", ] @@ -1593,20 +1587,20 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "strum" -version = "0.25.0" +version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" dependencies = [ "strum_macros", ] [[package]] name = "strum_macros" -version = "0.25.3" +version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" dependencies = [ - "heck 0.4.1", + "heck", "proc-macro2", "quote", "rustversion", @@ -1778,14 +1772,24 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.10.1" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" dependencies = [ "cfg-if", "fastrand", + "once_cell", "rustix", - "windows-sys 0.52.0", + "windows-sys 0.59.0", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", ] [[package]] @@ -1906,9 +1910,9 @@ dependencies = [ [[package]] name = "trane" -version = "0.21.3" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02a83a5e9c8c88be0ad9465d195e1e9f9ca8e4865c5a196c7295cf999f163383" +checksum = "445dbc9ca2d373179d0aa6503888483b1769e262a312bac95b0e777bbc2372c1" dependencies = [ "anyhow", "chrono", @@ -1933,7 +1937,7 @@ dependencies = [ "tantivy", "tempfile", "thiserror", - "typeshare", + "ts-rs", "url", "ustr", "walkdir", @@ -1941,13 +1945,14 @@ dependencies = [ [[package]] name = "trane-cli" -version = "0.21.0" +version = "0.22.0" dependencies = [ "anyhow", "built", "chrono", "clap", "indoc", + "rand", "rustyline", "rustyline-derive", "serde_json", @@ -1957,33 +1962,34 @@ dependencies = [ ] [[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "typeshare" -version = "1.0.3" +name = "ts-rs" +version = "9.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04f17399b76c2e743d58eac0635d7686e9c00f48cd4776f00695d9882a7d3187" +checksum = "b44017f9f875786e543595076374b9ef7d13465a518dd93d6ccdbf5b432dde8c" dependencies = [ "chrono", - "serde", - "serde_json", - "typeshare-annotation", + "thiserror", + "ts-rs-macros", ] [[package]] -name = "typeshare-annotation" -version = "1.0.4" +name = "ts-rs-macros" +version = "9.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a615d6c2764852a2e88a4f16e9ce1ea49bb776b5872956309e170d63a042a34f" +checksum = "c88cc88fd23b5a04528f3a8436024f20010a16ec18eb23c164b1242f65860130" dependencies = [ + "proc-macro2", "quote", "syn 2.0.72", + "termcolor", ] +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + [[package]] name = "unicode-bidi" version = "0.3.15" @@ -2174,9 +2180,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ "windows-sys 0.52.0", ] @@ -2214,6 +2220,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-targets" version = "0.48.5" @@ -2375,18 +2390,18 @@ dependencies = [ [[package]] name = "zstd-safe" -version = "7.2.0" +version = "7.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa556e971e7b568dc775c136fc9de8c779b1c2fc3a63defaafadffdbd3181afa" +checksum = "54a3ab4db68cea366acc5c897c7b4d4d1b8994a9cd6e6f841f8964566a419059" dependencies = [ "zstd-sys", ] [[package]] name = "zstd-sys" -version = "2.0.12+zstd.1.5.6" +version = "2.0.13+zstd.1.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a4e40c320c3cb459d9a9ff6de98cff88f4751ee9275d140e2be94a2b74e4c13" +checksum = "38ff0f21cfee8f97d94cef41359e0c89aa6113028ab0291aa8ca0038995a95aa" dependencies = [ "cc", "pkg-config", diff --git a/Cargo.toml b/Cargo.toml index 94807c7..2cf1334 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] edition = "2021" name = "trane-cli" -version = "0.21.0" +version = "0.22.0" build = "build.rs" default-run = "trane" @@ -19,11 +19,12 @@ built = { version = "0.7.4", features = ["chrono", "dependency-tree", "git2", "s chrono = "0.4.38" clap = { version = "4.5.9", features = ["derive"] } indoc = "2.0.5" +rand = "0.8.5" rustyline = "14.0.0" rustyline-derive = "0.10.0" serde_json = "1.0.120" termimad = "0.29.4" -trane = "0.21.3" +trane = "0.22.0" ustr = { version = "1.0.0", features = ["serde"] } # Commented out for use in local development. # trane = { path = "../trane" } diff --git a/src/display.rs b/src/display.rs index 3888655..4636910 100644 --- a/src/display.rs +++ b/src/display.rs @@ -1,9 +1,12 @@ //! Contains the logic to print Trane assets to the terminal. use anyhow::{Context, Result}; +use rand::prelude::SliceRandom; use std::fs::read_to_string; use termimad::print_inline; -use trane::data::{BasicAsset, ExerciseAsset, ExerciseManifest}; +use trane::data::{ + course_generator::literacy::LiteracyLesson, BasicAsset, ExerciseAsset, ExerciseManifest, +}; /// Prints the markdown file at the given path to the terminal. pub fn print_markdown(path: &str) -> Result<()> { @@ -14,6 +17,39 @@ pub fn print_markdown(path: &str) -> Result<()> { Ok(()) } +/// Randomly samples five values from the given list of strings. +fn sample(values: &[String]) -> Vec { + let mut sampled = values.to_vec(); + let mut rng = rand::thread_rng(); + sampled.shuffle(&mut rng); + sampled.truncate(5); + sampled +} + +/// Prints a literacy asset to the terminal. +pub fn print_literacy(lesson_type: &LiteracyLesson, examples: &[String], exceptions: &[String]) { + let sampled_examples = sample(examples); + let sampled_exceptions = sample(exceptions); + match lesson_type { + LiteracyLesson::Reading => println!("Lesson type: Reading"), + LiteracyLesson::Dictation => println!("Lesson type: Dictation"), + } + if !sampled_examples.is_empty() { + println!("Examples:"); + for example in sampled_examples { + print_inline(&example); + println!(); + } + } + if !sampled_exceptions.is_empty() { + println!("Exceptions:"); + for exception in sampled_exceptions { + print_inline(&exception); + println!(); + } + } +} + /// Trait to display an asset to the terminal. pub trait DisplayAsset { /// Prints the asset to the terminal. @@ -49,6 +85,14 @@ impl DisplayExercise for ExerciseAsset { match self { ExerciseAsset::BasicAsset(asset) => asset.display_asset(), ExerciseAsset::FlashcardAsset { front_path, .. } => print_markdown(front_path), + ExerciseAsset::LiteracyAsset { + lesson_type, + examples, + exceptions, + } => { + print_literacy(lesson_type, examples, exceptions); + Ok(()) + } ExerciseAsset::SoundSliceAsset { link, description, .. } => { @@ -108,7 +152,7 @@ impl DisplayAnswer for ExerciseAsset { Ok(()) } } - ExerciseAsset::SoundSliceAsset { .. } => Ok(()), + ExerciseAsset::SoundSliceAsset { .. } | ExerciseAsset::LiteracyAsset { .. } => Ok(()), } } }