Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Matan Kushner
committed
Jun 10, 2019
1 parent
8239fbd
commit 097f1b0
Showing
27 changed files
with
196 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use crate::utils; | ||
|
||
use dirs::home_dir; | ||
|
||
pub struct Config { | ||
data: toml::value::Table, | ||
} | ||
|
||
impl Config { | ||
/// Initialize the Config struct | ||
pub fn initialize() -> Config { | ||
if let Some(file_data) = Config::config_from_file() { | ||
return Config { data: file_data }; | ||
} | ||
|
||
Config { | ||
data: toml::value::Table::new(), | ||
} | ||
} | ||
|
||
/// Create a config from a starship configuration file | ||
fn config_from_file() -> Option<toml::value::Table> { | ||
let file_path = home_dir()?.join(".config/starship.toml"); | ||
let toml_content = utils::read_file(&file_path.to_str()?).ok()?; | ||
log::trace!("Config file content: \n{}", &toml_content); | ||
|
||
let config = toml::from_str(&toml_content).ok()?; | ||
log::debug!("Config found: \n{:?}", &config); | ||
Some(config) | ||
} | ||
|
||
/// Get the subset of the table for a module by its name | ||
pub fn get_module_config(&self, module_name: &str) -> Option<&toml::value::Table> { | ||
let module_config = self | ||
.data | ||
.get(module_name) | ||
.map(toml::Value::as_table) | ||
.unwrap_or(None); | ||
log::debug!("Config found for {}: {:?}", &module_name, &module_config); | ||
module_config | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
// Lib is present to allow for benchmarking | ||
mod config; | ||
pub mod context; | ||
pub mod module; | ||
pub mod modules; | ||
pub mod print; | ||
pub mod segment; | ||
mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.