diff --git a/Cargo.lock b/Cargo.lock index adefd26..5623edf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,98 +43,6 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" -[[package]] -name = "async-channel" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43de69555a39d52918e2bc33a408d3c0a86c829b212d898f4ca25d21a6387478" -dependencies = [ - "concurrent-queue", - "event-listener", - "futures-core", -] - -[[package]] -name = "async-executor" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90f47c78ea98277cb1f5e6f60ba4fc762f5eafe9f6511bc2f7dfd8b75c225650" -dependencies = [ - "async-io", - "futures-lite", - "multitask", - "parking 1.0.6", - "scoped-tls", - "waker-fn", -] - -[[package]] -name = "async-io" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ae22a338d28c75b53702b66f77979062cb29675db376d99e451af4fa79dedb3" -dependencies = [ - "cfg-if", - "concurrent-queue", - "futures-lite", - "libc", - "once_cell", - "parking 2.0.0", - "polling", - "socket2", - "vec-arena", - "wepoll-sys-stjepang", - "winapi", -] - -[[package]] -name = "async-mutex" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20e85981fc34e84cdff3fc2c9219189752633fdc538a06df8b5ac45b68a4f3a9" -dependencies = [ - "event-listener", -] - -[[package]] -name = "async-std" -version = "1.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c8da367da62b8ff2313c406c9ac091c1b31d67a165becdd2de380d846260f7" -dependencies = [ - "async-executor", - "async-io", - "async-mutex", - "async-task", - "blocking", - "crossbeam-utils", - "futures-channel", - "futures-core", - "futures-io", - "futures-lite", - "kv-log-macro", - "log", - "memchr", - "num_cpus", - "once_cell", - "pin-project-lite", - "pin-utils", - "slab", - "wasm-bindgen-futures", -] - -[[package]] -name = "async-task" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c17772156ef2829aadc587461c7753af20b7e8db1529bc66855add962a3b35d3" - -[[package]] -name = "atomic-waker" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" - [[package]] name = "atty" version = "0.2.14" @@ -207,37 +115,12 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" -[[package]] -name = "blocking" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea5800d29218fea137b0880387e5948694a23c93fcdde157006966693a865c7c" -dependencies = [ - "async-channel", - "atomic-waker", - "futures-lite", - "once_cell", - "waker-fn", -] - -[[package]] -name = "bumpalo" -version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" - [[package]] name = "byteorder" version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" -[[package]] -name = "cache-padded" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" - [[package]] name = "cc" version = "1.0.58" @@ -311,15 +194,6 @@ dependencies = [ "bitflags 1.2.1", ] -[[package]] -name = "concurrent-queue" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" -dependencies = [ - "cache-padded", -] - [[package]] name = "constant_time_eq" version = "0.1.5" @@ -368,6 +242,67 @@ dependencies = [ "winapi", ] +[[package]] +name = "crossbeam" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69323bff1fb41c635347b8ead484a5ca6c3f11914d784170b158d8449ab07f8e" +dependencies = [ + "cfg-if", + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-epoch", + "crossbeam-queue", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-channel" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ee0cc8804d5393478d743b035099520087a5186f3b93fa58cec08fa62407b6" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", + "maybe-uninit", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "lazy_static", + "maybe-uninit", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-queue" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" +dependencies = [ + "cfg-if", + "crossbeam-utils", + "maybe-uninit", +] + [[package]] name = "crossbeam-utils" version = "0.7.2" @@ -450,8 +385,8 @@ name = "domasi" version = "0.1.0" dependencies = [ "anyhow", - "async-std", "clap", + "crossbeam", "crossterm", "directories", "notify-rust", @@ -460,54 +395,6 @@ dependencies = [ "toml", ] -[[package]] -name = "event-listener" -version = "2.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f14646a9e0430150a87951622ba9675472b68e384b7701b8423b30560805c7a" - -[[package]] -name = "fastrand" -version = "1.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bd3bdaaf0a72155260a1c098989b60db1cbb22d6a628e64f16237aa4da93cc7" - -[[package]] -name = "futures-channel" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5" -dependencies = [ - "futures-core", -] - -[[package]] -name = "futures-core" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399" - -[[package]] -name = "futures-io" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789" - -[[package]] -name = "futures-lite" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97999970129b808f0ccba93211201d431fcc12d7e1ffae03a61b5cedd1a7ced2" -dependencies = [ - "fastrand", - "futures-core", - "futures-io", - "memchr", - "parking 2.0.0", - "pin-project-lite", - "waker-fn", -] - [[package]] name = "getrandom" version = "0.1.14" @@ -540,24 +427,6 @@ version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a164bb2ceaeff4f42542bdb847c41517c78a60f5649671b2a07312b6e117549" -[[package]] -name = "js-sys" -version = "0.3.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85a7e2c92a4804dd459b86c339278d0fe87cf93757fae222c3fa3ae75458bc73" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "kv-log-macro" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" -dependencies = [ - "log", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -654,12 +523,27 @@ dependencies = [ "libc", ] +[[package]] +name = "maybe-uninit" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" + [[package]] name = "memchr" version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" +[[package]] +name = "memoffset" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c198b026e1bbf08a937e94c6c60f9ec4a2267f5b0d2eec9c1b21b061ce2be55f" +dependencies = [ + "autocfg", +] + [[package]] name = "minimp3" version = "0.3.5" @@ -703,17 +587,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "multitask" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c09c35271e7dcdb5f709779111f2c8e8ab8e06c1b587c1c6a9e179d865aaa5b4" -dependencies = [ - "async-task", - "concurrent-queue", - "fastrand", -] - [[package]] name = "nom" version = "5.1.2" @@ -763,16 +636,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "objc" version = "0.2.7" @@ -811,24 +674,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "once_cell" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad" - -[[package]] -name = "parking" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6cb300f271742d4a2a66c01b6b2fa0c83dfebd2e0bf11addb879a3547b4ed87c" - -[[package]] -name = "parking" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" - [[package]] name = "parking_lot" version = "0.10.2" @@ -859,36 +704,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" -[[package]] -name = "pin-project-lite" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282adbf10f2698a7a77f8e983a74b2d18176c19a7fd32a45446139ae7b02b715" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "pkg-config" version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" -[[package]] -name = "polling" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e09dffb745feffca5be3dea51c02b7b368c4597ab0219a82acaf9799ab3e0d1" -dependencies = [ - "cfg-if", - "libc", - "wepoll-sys-stjepang", - "winapi", -] - [[package]] name = "proc-macro2" version = "1.0.19" @@ -977,12 +798,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "scoped-tls" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" - [[package]] name = "scopeguard" version = "1.1.0" @@ -1036,12 +851,6 @@ dependencies = [ "libc", ] -[[package]] -name = "slab" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" - [[package]] name = "slice-deque" version = "0.3.0" @@ -1202,12 +1011,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" -[[package]] -name = "vec-arena" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17dfb54bf57c9043f4616cb03dab30eff012cc26631b797d8354b916708db919" - [[package]] name = "vec_map" version = "0.8.2" @@ -1220,103 +1023,12 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" -[[package]] -name = "waker-fn" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9571542c2ce85ce642e6b58b3364da2fb53526360dfb7c211add4f5c23105ff7" - [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" -[[package]] -name = "wasm-bindgen" -version = "0.2.67" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0563a9a4b071746dd5aedbc3a28c6fe9be4586fb3fbadb67c400d4f53c6b16c" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.67" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc71e4c5efa60fb9e74160e89b93353bc24059999c0ae0fb03affc39770310b0" -dependencies = [ - "bumpalo", - "lazy_static", - "log", - "proc-macro2", - "quote 1.0.7", - "syn 1.0.38", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95f8d235a77f880bcef268d379810ea6c0af2eacfa90b1ad5af731776e0c4699" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.67" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97c57cefa5fa80e2ba15641578b44d36e7a64279bc5ed43c6dbaf329457a2ed2" -dependencies = [ - "quote 1.0.7", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.67" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841a6d1c35c6f596ccea1f82504a192a60378f64b3bb0261904ad8f2f5657556" -dependencies = [ - "proc-macro2", - "quote 1.0.7", - "syn 1.0.38", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.67" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93b162580e34310e5931c4b792560108b10fd14d64915d7fff8ff00180e70092" - -[[package]] -name = "web-sys" -version = "0.3.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dda38f4e5ca63eda02c059d243aa25b5f35ab98451e518c51612cd0f1bd19a47" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "wepoll-sys-stjepang" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fd319e971980166b53e17b1026812ad66c6b54063be879eb182342b55284694" -dependencies = [ - "cc", -] - [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index a82382b..55350c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ version = "0.1.0" [dependencies] anyhow = "1.0" -async-std = "1.6" clap = "2.33" crossterm = "0.17" directories = "3.0" @@ -16,3 +15,4 @@ notify-rust = "4.0" rodio = "0.11" serde = { version = "1.0", features = ["derive"] } toml = "0.5" +crossbeam = "0.7" diff --git a/src/config.rs b/src/config.rs index a7e654b..aa8b24c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -58,7 +58,7 @@ impl Config { .to_path_buf() } - fn get_config_directory() -> PathBuf { + pub fn get_config_directory() -> PathBuf { ProjectDirs::from("moe", "paoda", "domasi") .unwrap() .config_dir() diff --git a/src/main.rs b/src/main.rs index 2e3ecae..347aab9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,17 +1,14 @@ -use async_std::task; use clap::{App, Arg, ArgMatches, SubCommand}; +use crossbeam::channel::{unbounded, Receiver, Sender}; use crossterm::{ - cursor, event::{poll, read, Event, KeyCode, KeyEvent, KeyModifiers}, - terminal::{disable_raw_mode, enable_raw_mode, Clear, ClearType}, - QueueableCommand, + terminal::{disable_raw_mode, enable_raw_mode}, }; use domasi::pomodoro::{Alert, Clock, Status}; use domasi::{Config, Pomodoro}; use std::fs; -use std::io::{stdout, Write}; +use std::io::{self, Write}; use std::path::{Path, PathBuf}; -use std::sync::mpsc::{channel, Receiver, Sender}; use std::thread; fn main() { @@ -54,7 +51,7 @@ fn main() { } pub fn create_config() { - let config_dir = Config::get_data_directory(); + let config_dir = Config::get_config_directory(); let data_dir = Config::get_data_directory().join("alert"); if !config_dir.exists() { @@ -88,17 +85,20 @@ pub fn create_config() { pub fn start(args: &ArgMatches) { let mut pomodoro = Pomodoro::new(); - - let (tx, rx): (Sender, Receiver) = channel(); + let (tx, rx): (Sender, Receiver) = unbounded(); // UI Thread thread::spawn(move || loop { if let Ok(status) = rx.recv() { loop { let (remain, text) = Clock::get_formatted_string(status); - print_overwrite(&text); - // Make this check better pls + let out = io::stdout(); + let mut handle = out.lock(); + handle.write_all(text.as_bytes()).unwrap(); + handle.flush().unwrap(); + + // TODO: Make sure this isn't an issue. if remain < 1 { break; } @@ -111,48 +111,45 @@ pub fn start(args: &ArgMatches) { // User Input Thread thread::spawn(|| setup_user_input().unwrap()); - // Async Pomodoro - task::block_on(async { - let config = { - match Config::load() { - Some(cfg) => cfg, - None => Default::default(), - } - }; + let config = { + match Config::load() { + Some(cfg) => cfg, + None => Default::default(), + } + }; - let maybe_audio: Option; + let maybe_audio: Option; - match args.value_of("alert") { - Some(path) => maybe_audio = Some(Path::new(path).to_path_buf()), - None => { - match &config.sound_file { - Some(path) => maybe_audio = Some(path.clone()), - None => { - // Look in the default locations - // check for .mp3, .wav, .ogg, .flac - let data_dir = Config::get_data_directory().join("alert"); - let data_dir_str = data_dir.to_string_lossy(); + match args.value_of("alert") { + Some(path) => maybe_audio = Some(Path::new(path).to_path_buf()), + None => { + match &config.sound_file { + Some(path) => maybe_audio = Some(path.clone()), + None => { + // Look in the default locations + // check for .mp3, .wav, .ogg, .flac + let data_dir = Config::get_data_directory().join("alert"); + let data_dir_str = data_dir.to_string_lossy(); - let items = fs::read_dir(&data_dir).unwrap_or_else(|_err| { - panic!("Unable to read the contents of {}", data_dir_str); - }); + let items = fs::read_dir(&data_dir).unwrap_or_else(|_err| { + panic!("Unable to read the contents of {}", data_dir_str); + }); - maybe_audio = get_audio_file(items); - } + maybe_audio = get_audio_file(items); } } } + } - match maybe_audio { - Some(audio_path) => { - let default_device = rodio::default_output_device().unwrap(); - let alert = Alert::new(&audio_path, &default_device); + match maybe_audio { + Some(audio_path) => { + let default_device = rodio::default_output_device().unwrap(); + let alert = Alert::new(&audio_path, &default_device); - pomodoro.start(config, tx, Some(&alert)).await; - } - None => pomodoro.start(config, tx, None).await, + pomodoro.start(config, tx, Some(&alert)); } - }); + None => pomodoro.start(config, tx, None), + } } fn get_audio_file(items: std::fs::ReadDir) -> Option { @@ -185,16 +182,6 @@ fn setup_user_input() -> crossterm::Result<()> { disable_raw_mode() } -fn print_overwrite(text: &str) { - let mut stdout = stdout(); - - stdout.queue(Clear(ClearType::CurrentLine)).unwrap(); - stdout.queue(cursor::SavePosition).unwrap(); - stdout.write_all(text.as_bytes()).unwrap(); - stdout.queue(cursor::RestorePosition).unwrap(); - stdout.flush().unwrap(); -} - fn get_user_input() -> crossterm::Result<()> { loop { if poll(Clock::get_polling_interval())? { diff --git a/src/pomodoro.rs b/src/pomodoro.rs index 8174888..301f412 100644 --- a/src/pomodoro.rs +++ b/src/pomodoro.rs @@ -1,12 +1,11 @@ use super::Config; +use crossbeam::channel::Sender; use rodio::{Decoder, Device, Source}; use std::fs::File; use std::io::BufReader; use std::path::Path; -use std::sync::mpsc::Sender; use std::time::{Duration, Instant}; -// #[derive()] pub struct Alert<'a> { path: &'a Path, device: &'a Device, @@ -68,12 +67,7 @@ impl Default for Pomodoro { } impl<'a> Pomodoro { - pub async fn start( - &mut self, - config: Config, - tx: Sender, - maybe_alert: Option<&Alert<'a>>, - ) { + pub fn start(&mut self, config: Config, tx: Sender, maybe_alert: Option<&Alert<'a>>) { loop { self.next(); @@ -86,15 +80,15 @@ impl<'a> Pomodoro { match self.state { State::Work => { Self::send_to_clock(&tx, self.state, config.work_time); - Self::wait(config.work_time).await; + Self::wait(config.work_time); } State::ShortBreak => { Self::send_to_clock(&tx, self.state, config.short_break); - Self::wait(config.short_break).await; + Self::wait(config.short_break); } State::LongBreak => { Self::send_to_clock(&tx, self.state, config.long_break); - Self::wait(config.long_break).await; + Self::wait(config.long_break); } State::Inactive => { println!("Pomodoro Cycle is complete"); @@ -130,8 +124,8 @@ impl Pomodoro { } } - async fn wait(duration: Duration) { - async_std::task::sleep(duration).await; + fn wait(duration: Duration) { + std::thread::sleep(duration); } fn send_to_clock(tx: &Sender, state: State, length: Duration) { @@ -196,7 +190,7 @@ impl Clock { let minutes = (seconds - (hours * 3600)) / 60; let seconds = seconds - (hours * 3600) - (minutes * 60); - let mut clock = String::new(); + let mut clock = "\r".to_string(); clock.push_str(&format!("{}", status.state));