diff options
author | Matan Kushner <hello@matchai.me> | 2019-06-10 15:56:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-10 15:56:17 +0100 |
commit | 097f1b05f1d82967fe2a900ccf7ba3597c04ad77 (patch) | |
tree | e5419607802145bf2521defd9823d224f937b653 /src/context.rs | |
parent | 8239fbd12befad1126e677fa083ce73947d74d8c (diff) |
Add support for prompt configuration (#62)
- Create `Config` struct that is added to `Context` when initialized
- Read `~/.confg/starship.toml` during initialization (can be updated later to also look at `$XDG_CONFIG_HOME`)
- `Context` now has a method for creating modules. This allows us to provide modules with a reference to the configuration specific to that module
Diffstat (limited to 'src/context.rs')
-rw-r--r-- | src/context.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/context.rs b/src/context.rs index e0e7e286c..fd0ccc825 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1,3 +1,6 @@ +use crate::config::Config; +use crate::module::Module; + use clap::ArgMatches; use git2::Repository; use std::env; @@ -6,6 +9,7 @@ use std::fs; use std::path::PathBuf; pub struct Context<'a> { + pub config: Config, pub current_dir: PathBuf, pub dir_files: Vec<PathBuf>, pub arguments: ArgMatches<'a>, @@ -28,6 +32,8 @@ impl<'a> Context<'a> { where T: Into<PathBuf>, { + let config = Config::initialize(); + // TODO: Currently gets the physical directory. Get the logical directory. let current_dir = Context::expand_tilde(dir.into()); @@ -51,6 +57,7 @@ impl<'a> Context<'a> { .and_then(|repo| get_current_branch(&repo)); Context { + config, arguments, current_dir, dir_files, @@ -68,6 +75,10 @@ impl<'a> Context<'a> { dir } + pub fn new_module(&self, name: &str) -> Module { + Module::new(name, self.config.get_module_config(name)) + } + // returns a new ScanDir struct with reference to current dir_files of context // see ScanDir for methods pub fn new_scan_dir(&'a self) -> ScanDir<'a> { |