Skip to content

Commit

Permalink
Merge pull request #8 from icanvardar/feat/repl
Browse files Browse the repository at this point in the history
feat: add repl
  • Loading branch information
icanvardar authored Nov 3, 2024
2 parents b3a868b + f46f4aa commit d083034
Show file tree
Hide file tree
Showing 6 changed files with 311 additions and 18 deletions.
87 changes: 85 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ bincode = "1.3.3"
tokio = { version = "1.40.0", features = ["full"] }
dirs = { version = "4.0" }
clap = { version = "4.5.20", features = ["derive"] }
crossterm = "0.28.1"
30 changes: 16 additions & 14 deletions src/common/app_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ pub struct Args {
}

pub trait AppBuilder {
fn build(
) -> Pin<Box<dyn core::future::Future<Output = Result<Autocomplete, Box<dyn Error>>> + Send>>
fn build() -> Pin<Box<dyn core::future::Future<Output = Result<Arbor, Box<dyn Error>>> + Send>>
where
Self: Sync,
{
Expand All @@ -38,19 +37,23 @@ pub trait AppBuilder {
None
};

Ok(Autocomplete::build(
args.language.clone(),
args.thread_count,
args.max_suggestion,
args.backup,
output,
)
.await?)
Ok(Arbor {
autocomplete: Autocomplete::build(
args.language.clone(),
args.thread_count,
args.max_suggestion,
args.backup,
output,
)
.await?,
})
})
}
}

pub struct Arbor;
pub struct Arbor {
pub autocomplete: Autocomplete,
}

impl AppBuilder for Arbor {}

Expand All @@ -74,9 +77,9 @@ mod tests {
let mut arbor = Arbor::build().await?;
let word = "hello".to_string();

arbor.insert_word(word.clone()).await?;
arbor.autocomplete.insert_word(word.clone()).await?;

let suggestion = arbor.suggest_word("hel").await?;
let suggestion = arbor.autocomplete.suggest_word("hel").await?;

assert_eq!(suggestion.iter().nth(0).unwrap().to_owned(), word);

Expand All @@ -91,4 +94,3 @@ mod tests {
return Ok(Args::try_parse_from(itr)?);
}
}

1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pub mod util {
pub mod app_data;
pub mod backup;
pub mod errors;
pub mod repl;
}
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::error::Error;

use arbor::common::app_builder::{AppBuilder, Arbor};
use arbor::util::repl::Repl;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
Arbor::build().await?;
Repl::new().await?.run().await?;

Ok(())
}
Loading

0 comments on commit d083034

Please sign in to comment.