mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-06-01 16:10:51 +00:00
8239fbd12b
- Create subcommands to be able to print modules independently
- `starship prompt` will print the full prompt
- `starship module <MODULE_NAME>` will print a specific module
e.g. `starship module python`
- Added `--path` flag to print the prompt or modules without being in a specific directory
- Added `--status` flag to provide the status of the last command, instead of requiring it as an argument
- Refactored integration tests to be end-to-end tests, since there was no way in integration tests to set the environment variables for a specific command, which was required for the `username` module
- Moved e2e tests to `tests/testsuite` to allow for a single binary to be built
- Tests will build/run faster
- No more false positives for unused functions
- Added tests for `username`
- Removed codecov + tarpaulin 😢
60 lines
1.5 KiB
Rust
60 lines
1.5 KiB
Rust
use clap::ArgMatches;
|
|
use rayon::prelude::*;
|
|
use std::io::{self, Write};
|
|
|
|
use crate::context::Context;
|
|
use crate::module::Module;
|
|
use crate::modules;
|
|
|
|
pub fn prompt(args: ArgMatches) {
|
|
let prompt_order = vec![
|
|
"battery",
|
|
"username",
|
|
"directory",
|
|
"git_branch",
|
|
"git_status",
|
|
"package",
|
|
"nodejs",
|
|
"rust",
|
|
"python",
|
|
"go",
|
|
"line_break",
|
|
"character",
|
|
];
|
|
let context = Context::new(args);
|
|
|
|
let stdout = io::stdout();
|
|
let mut handle = stdout.lock();
|
|
|
|
// Write a new line before the prompt
|
|
writeln!(handle).unwrap();
|
|
|
|
let modules = prompt_order
|
|
.par_iter()
|
|
.map(|module| modules::handle(module, &context)) // Compute modules
|
|
.flatten()
|
|
.collect::<Vec<Module>>(); // Remove segments set to `None`
|
|
|
|
let mut printable = modules.iter();
|
|
|
|
// Print the first module without its prefix
|
|
if let Some(first_module) = printable.next() {
|
|
let module_without_prefix = first_module.to_string_without_prefix();
|
|
write!(handle, "{}", module_without_prefix).unwrap()
|
|
}
|
|
|
|
// Print all remaining modules
|
|
printable.for_each(|module| write!(handle, "{}", module).unwrap());
|
|
}
|
|
|
|
pub fn module(module_name: &str, args: ArgMatches) {
|
|
let context = Context::new(args);
|
|
|
|
// If the module returns `None`, print an empty string
|
|
let module = modules::handle(module_name, &context)
|
|
.map(|m| m.to_string())
|
|
.unwrap_or_default();
|
|
|
|
print!("{}", module);
|
|
}
|